upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/docs/shader_inputs.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/shader_inputs.md')
-rw-r--r--docs/shader_inputs.md61
1 files changed, 60 insertions, 1 deletions
diff --git a/docs/shader_inputs.md b/docs/shader_inputs.md
index 17f715b38..aa9da8759 100644
--- a/docs/shader_inputs.md
+++ b/docs/shader_inputs.md
@@ -8,6 +8,38 @@ it.
8Measured on the local package's disassembly (`work/shaders/dxbc/disasm`) at `16282101`. Offsets, bit positions and 8Measured on the local package's disassembly (`work/shaders/dxbc/disasm`) at `16282101`. Offsets, bit positions and
9counts only; no shader text. 9counts only; no shader text.
10 10
11## Bloom and exposure
12
13Reported by @Silliana in [#3235](https://github.com/ItsNotRexed/Leonida/issues/3235). The observations below were
14checked against the local disassembly. Offsets are bytes into the constant buffer read by the named shader.
15
16### A black bloom chain (`PS_DownSampleBloomFilterKaris`)
17
18- Check the RGB tint at `+0x00`, `+0x04` and `+0x08` first. The shader multiplies the filtered colour by these
19 values before export. An all-zero tint makes bloom black even with a valid source. The fourth value at `+0x0C`
20 feeds the exported alpha.
21- The sample loop has a limit of 13. Its luminance-dependent weight has the form `1 / (1 + k × luminance)`,
22 with scale `k` at `+0x1C`. Setting it to zero removes that dependence for finite inputs. The spatial filter
23 and output tint still apply.
24
25### Flat, wrong or slowly changing exposure (`PS_CalculateExposure`)
26
27- The mode dword at `+0x410` selects the exposure calculation. A nonzero value takes the path that computes
28 logarithmic exposure from the measured luminance. Check this before diagnosing the automatic exposure path.
29- On the compensation path, a nonzero dword at `+0x40C` selects the fixed value at `+0x408`. Zero selects a
30 sample from a 1D compensation curve. Check that the curve is bound when using the texture path.
31- Check the previous-exposure texture when the pass changes slowly. The adaptation code subtracts its sample
32 from the target exposure and can blend back toward the target. It tests `+0x3B0` against zero and compares
33 a value derived from the exposure delta against the threshold at `+0x3B4`. For a single-frame comparison,
34 the issue report suggests seeding the previous exposure with the target.
35
36### Luminance downsample and bloom upsample
37
38All five sampling sites in `PS_LuminanceSourceDownsample` contribute to the export. All nine in
39`PS_UpSampleBloomFilterBlend` do too. Check the source resolution, sampling and reduction before comparing
40the luminance pyramid with a whole-frame average.
41When inspecting the upsample in isolation, check in the pipeline state how its output blends with the previous level.
42
11## Studio-shot lighting (`PS_STUDIOSHOT_PBR_MATERIAL_STANDARD_LIGHTING`) 43## Studio-shot lighting (`PS_STUDIOSHOT_PBR_MATERIAL_STANDARD_LIGHTING`)
12 44
13Reported by @Silliana in [#1892](https://github.com/ItsNotRexed/Leonida/issues/1892). The corpus has one program 45Reported by @Silliana in [#1892](https://github.com/ItsNotRexed/Leonida/issues/1892). The corpus has one program
@@ -40,7 +72,8 @@ The fields below are the ones confirmed. The rest of the record is read but not
40|---|---|---| 72|---|---|---|
41| +0x10 | 3 × f32 | Light position; the shader subtracts the world position of the pixel from it. | 73| +0x10 | 3 × f32 | Light position; the shader subtracts the world position of the pixel from it. |
42| +0x20 | u32 | Bits 0–8: profile index (9 bits) into the profile table. Bits 9–17 and 18–21 are two more fields, not decoded. | 74| +0x20 | u32 | Bits 0–8: profile index (9 bits) into the profile table. Bits 9–17 and 18–21 are two more fields, not decoded. |
43| +0x28 | u32 | Flags. Bit 24 enables the light-shaping planes; bit 16 takes part in the shadow-map gate; bits 17, 20, 21, 26, 27 and 30 are tested, not decoded. | 75| +0x28 | u32 | Flags. Bit 24 enables the light-shaping planes; bit 16 takes part in the shadow-map gate; bits 30–31 are the light type (0–3), which selects how +0x3C is used; bits 17, 20, 21, 26 and 27 are tested, not decoded. |
76| +0x3C | 2 × f16 | Light shape size: the light's dimensions, used differently per light type. See [Light shape size](#light-shape-size). |
44| +0x40 | u32 | Low 24 bits non-zero turns on one per-light factor; at zero that factor is 1.0, so the light still shades. The top byte isn't read on the paths checked. | 77| +0x40 | u32 | Low 24 bits non-zero turns on one per-light factor; at zero that factor is 1.0, so the light still shades. The top byte isn't read on the paths checked. |
45| +0x4C | u32 | Top byte: number of light-shaping planes (0–255). See below. | 78| +0x4C | u32 | Top byte: number of light-shaping planes (0–255). See below. |
46| +0x5F | u8 | Read as byte / 255; at 0 one block of the light's shading is skipped. | 79| +0x5F | u8 | Read as byte / 255; at 0 one block of the light's shading is skipped. |
@@ -58,6 +91,25 @@ end of the buffer after the last light. A float in this dword has its exponent i
58gives 63 planes. The loop itself ends after at most 255 iterations. If a device-lost still shows up there, check this 91gives 63 planes. The loop itself ends after at most 255 iterations. If a device-lost still shows up there, check this
59dword and the buffer's bounds first. 92dword and the buffer's bounds first.
60 93
94#### Light shape size
95
96Reported by @Silliana [on the pull request](https://github.com/ItsNotRexed/Leonida/pull/3157): +0x3C holds two f16,
97the low half a sphere radius and the high half a range. Since intensity is radiance, the light's power grows with
98radius², so a radius that's too big (for example the range written into both halves) gives scattered single-pixel
99specular blowups that look like a translator bug.
100
101What the shader shows confirms the two f16 halves, but their use depends on the light type (bits 30–31 at +0x28):
102
103- In one path they are the two half-sizes of a rectangle. The light's position is moved by ± the low half along one
104 axis and ± the high half along the other, and points are clamped to those bounds.
105- In another path the high half is a length along the light's axis (clamped to ± half of it), and it is also squared
106 and compared against a distance.
107- The low half also sets one blend factor.
108- No range-style falloff was found: neither half divides a distance.
109
110So a wrong value here makes the light the wrong size, and an oversized area light is a likely cause of the blowups.
111Which light type reads the low half as a sphere radius isn't decoded yet.
112
61#### Correction to #1892 113#### Correction to #1892
62 114
63#1892 puts two checks on one dword at +0x40: a top-byte loop count, and low 24 bits that must be non-zero or the light 115#1892 puts two checks on one dword at +0x40: a top-byte loop count, and low 24 bits that must be non-zero or the light
@@ -171,6 +223,13 @@ transmittance table #1897 names, so it runs second and not side by side with `CS
171(mip 0). Which texture is bound to which table comes from #1897, not from the program. If a sky pass runs before the 223(mip 0). Which texture is bound to which table comes from #1897, not from the program. If a sky pass runs before the
172tables are built, it reads whatever is in them, and the black or noisy sky looks like a translator bug. 224tables are built, it reads whatever is in them, and the black or noisy sky looks like a translator bug.
173 225
226### Transmittance addresses texel corners
227
228`CS_Transmittance` turns its integer texel index into table coordinates as x × 1/256 and y × 1/64, with no +0.5,
229so each texel holds the value at its corner, not its centre (pointed out by @Silliana in
230[#3217](https://github.com/ItsNotRexed/Leonida/pull/3217#issuecomment-7084678180)). A reference table built at texel
231centres differs from it slightly, most visibly near the ground. That difference is expected and isn't a translator bug.
232
174### The dword at +0xD0: output format, not an enable 233### The dword at +0xD0: output format, not an enable
175 234
176#1897 reports a SkyView dword that skips the stores when it is zero. In `CS_SkyView` and `CS_MultipleScattering` 235#1897 reports a SkyView dword that skips the stores when it is zero. In `CS_SkyView` and `CS_MultipleScattering`