Skip to content

Keep the lens flare from building up light along its edges - #214

Open
nicoNaeg wants to merge 1 commit into
TheMoonPeople:masterfrom
nicoNaeg:fix/lens-flare-edge
Open

nicoNaeg wants to merge 1 commit into
TheMoonPeople:masterfrom
nicoNaeg:fix/lens-flare-edge

Conversation

@nicoNaeg

Copy link
Copy Markdown

Summary

At 6 pm, while the sun's lens flare is drawn, two orange vertical strips show along the right edge of the screen. These are the "white strips across the screen on the right side" in #51's 06:00 PM screenshot. They are light that the flare left behind in earlier frames.

  • The strips are gone at 1280x720, and at 960x720 (4:3), which showed them too.
  • A fainter band along the bottom edge goes as well. It built up the same way, at every size including 512x480.
  • No pixel gets brighter. The light the flare adds within a frame is unchanged.

Part of #51. The sky specks in the same issue did not reproduce here, so this PR does not touch them.

Cause

LensFlareDraw (port/src/render/screeneffect.cpp) follows retail's passes in two window-sized work targets:

  1. It clears the first target and draws the occlusion plate there. It then downsamples that to a third (170.67x160) into the second target.
  2. The seed copies the small image back into the first target. Four ghost passes then ping-pong between the two targets, each adding offset copies.
  3. The composite stretches the first target's 170x160 over the screen.

The second target is never cleared, and the area just past the downsampled image is both read and written:

  • The seed reads one row past it, as retail does (texture rows up to 161). Above 512x480 it also reads a little past its right edge, because its last pixels sample beyond x 170.67.
  • The ghost passes that draw into the second target add light there every frame. The third pass's quads end at x 171.4 and y 161.4.

That light built up frame after frame, and the seed copied it into the flare's last column and row. The composite stretched those into lines along the screen's right and bottom edges. After the ghost passes' offset copies, the right one shows as two strips, around x 1252–1261 and 1273–1279 of a 1280x720 window.

Change

  • The clear. LensFlareDraw clears the second target over the visible extent before the downsample, as it already clears the first before the occlusion plate.
  • Test. ScreenEffect.LensFlareLeavesNoEdgeOnceHidden (port/src/tests/screeneffect_test.cpp):
    • draws a visible flare for eight frames at 1024x960;
    • hides the sun behind geometry for one more frame;
    • checks the brightest pixel along the right and bottom edges.
  • Fixture. The file's PresentRenderer takes an optional window size for the test. The other tests keep 512x480.

Testing

Environment: macOS 26.6.2 arm64 (M4 Pro), Homebrew LLVM 23.1.5, MoltenVK 1.4.2, presets macos-arm64 (Debug) and macos-arm64-release. PAL data (data_version 20) for the replays.

Replay (Release): --jump town:1 --fast-load, turning the camera right between frames 200 and 290. There is no input after that, and frame 6900 (about 6 pm) shows the strips. "Orange" is the strongest red-minus-blue average over the top half of each of the last 40 columns. The scene beside them measures 16.

Check Without change With change
New unit test at 1024x960: brightest pixel near the right / bottom edge (scene 64) FAIL: 186 / 106 PASS
ScreenEffect.*, Debug 9/9 PASS
1280x720, frame 6900: orange in the last 40 columns 50 16
960x720 (4:3), frame 6900: same 45 17
Pixels that differ from the parent commit 1280x720: 11,137, all within 64 px of the right or bottom edge. 960x720: 8,371, same. 512x480: 698, all in the bottom 28 rows. None brighter; up to 74 darker.
Full ctest, Debug 2756/2759 pass. The 3 failures fail without this change too: PcSettingsReplay.pad (KeyError: 'present_mode', also with a build of the parent commit), and GfxMisc.MeshBoundsFollowTheFlagAndAreInvalidatedByUpdates and GfxGpuMeshDc2.FragmentInvocationQueriesPreservePixelsAndWindowOwnership, which test only the Kazarov renderer and fail on master in CI and locally

"Without change" used builds of the parent commit (bcd1967).

Not covered

  • Dungeons. They draw the flare through the same function (dng_main.cpp passes work and work2), but no dungeon flare was replayed.
  • Platforms. Windows and Linux were not tested.

LensFlareDraw clears its first work target before the occlusion plate,
but never the second. The seed reads one row past the area downsampled
into the second, as retail does, and above 512x480 a little past its
right edge too. The ghost passes that draw into the second reach those
texels as well, so their light built up there frame after frame. The
composite stretched it into lines along the screen's right and bottom
edges: the orange strips at the right of the 6 pm screenshot in TheMoonPeople#51.

Clear the second target over the visible extent before the downsample,
as the first already is.

ScreenEffect.LensFlareLeavesNoEdgeOnceHidden draws a visible flare for
eight frames at 1024x960, then hides the sun behind geometry and checks
that the right and bottom edges keep the scene's colour. PresentRenderer
takes an optional window size for it.
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