Skip to content

feat: rain in and out of focus - #10

Merged
SERDUN merged 1 commit into
serdunfrom
feat/rain-focus
Oct 1, 2026
Merged

SERDUN merged 1 commit into
serdunfrom
feat/rain-focus

Conversation

@SERDUN

@SERDUN SERDUN commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Rain in and out of focus: a game can keep sharp the rain that matters and soften the rest.

Before this, every drop was drawn equally sharp at whatever depth it fell. Perspective makes the drops nearest the eye the biggest and fastest on the screen, so they were the most prominent. Yet they pass in front of whatever the game is about.

Rain

  • focusDepth is the depth the eye is focused at. It defaults to 0, the street line.
  • aperture sets how strongly the rest of the rain is out of focus:
    • A drop is blurred by aperture × |perspective − perspective at the focused depth|. A thin lens blurs as |1/z − 1/z_focus|, and the perspective is 1/z.
    • Its streak widens by the blur and fades by as much as it widened, so its light is the same.
    • Its ends fade out over the blur too, so a blurred streak has no hard cut.
    • Splashes follow the same rule.
  • 0, the default, draws every drop sharp, as before.

Checks

  • Tests: flame_water has 38 tests, flame_lighting 17; all pass. A new test compares one seed with and without aperture:
    • every drop is at least as wide;
    • its width × alpha stays the same;
    • drops at the focused depth are barely blurred, and the nearest ones are over twice as wide and fainter.
  • Frames: in Umbrella with aperture 0.12, the drops on the walker's line stay thin and sharp, and the ones near the eye become soft, pale streaks. Checked in the frame test and on a Pixel 9 (Vulkan).
  • Cost: about +0.2 ms per frame in the game's CPU bench (3.07 against 2.83 ms), from the extra vertices of the blurred ends.

Merged by rebase into serdun; then a row in #9 and a new tag.

Every drop was drawn equally sharp at whatever depth it fell, so the
drops nearest the eye - the biggest and fastest on the screen - were the
most prominent, though they pass in front of whatever a game is about.

Rain.focusDepth and Rain.aperture make the eye a lens. A drop is blurred
by aperture times the difference between its perspective and the
focused depth's (a thin lens blurs as |1/z - 1/z_focus|, and the
perspective is 1/z), its streak widened by that much and faded by as
much as it widened, so its light stays the same; its ends fade out over
the blur too. Splashes follow the same rule. Aperture 0, the default,
draws every drop sharp, as before.
@SERDUN
SERDUN merged commit 5a7e3f5 into serdun Oct 1, 2026
@SERDUN
SERDUN deleted the feat/rain-focus branch October 1, 2026 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant