Skip to content

TEST-1028: the game's tiled deferred-lighting PS on a synthetic G-buffer (response test, vk_lighting) - #4906

Open
cxchhh wants to merge 4 commits into
ItsNotRexed:mainfrom
cxchhh:lighting-pass-test1028
Open

cxchhh wants to merge 4 commits into
ItsNotRexed:mainfrom
cxchhh:lighting-pass-test1028

Conversation

@cxchhh

@cxchhh cxchhh commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: TEST-1028 (claim)

Depends on: #4119
Depends on: #4436

Neither dependency is needed to build or run this. It is the next step after their G-buffer and sun shadow pass, and the doc refers to them. The PR touches none of their files.

What and why

#4436 lists "the game's own shadow-mask and deferred lighting shaders" as the next step for the G-buffer sandbox. This PR runs the game's own translated tiled deferred-lighting pixel shader as a full-screen pass. The inputs are synthetic. The PR records which slots of the shader's table hold the G-buffer, the shadow mask and the sun.

  • runtime/test/vk_lighting.cpp is a generic full-screen pass runner driven by a text plan. The plan gives the pair, a raw heap, user SGPRs, images and S#s.
    • The runner encodes each T# with gfx10::encode and writes it into the heap at the slots the plan names. It maps them through a leonida::BindlessSet, draws one triangle and writes each target's readback to a file.
    • It needs no fragment barycentrics.
    • It is registered in runtime/CMakeLists.txt.
  • tools/lighting_pass.py picks the shaders by layout, never by name.
    • The VS: only SV_VertexID, only s10, and it exports pos0 and param0.
    • The PS: only SV_Position in, mrt0 and mrt1 out (both compr), user SGPRs s8, s9 and s14. It also has the table loads listed in the doc and the 12-bit normal decode.
    • A PS that also reads the sun colour and intensity counts as directional.
    • The tool runs the probes and prints counts only. It exits 0 on PASS, 1 on FAIL, and 77 when the tool or a shader is missing.
  • docs/lighting_pass.md records the table: what each slot holds and how it was found. Every slot was found by perturbing one input at a time on the GPU.
    • Normal (mrt1, 24-bit octahedral) and albedo (mrt0).
    • The per-pixel sun shadow mask.
    • The sun direction, colour and intensity.
    • The output scale and a sun attenuation factor.

This is a response test, not a reproduction of the game's lighting.

  • The pass's camera and view constants are not decoded. Every constant the shader reads is set to 0.5 except the few named in the doc. So the view direction is arbitrary and a specular term is mixed into every output.
  • The checks are therefore ratios and signs, not a comparison against a CPU BRDF.
  • The G-buffer is synthetic (a uniform normal and albedo per run), not TEST-728: world props through the deferred material shaders into the G-buffer #4119's targets. vk_gbuffer needs VK_KHR_fragment_shader_barycentric, and the V100 this was measured on doesn't have it.

The check (sun along +x, six axis normals, 32×18)

The sun term is the output with sun colour 1 minus the output with sun colour 0. PASS needs all of these:

  • The normal facing the sun gets at least 3× the sun term of the opposite normal.
  • A flipped sun swaps them.
  • A zero shadow mask leaves at most 1 % of the sun term.
  • The non-directional variant has no sun term.
  • A one-hot red, green or blue albedo puts its own output channel at least 5 % above the other two, and those two stay equal.
  • Every pixel is finite.

Tested

NVIDIA Tesla V100-SXM2-32GB, driver 580.95.05, Linux (Ubuntu 24.04), g++ 13.3, Vulkan-Headers 1.4.363. One retail Xbox Series install (1.0.2.1). Shaders were translated at main 0db7fed with --wave64-emulate --f16-interp-fallback: 26,503 translated. The translator files are unchanged between that commit and this PR's base d974c88. The PR was re-run on its base: lighting_pass PASS, 12 unit tests OK, the docs tests OK, and the CMake build of vk_lighting with no warnings.

  • tools/lighting_pass.py: PASS (51 runs).

    • Layout match: 3 VS, 120 directional PS and 120 other PS.
    • Sun term: facing 3.059, away 0.2955. With the sun flipped: facing 0.5276, away 6.973.
    • Shadow mask 0: 0. Non-directional variant: 0.
    • One-hot albedo (r/g/b): red 3.925/3.137/3.137, green 3.087/3.875/3.087, blue 3.151/3.151/3.939.
  • Negative controls (one input moved to a wrong offset; each FAILs):

    change result
    normal in another slot facing = away = 5.144
    shadow mask in another slot a zero mask keeps a sun term of 1.336
    sun colour at the other light colour's offset sun term ≈ 0.0008
    albedo in another slot all three one-hot albedos give 3.21/3.21/3.21
  • All 120 directional variants, with the same sun checks (docs/lighting_pass.md §6). The PASS claim is only for the 68 in the first row; the rest are listed as not covered, not hidden.

    result variants material models
    PASS 68 17 models × 4 variants (plain, GLOBAL_GLINTS, UNDERWATER, WETNESS): STANDARD, the six CLEARCOAT models, EMISSIVE, EYE, GLINTS, HAZE, RETROREFLECTION, RETROREFLECTION_DIFFRACTION, SHEEN_ANISOTROPY_SSS, SKIN, TERRAIN_GLINTS, TERRAIN_GLINTS_TRANSLUCENCY
    sign right, ratio below 3 36 ANISOTROPY, BLURTRANSMISSION, DIFFRACTION, IRIDESCENCE, RADIAL_DIFFRACTION, SHEEN, SHEEN_ANISOTROPY, SHEEN_IRIDESCENCE, TRANSLUCENCY
    no sun term 12 EMISSIVE_DIFFRACTION, EMISSIVE_RETROREFLECTION, HAIR
    device lost 4 EYE_RETROREFLECTION
    • Sign right, ratio below 3: facing/away is 2.19–2.44 and a flipped sun swaps it. These models also light the far side (sheen, transmission) or add a strong view lobe, so the 3× threshold does not fit them.
    • No sun term: a model-specific constant gates the sun. For HAIR, setting two hair-only constants to 0 instead of the 0.5 fill brings the sun term back (3.79); these constants are not decoded.
    • Device lost: VK_ERROR_DEVICE_LOST on the V100 with these inputs; not rerun.
    • Table B copy: the first full run found 35 variants that copy table B into s[12:13] or s[92:93] instead of s[10:11]. The tool now follows that copy, which moved 25 variants to PASS.
  • Other checks:

    • python -I tests/test_lighting_pass.py: 12 tests OK. They use hand-written listings and synthetic readbacks, without a GPU.
    • tests/test_docs_*.py (10 files) and tests/test_tool_stdout_encoding.py: OK.
    • python -m compileall -q tools tests: OK.
    • cmake -G Ninja and cmake --build --target vk_lighting on Linux: no warnings. The CMake-built binary gives the same PASS.
  • Only on Linux. Not run on Windows/MSVC, and not on a GPU with fragment barycentrics, so the real-G-buffer combination is untested.

AI-assisted (Claude Code).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. Plans and readbacks stay in the user's folder; the doc and this PR give counts and means of synthetic outputs only.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

…-buffer (TEST-1028)

runtime/test/vk_lighting.cpp is a generic full-screen pass runner driven by a text plan: the translated VS/PS pair,
a raw heap for the shaders' table pointers and V#s, user SGPRs, images (their T#s encoded with gfx10::encode,
written into the heap and mapped through a BindlessSet) and S#s. It needs no fragment barycentrics.

tools/lighting_pass.py picks the full-screen VS and the directional and non-directional lighting PS by layout, lays
out the table they read (normal, albedo, sun shadow mask, sun direction, colour and intensity, pass scales; measured
by perturbing one input at a time) and runs a response test: the sun lights the normal that faces it, a flipped sun
swaps that, a zero shadow mask removes it, the non-directional variant has none, a one-hot albedo raises its own
channel. Counts only. The camera constants are not decoded, so this is a response test, not a reproduction of the
lighting. docs/lighting_pass.md records the slots, the checks, the negative controls and which material variants
the check covers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Kev-Ball

Kev-Ball commented Nov 23, 2026 •

Copy link
Copy Markdown

Correction after the author's slot measurements: this test fed MRT0 into A + 0xbc0, the slot that responds as specular F0. The diffuse albedo slot is A + 0x920 and held the fixture’s default value. The single-texel controls establish pixel correspondence at 0xbc0 and the normal slot. The zero at mask 0 establishes that changing B + 0x148 then has no effect. My draw did not establish a physical sun-shadow response or test the diffuse albedo connection. Author’s measurements

I ran #4119’s translated material pass into this lighting pass on an RTX 3080 Ti (NVIDIA 620.73.04, CachyOS, fragment barycentrics available), using my 1.0.2.1 copy. At cf1f389c the stock 51-draw synthetic response test passed first. It selected 3 VS, 120 directional PS and 120 other PS. Facing/away was 3.059/0.2955 and the flipped pair was 0.5276/6.973.

For the combined test I drew a hand-built textured quad at 32×18 with #4119 at 9d901226. I added a local binary dump of its existing MRT0, MRT1 and depth readback buffers so the packed normal and alpha bits survived the handoff. Of 576 pixels, 102 passed the depth coverage check, all 102 were shaded and their albedos had 102 distinct RGB values. I supplied the exact MRT0 and MRT1 bytes to the lighting plan’s albedo and normal slots. Other material, view and shadow inputs remained synthetic.

  • Pixel correspondence: I changed one covered texel’s red albedo, reran the lighting pass and compared the entire RGBA16F target 0. Exactly that output pixel changed (1/576). Restoring albedo and changing only the packed normal at that texel also changed exactly that pixel (1/576).
  • Shadow response: With the sun aligned to the decoded normal, all 102 covered pixels had a positive red-channel sun term (sun-colour 1 minus 0, range 0.9692–1.3521). Setting the shadow mask to zero made that term exactly zero at every covered pixel.
  • Ratio scope: Reversing the sun gave a larger mean red-channel term on this material/camera setup (2.4584 vs 1.1096 aligned). The stock threefold facing/away criterion holds for its documented synthetic inputs. I would keep it scoped there. This run establishes the two attachment connections and a shadow response, with no physical-lighting reference.

No game-derived files or readbacks attached. AI-assisted.

@whattheflop whattheflop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Windows CPU verification, AI-assisted. The exact head built vk_lighting with MSVC 19.38, CMake 4.4.4 and Ninja 1.13.2. The native usage path exited 2 without Vulkan initialization, the Python help exited 0, and all 12 lighting tests passed on uv CPython 3.12.13. Synthetic readbacks reproduced the expected sun, flipped direction, shadow, non-directional and RGB response verdicts.

Two small follow-ups:

  • The stated all-pixels finite check currently reads only o_t0.bin. On a synthetic 32×18 readback, NaN or infinity in the final pixel of target 0 failed as expected, while NaN in the final pixel of target 1 still reported finite True and passed. Keep the response means on target 0 and check finiteness of both targets, or narrow the stated rule to target 0.
  • The plan writer at lines 196–198 omits newline="\n", which fails the stock newline test on Windows.

No GPU draw or game data used.

@tupacfan04

Copy link
Copy Markdown
Contributor

Code sound; the corpus claim is not reproducible here.

Verified: 46 tests (10 docs + encoding + 12 test_lighting_pass.py), compileall and diff-check clean, exit-77 path. I compiled runtime/test/vk_lighting.cpp with MSVC 14.51 /std:c++20 /W4 /WX and the CMakeLists.txt:1015 defines: zero warnings. On a local RTX 5070 with a trivial synthetic GLSL VS/PS it printed device="NVIDIA GeForce RTX 5070" size=32x18 t0=4608 t1=4608 and all 576 texels were exactly 0.5/0.25/0.75, with t1 zeros - plan parse, two targets, draw and readback all work.

Still needs game data: the pick() corpus counts, every slot offset, all ratios and the negative controls.

Minor: docs/lighting_pass.md:23 says "exit 77 without them", true of vk_lighting.cpp:155-192, but tools/lighting_pass.py:292-293 turns it into exit 1.

Approve on the code, with that caveat. AI-assisted review.

@Kev-Ball

Kev-Ball commented Nov 23, 2026 •

Copy link
Copy Markdown

The input names below follow the original fixture. The author subsequently measured A + 0xbc0 as specular F0, A + 0x920 as diffuse albedo, and A + 0x1400 with B + 0x148 as a multiplicative blend. The figures verify the original perturbations. They do not independently identify those slots as albedo, sun colour or shadow. Author’s measurements

To cover the negative controls raised in review, I reran all four from §5 of docs/lighting_pass.md at cf1f389c on the RTX 3080 Ti (620.73.04, CachyOS), with the same 1.0.2.1 shader pair as my earlier baseline. I changed one input address per run and kept shader selection fixed. Each control completed 51 draws, returned finite outputs and exited 1. The unchanged baseline exited 0.

Input moved Measured effect
Normal → A + 0x920 Facing and away both gave 5.144.
Shadow mask → A + 0x920 Setting the mask to zero left a sun term of 1.336.
Sun colour → 0x12c The facing sun term fell from 3.059 to 0.000825.
Albedo → A + 0x1480 All three one-hot inputs gave the same RGB, 3.210 in every channel.

These reproduce the four documented slot perturbations independently on Ampere. The result covers the default layout-selected shaders. AI-assisted, aggregate synthetic responses only.

@cxchhh

cxchhh commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

A correction to the slot names in this PR, from controlled reruns on the same layout-selected standard directional shader (Tesla V100, NVIDIA 580.95.05, Linux; synthetic inputs, counts only). The response checks in the PR still hold as measured, but three of the names are wrong:

Slot Named here Measured behaviour
B + 0x148 (V# B+0x0) sun colour Not a light colour. With A + 0x1400 as m, it enters as lerp(1, c, m) multiplying the whole lighting result. With c = 1 the mask has no effect at all (difference exactly 0 over 2,304 pixels); with c = 0.5 mask 255 minus mask 0 is −0.5× the lit output. So the "sun term" (c 1 minus 0, mask 255) is the total lighting X, and "shadow mask 0 → 0" holds because c is no longer applied, not because a shadow removes the sun.
A + 0x1400 sun shadow mask The m of that lerp (see above).
A + 0xbc0 albedo Behaves as specular F0: with diffuse albedo 0, F0 1 minus 0 correlates 0.77 with N·H and saturates at N·H ≥ 0.8. The one-hot channel selectivity in albedo_ok comes from that tint.
A + 0x920 rgb (mid-grey) The diffuse albedo: linear and channel-selective (+0.429 per channel at 255 vs 128, 0 in the others).

Other measured inputs:

  • Light probe. A + 0x900 (2D array) scales the whole term linearly: 0/64/128/255 gives 0/0.660/1.321/2.633. It is evaluated along A + 0x2c0 dwords 0xec..0xf4. B + 0x12c × A + 0x3a0+0x54 × the A + 0x1320 1D LUT belongs to a separate branch, which is why moving the "sun colour" to 0x12c gave ≈0.

  • Diffuse LUT. A + 0xc80 is sampled at u = 0.5 + 0.5·sign(N·L)·√|N·L|. A horizontal ramp in that slot gives a direct diffuse that follows k·u with correlation 0.9973. The remaining 6 % rms residual is not removed by any single extra factor: (1−N·L)^5 is the best at 4.6 %. A value-for-value CPU reference therefore isn't available yet.

  • Camera. The camera lives in B + 0x80:

    • 0x4c/0x50: pixel → NDC scale;
    • 0x10..0x30: a 3×3 view ray with constant terms;
    • 0x34/0x38: near/far. They linearise the depth in A + 0xf80.r as n·f / (n + (f−n)·|d|).

    The 0.5 fill used here leaves the view direction undefined. That fits @Kev-Ball's observation that a reversed sun gave the larger term on another setup.

  • EMISSIVE zeros. The zero sun term of EMISSIVE_DIFFRACTION and EMISSIVE_RETROREFLECTION (§6) is an input artefact, not a material constant. They read A + 0x13c0, as do 91 of the 120 directional variants. With this PR's 128/128/128/255 fill its alpha is 1, which zeroes the term. With alpha 128 both give 1.766, the same as STANDARD. HAIR stays at 0 under that change too; its cause is still open.

I'd fix the names and the wording of §3/§6 in a follow-up PR after this one lands, together with @whattheflop's two follow-ups (finiteness of both targets, newline="\n") and @tupacfan04's exit-77 note, rather than change this branch under review.

AI-assisted. No game data: offsets, counts and correlations only.

…review

Slot names (measured on the V100; the check's own numbers are unchanged):
- B + 0x148 and A + 0x1400 are a tint c and a mask m that multiply the whole lighting result by lerp(1, c, m), not
  the sun colour and a sun shadow mask. The "sun term" is therefore the total lighting term (tint 1 minus 0 at mask
  255), and "mask 0 -> 0" checks the mask and tint slots, not a shadow. Constants renamed to TINT, MASK_T, LIGHT_V.
- A + 0xbc0 behaves as the specular F0 (F0_T); A + 0x920 rgb is the diffuse albedo (DIFFUSE_T). The albedo check
  now puts the one-hot albedo into A + 0x920: red 4.073/3.14/3.14 and symmetric for green and blue (was A + 0xbc0,
  3.925/3.137/3.137). Its negative control (albedo at A + 0x1480) gives 3.608 in all channels and fails.
- docs: the camera V# at B + 0x80 (pixel to NDC, the 3x3 view ray, near/far depth linearisation), the light probe
  at A + 0x900, the diffuse table at A + 0xc80, the other light colour at B + 0x12c, and why the 12 variants without
  a lighting term give 0: all read A + 0x13c0, whose alpha the 128/128/128/255 fill sets to 1; at 128 the 8
  EMISSIVE variants give 2.31-3.48, HAIR stays near 0.

Review follow-ups:
- read_rgb checks every pixel of both targets for finiteness (whattheflop).
- The plan is written with newline="\n" (whattheflop).
- vk_lighting's exit 77 (missing device feature) is passed on as exit 77, a skip, as the docs say (tupacfan04).

Tests: test_lighting_pass.py 15 (new: the diffuse/F0 slots, both targets' finiteness, \n plan, the 77 skip).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cxchhh

cxchhh commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @whattheflop, @tupacfan04 and @Kev-Ball. I pushed 88943d8 on top of cf1f389 as a fast-forward, with no history rewrite. It makes your three fixes and the slot correction from my earlier comment in this PR, instead of the "follow-up PR after this one lands" that the comment mentioned.

Review fixes

  • Finiteness (@whattheflop): read_rgb now checks every pixel of both targets. A new test puts a NaN in the last pixel of target 1, and the check now reports it as not finite.
  • Line endings (@whattheflop): the plan is written with newline="\n". A test asserts that the plan contains no \r.
  • Exit 77 (@tupacfan04): when vk_lighting exits 77 (a missing device feature), tools/lighting_pass.py now also exits 77 and reports a skip, as docs/lighting_pass.md says. Any other runner exit is still 1. Both cases are tested by mocking the runner exit.

Slot names. Only the names and explanations change; the check's numbers are unchanged.

  • Tint and mask: B + 0x148 and A + 0x1400 are a tint and a mask, lerp(1, c, m) over the whole lighting result. The "sun term" is now called the total lighting term. The explanation of mask 0 → 0 is corrected: with the mask at 0 the tint no longer applies, so this checks the two slots, not a shadow.
  • F0 and albedo: A + 0xbc0 behaves as the specular F0, and A + 0x920 rgb is the diffuse albedo. The albedo check had to move to A + 0x920, so I re-ran it.

V100 rerun of the full check:

Before Now
Facing/away 3.059/0.2955 3.059/0.2955
Flipped light 0.5276/6.973 0.5276/6.973
Mask 0 0 0
Non-directional variant 0 0
One-hot albedo 3.925/3.137/3.137 (in A + 0xbc0) 4.073/3.14/3.14, the same pattern for green and blue (in A + 0x920)
Result PASS, 51 runs PASS, 51 runs

Negative controls, all still FAIL:

  • normal → A + 0x920: 5.144 = 5.144;
  • mask → A + 0x920: 1.336;
  • tint → 0x12c: 0.0008248;
  • diffuse albedo → A + 0x1480: 3.608 in every channel (new).

@Kev-Ball's Ampere reruns of the first three controls match these numbers.

Docs additions

  • §3.1 decodes the camera V# at B + 0x80: pixel → NDC, the 3×3 view ray, and the near/far depth linearisation.
  • §3 adds rows for the light probe, the A + 0xc80 diffuse table and the other light colour at B + 0x12c.
  • §6 explains why 12 directional variants have no lighting term. All 12 read the T# at A + 0x13c0 (91 of the 120 directional variants do). The 128/128/128/255 fill sets its alpha to 1, which zeroes the term for these models; the other 79 readers are unaffected. With only that alpha at 128:
    • the 8 EMISSIVE variants give 2.31–3.48;
    • the 4 HAIR variants give only 0.004–0.006, so HAIR still has an open cause.

Tests run:

  • tests/test_lighting_pass.py: 15 OK, 4 of them new.
  • The 10 test_docs_* files, test_tool_stdout_encoding, test_text_write_line_endings, test_csv_line_endings, test_report_paths and test_report_path_case: OK.
  • compileall and git diff --check: clean.

All 4 changed files were verified byte for byte on the branch. Still not done: a CPU BRDF reference, because the direct diffuse keeps a 6 % residual.

AI-assisted. No game data: offsets, counts and means only.

@whattheflop

Copy link
Copy Markdown
Contributor

Retested both findings from my review on 88943d8 on Windows with uv CPython 3.12.13. Both are resolved. Two synthetic RGBA16F readbacks caught NaN and both signed infinities in all four channels of both targets (24/24). RGB averages stayed on target 0. The clean mocked CLI returned 0, and a NaN in the final alpha sample of target 1 returned 1. The same fixture plan went from 10 CRLF endings to 10 LF endings. All 31 focused stock lighting, newline, encoding, and docs tests passed. CPU only, AI-assisted.

@memorypressure

Copy link
Copy Markdown

Verified against main 3faac55: merges cleanly; the 12 CPU tests in tests/test_lighting_pass.py pass under python -I (re-run) and all docs guards are green; nothing on main pre-empts this. The vk_lighting C++ harness and its response test could not be run here (no GPU/cmake) — the GPU claims stand unverified. One compliance nit, verified in the diff: tools/lighting_pass.py:197 opens plan.txt with encoding=utf-8 but omits newline="\n", which the repo's write rules require — on Windows the plan file gets CRLF before the C++ harness parses it. One-line fix. CI pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@DenRakEiw

Copy link
Copy Markdown
Contributor

Tested 88943d8e on Windows 11 (MSVC 19.44 / Ninja / Vulkan SDK 1.4.363.0, Python 3.12.10, no game files): pass.

  • Trial-merged onto origin/main (3faac557): clean; vk_lighting.exe compiled and linked cleanly.
  • python -I tests/test_lighting_pass.py: 15/15 OK (0.11s). (Build + synthetic unit test check only; no game shaders run.)

AI-assisted (Gemini 4 Neon).

cxchhh and others added 2 commits November 23, 2026 07:25
…, HAIR

Repeats the fit with a real camera state (60 degree fov, n 0.1, f 100, depth back-computed with the decoded
formula) and records the further inputs that have to be set before the direct light is clean: the smoothness in
A + 0x1240 r (GGX alpha = max(0.001, (1 - r)^2) after its remaps at A + 0x300 0x634..0x63c and A + 0x2c0
0x108/0x10c), the sun disc at A + 0x2c0 0x118/0x11c (the specular light vector is the disc point closest to the
reflection vector; without the disc it is R itself), and plane-like constants at B + 0x160 0x210..0x23c that remove
the direct light from part of the screen.

Result: the direct diffuse follows the A + 0xc80 table with a 3.9-6.2 % rms residual (no lower than 4.9 % with free
N.V/N.L/L.H terms; a grazing-angle tail), the specular fits GGX/Smith/Schlick only to 26-46 %, so there is no
value-for-value mode. HAIR is not zero with this camera: it reads B + 0x160 0x158 and B + 0x80 0x4, and with both
non-zero the side facing -L is the bright one. Docs only; the check and its numbers are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…square (likely the shadow input)

With the camera and inputs of §3.2, A + 0xbe0 r multiplies the direct light by r^2 and leaves the ambient alone;
A + 0x1400 (the mask of §3) does not change the output with the tint at 1. Docs only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gut0to

gut0to commented Nov 23, 2026

Copy link
Copy Markdown

Independent Windows check on head cf1f389c (Python 3.13): python -I tests/test_lighting_pass.py passes all 12 tests. The GPU integration check did not run because vk_lighting is not built in this environment.

I also confirmed in the current source that read_rgb() only reads o_t0.bin, although §5 says every output pixel must be finite, and write_plan() opens plan.txt without newline="\n", so Windows text mode may write CRLF. AI-assisted review.

@cxchhh

cxchhh commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Two docs-only commits on top of 88943d8, both fast-forward: 7e28d94 and dd6f4b8. Only docs/lighting_pass.md changes. The check and its numbers are unchanged.

New §3.2: a second BRDF fit with a consistent camera. The camera of §3.1 is filled in as a real state:

  • 60° field of view, near/far 0.1/100, every pixel at 2 m;
  • the depth byte back-computed with the decoded formula;
  • each light run paired with its opposite light, so the ambient cancels.

Before the direct light is clean, these inputs had to be set:

Input What it does
A + 0x1240.r Smoothness r. GGX α = max(0.001, (1−r)²) after two remaps, A + 0x300 0x634..0x63c and A + 0x2c0 0x108/0x10c.
A + 0x2c0 0x118/0x11c Sun-disc sin/cos. The specular light vector is the disc point closest to R; without the disc the shader uses R itself.
B + 0x160 0x210..0x23c Plane-like constants. At 0.5 they remove the direct light from 467 of 1,694 lit pixels.

Fit results:

  • Direct diffuse: k·(the A + 0xc80 table), 3.9–6.2 % rms across three light directions. Free N·V/N·L/L·H terms and their (1−x)⁵ get it no lower than 4.9 %. The residual has a grazing-angle tail: 90th percentile +19 %, 99th +59 %.
  • Specular: GGX × height-correlated Smith × Schlick reaches only 26–46 % at the rough end.

Neither is close to 1 %, so there is no value-for-value mode.

HAIR is not zero with this camera.

  • It reads two extra dwords, B + 0x160 0x158 and B + 0x80 0x4.
  • With either at 0 the output stops depending on the light.
  • With both non-zero, the side facing −L is the bright one.
  • A tangent stored in the normal slot would behave like this. That is not checked.

Shadow input. On a real G-buffer, a real shadow map or all zeros in A + 0x1400 gave byte-identical output (the tint is 1). That fits the lerp of §3. Under the §3.2 setup, A + 0xbe0.r is the only T# that scales the direct light and leaves the ambient alone: it multiplies the direct term by r² (0/128/255 → 0/7.52/29.85). That makes it the likeliest shadow/visibility input.

@memorypressure: the missing newline="\n" at tools/lighting_pass.py:197 was fixed in 88943d8, which @whattheflop has retested.

AI-assisted. Synthetic inputs, offsets and counts only.

@cxchhh

cxchhh commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up check on a real G-buffer: A+0xbe0 is the shadow input, and the decoded camera V# removes the full-screen seam

AI-assisted (Claude Code). Counts only; no images, shaders or game data.

Setup

Results

Step Pixels changed Effect
Camera V# B+0x80 filled in (pixel→NDC, view ray, near/far, reversed-Z depth) instead of 0.5 576,078 The diagonal seam along the full-screen triangle edge is gone
Roughness remaps A300+0x634..0x63c and A2c0+0x108/0x10c cleared 152,761 Mean −0.154; the 0.5 fill widens and brightens every highlight
Sun disc A2c0+0x118/0x11c (0.266°) 215,459 Mean +0.006
Plane tests B160+0x210..0x23c cleared 0 They already pass everywhere at 0.5 in this view
Real shadow map (from #4436) in A+0xbe0.r: 0 shadowed, 255 lit — 207,069 of 207,093 shadowed pixels get darker (mean 5.99 → 0.28); all 369,849 lit pixels stay byte-identical

This confirms on real data what the docs' §3.2 inferred from synthetic inputs:

  • A+0xbe0.r gates only the direct light.
  • A+0x1400 (the tint mask) has no effect while the tint at B+0x148 is 1. A real or all-zero mask there gives byte-identical output.

All outputs are finite. This is still a response test: the albedo is untextured, and F0, the probe and the LUT are not the game's values.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested dd6f4b8 merged onto main 3faac55 on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:

  • Full ctest: 178/178.
  • Warnings: none new in the files this PR changes.

AI-assisted (Claude Code).

@tunczzz

tunczzz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested dd6f4b8d (merge base d974c88a) on Windows 11 10.0.26300 with an NVIDIA GeForce RTX 5070 Ti (Blackwell, subgroup 32..32), driver 616.56. Result: pass.

  • Runtime built from this head: MSVC 19.44 (BuildTools 2022), Ninja, RelWithDebInfo, -DLEONIDA_VULKAN_HEADERS_FETCH=ON (no Vulkan SDK; the loader comes from the NVIDIA driver). glslangValidator and llvm-mc 21 came from WSL Ubuntu. Build exit 0.
  • ctest -j 3: 177/177 passed.
  • scripts/run_gpu_tests.py --build <this build>: 170/217 passed, 47 skipped, 0 failed.
  • The merge base d974c88a is older than main 3faac557. The same tests exist in both, and every one gives the same result as on main 3faac557 (ctest 177/177, GPU 170/217).
  • vk_lighting builds. I didn't run tools/lighting_pass.py: it needs the game's translated lighting shaders, and I don't use game files.
  • As on main, run_gpu_tests.py records cs_fmt_d16_xyz twice and skips cs_tbuffer_store. That's main's runner bug, fixed by run_gpu_tests: record cs_tbuffer_store's result; fail a run that records a test twice #4784, not this PR.

Not run: other GPUs/vendors, Linux, lighting_pass.py (needs game shaders), the Vulkan validation layer (not installed). No game files.

AI-assisted (Claude Code).

@Atomic258

Copy link
Copy Markdown
Contributor

Tested dd6f4b8 on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_lighting_pass.py -> OK
  • Negative control (tools/lighting_pass.py removed): ModuleNotFoundError - differentiates

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

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.

10 participants