Reflection (REF shaders)
Shader names
<base>REF<kind>[AL]:
base SD (plain), SBTS
(normal mapped), SBPX (per pixel,
no normal map), SBOS,
SC, DBTS,
LBTS; kind S,
P or C;
AL = with alpha. Checked in the
disassembly of SDREFS, SDREFP, SBTSREFS,
SBTSREFP, SBPXREFSAL and SBPXREFPAL.
- Environment texture slot
(ALR material): SD/SBPX:
normal_idx(D3D slot 1 resp. 2); SBTS:normal_backup_idx(slot 2;normal_idxis the normal map, slot 1). The ramp lookup (slot 3) is the class’s own texture (see “SBTS”). pdconv writes the slot asextras.pd_env(and the SBTS normal map aspd_normal_map), a PNG file name. On st03: a 128² blurred picture of the arena’s arcades (SD/SBPX) and a 256² cloudy image (SBTS), both dark (mean RGB ≈ 50/255) with a soft alpha (mean 0.2–0.25). The env alpha is the reflection strength. - Texture coordinates:
REFS(sphere):R = c0.z · (n·E) · n − Ewith E the unit vector to the eye (SBTS/SBPX: fromcEYEPOSper vertex; SD: the constantcEYEVEC), thenuv = (R·cTMAT0, R·cTMAT1) / sqrt(R·cTMAT2 + cTMAT2.w) + c0.w(SBTS first folds R to(−x, −y, |z|)). Withc0.z = 2,c0.w = 0.5and the TMAT rows a scaled view rotation this is the classic sphere map,m = 2·sqrt(x² + y² + (z+1)²)(for unit R,x² + y² + (z+1)² = 2 + 2z, linear in R, which is why the shader needs only a dot product).REFP(planar):uv = (pos.xy · cTMAT0.zw + cTMAT0.xy) · c0.w + c0.w, a projection of the model-space x (horizontal) and y (height). SBTS adds the normal map’s xy through a 2×2 matrix (pixel constantc21).- REFP
cTMAT0(floorstain): uploaded by one routine shared by all five REFP classes (0x1402a5a30, register 16). From the material entry’s s16s at 0x44 (sx), 0x46 (sy) and 0x48 (depth):cTMAT0.zw = (sx, −sy) × 0.001. It takes the model-space point one unit in front of the camera, v = (0, 0, 1, 1) × inverse(model × view) = eye + forward axis (a point, not a direction; the w = 1 looks unintended but is what runs), normalizes it, and setscTMAT0.xy = depth / v.z × (v.x, v.y) × cTMAT0.zw, or 0 when |v.z| < 1e−6. So uv = ((pos.x + depth·v.x/v.z)·sx·0.001, −(pos.y + depth·v.y/v.z)·sy·0.001)·c0.w + c0.w: a projection along model-space x and y (height) with a camera parallax. A level floor reads a single env row, which shifts as the camera moves. pdconv writes the three values asextras.pd_tmat. st03/st13/st23 (the only REFP stages): SDREFP (15, 15, 20), SBTSREFP (7, 7, 20), SBPXREFPAL (5, 5, 20). - REFP model space is the
joint’s (refpflicker): a stage
index buffer’s vertices are local to its
transform joint (pdconv bakes the joint’s bind
matrix into the glTF positions), and REFP
projects that local position. The Palace’s REFP
floors hang off a joint that turns local (x, y,
z) into model (x, −z, y), i.e. local y = model z
and local z = minus the height, so the
projection spans the ground plane and v.z is
minus the camera point’s height; its wall
panels’ joints turn local xy into the wall
plane. Projected in the baked space instead, a
floor read one env row and v.z was the camera’s
horizontal z, which crosses 0 in the middle of
the stage (the lookup swept the texture as the
camera moved). pdconv writes the joint
(joint-local → model, game space, glTF
column-major) as
extras.pd_refp_xfon a per-joint copy of each REFP material whose joint is not the identity (st03/st13/st23). - SBTSREF* bump offset
(
c21): the env UV gets(c21.x·b + c21.w·g, c21.y·b + c21.z·g)with (b, g) the normal map’s blue and green as (x − 0.5)·2. The binds (e.g. 0x1402a0b20) set render states 0x16 and 0x18 of texture stage 2 to the material’s s16 at 0x42 / 255. The state setter (0x140020c40) stores states 0x16–0x19 of stage n as the pixel constant c(0x13 + n), soc21.x = c21.z= that value (pdconvpd_bumpenv). It is 0 on every SBTSREFS/SBTSREFP material of the 19 stages, so there is no bump offset..y/.ware not set by these binds (see PLACEHOLDERS). - REFS
cTMATand the vertexc0are set by the executable: not decoded (cEYEVEC: above).
- Weight:
w = COLOR0.a · (cEYEVEC.w − max(n·E, 0)), a fresnel term from the vertex alpha. The SD and SBTS REF pixel shaders clamp it to [−1, 1] with their other inputs (so withcEYEVEC.wof 1.5–2 it is 1 on surfaces facing the camera); SBPXREF* reads it unclamped. Plain SD clamps its specular colour and weight the same way (floorstain) (st03: 1.0 on 64 530 vertices, 0 on 7 521, 0.2/0.3 on 6 900; pdconv now writes COLOR_0 as RGBA). SBTS multiplies it by the normal map’s alpha (st03 mean 0.05–0.12). - Combine (D = directional +
point light × vertex colour, A = hemisphere
ambient):
base' = tex · saturate(env.rgb + 1 − w)(darkened where it reflects);- SD:
rgb = saturate(base'·A + base'·D) + env.rgb · env.a · w · 4 · D + specular · w; - SBPX: the same with the full light
saturate(A + D)instead ofDfor the env term; - SBTS:
env.rgb · env.a · w · 2 · (A + D) · shade, then the base term × shade, with the normal-mapped D and A and the scalar shadeCOLOR0.r(see “SBTS”).
- Godot
(
PdData._set_slots,PRELIT_CODEref_mode): this combine with the decodedcEYEVEC(pdconvpd_eye_w, camera forward),c0.z = 2; REFS as a view-space sphere map (our reading, not decoded); REFP with the decodedcTMAT0(pd_tmat; data converted before it falls back to the per-shader values above). (floorstain) The old REFP mapping (x and height across the arena mesh’s bounds) put a dark-navy env row on the whole Palace floor, which read as saturated blue stains in the wet patches (normal-map alpha) beside the café tables. REFC (cube map) is not reproduced (st03 has a 64² DXT cube, texture 45, that pdconv can’t decode yet).--no-refturns the term off. - Against the Palace clips (Xbox original, st03 blue and st23 red): the tree-hole intro shot looks matte in both originals, and ours matches it with or without the REF term (st03: 2 px change by more than 8/255, st23: 941 px). In st23’s battle footage the floor is about 1.6× brighter than ours at the spawn (luma 65–73 against 42), and REF doesn’t close that gap (42.0 → 42.1). Whatever makes that floor bright, it isn’t the PC REF term as decoded.