Shadow volumes (sshadowch, sshadow, sshadowc) and the shadow pass
Decoded from the SSHADOW*
shaders (dxbc_dis.py) and PDUWP.exe
(our reading of the machine code; addresses only
in the branch report). Characters, stage props
and the static stages cast stencil
shadow volumes; nothing else (no shadow
maps, no blob decals).
- Who has them (scan of all
831
.alrfiles withpdconv --stats): every player and enemy character (sshadowch, one buffer per rigid body part), boss and event characters, and most versus stages: prop models 8+ (sshadowch,sshadowon jointed props) and static models 0/8+ (sshadowc). Effects, capsules and skill objects have none.saura(0x0B) are the aura shells, not shadows. - Format 0x07 (16 B):
position 3 × f32, packed 11:11:10 normal (as
stages). One vertex buffer per model; each index
buffer (strip) is one part on its
transform_idxjoint, positions in the joint’s space (they land exactly on the bind-pose body). The meshes are fattened: flat per-face normals, and every edge carries a zero-area quad, so the mesh is closed by position (checked on pc00a: no open edge in any of 19 parts) and stays closed when the vertices that face away from the light move. Format 0x10 (12 B): position only (sshadowc): fixed closed regions, see “Stage volumes” below. - Vertex shaders:
sshadow:p + L · wfor vertices withdot(n, −L) < c0.x, L =cDL_VEC.xyz(direction the light travels, object space), w =cDL_VEC.w.sshadowch: the same plusLadded to every vertex (a 1-unit push along the light).…Pvariants: away from the point lightcP0_POS(lengthcP0_POS.w;sshadowchppushes byc0.z).sshadowc: position only. Pixel shaders: black, alpha 1, nothing else. - Per-draw constants (exe):
cDL_VEC.xyz= a light vector brought into object space by the object’s matrix;cDL_VEC.w= the f32 at material entry + 0x3C, 100.0 in all shadow materials seen (10 m at the 0.1 m unit).c0.xand the light vector’s source are not traced. - Render states (the exe’s
render-state emulation, see “Effect drawing”):
extra state ids 0x44 stencil z-fail op, 0x45
pass op, 0x46 function, 0x47 reference,
0x48/0x49 read/write mask, 0x8F depth enable,
0x90 stencil enable, 0x91 fail op; 0x43 colour
write mask (0x1010101 all, 0x10101 rgb). The
shadow pass:
- volumes: depth test on, depth write off, colour writes off, no culling, two-sided stencil (always pass; keep on pass and fail; depth fail: increment (wrap) on front faces, decrement on back faces), masks 0x1F. That is z-fail (“Carmack’s reverse”); the volumes must be closed, which the fattened meshes are.
- darkening: depth off, stencil
!= 0, colour writes rgb only, blend mode word 0x7601 (source = destination alpha, destination = inverse destination alpha, add), a full-screen rectangle in the shadow colour (alpha forced to 255). Result:shadow · dst_a + scene · (1 − dst_a).
- Shadow colour = light script
0x2001(0, rgb)’s colour. The script calls arrive in a handler table (one function per id from 0x2000) with the arguments in reverse order (0x2000’s first word is the set index); the0x2001handler stores the colour in the global the shadow pass reads, and nothing else reads it. It is dark (st03 15/18/25 of 255, st07 3/0/14, black on st02); pdconv first took it for the background colour (light.jsonclear_color, now alsoshadow_color). - Destination alpha = how much a
surface takes the shadow. The stage
pixel shaders (SD and the other
(4a − 3) · wshaders, see “Stage shaders”) outputalpha = (4a − 3) · (c0.z · max(N·L, 0) + c0.w)with the pixel shader’sc0= (0.8, 0.8, 0.8, 1/124), a constant the exe uploads for those shaders (never written). So an opaque floor facing the light goes 80 % of the way to the shadow colour, a surface facing away ~1 %. - Alpha-test cut-off
(follows): the material bind sets alpha
reference 0, uploaded as
misc_constant.x = ref / 255; the shaders discard(4a − 3) · w ≤ 0, and w > 0, so texels pass when a > 0.75. - Godot
(
PdShadow): Godot 4.7 materials only REPLACE the stencil with one reference value, so the count can’t be kept. Per part: back faces write 1 on depth fail, then front faces write 0 on depth fail (z-fail for one closed volume); parts drawn later can clear an earlier part’s mark where their front face lies behind the surface. The darkening is a second pass of each opaque stage material reading the mark and blending the shadow colour by the alpha above (Godot can’t blend by destination alpha). - What the other layers leave in
destination alpha
(
dxbc_dis.py):SWBOS(characters):o0.w = (4a − 3) · (sat(r.b) · c0.z + c0.w), a = the colour map’s alpha, r = the toon ramp (slot 3) sampled at the two N·L terms. The same form as the stage shaders, with the ramp’s blue channel in place ofmax(N·L, 0), so a character inside a shadow darkens like a floor would. Samec0variable name as the stage shaders; that the exe uploads the same (0.8, 0.8, 0.8, 1/124) to it is our assumption.SDAL(blended layers):o0.w= the texture alpha. What reaches destination alpha also depends on the blend state (not in the .cso, not traced).- Godot: characters get the stage-volume count
in their shader with
max(N·L, 0)for the ramp (the ramp isn’t converted). sdal layers take the weight of the surface below them, i.e. the reading that the layer leaves destination alpha alone: then the full-screen pass’sshadow · d + (layer over surface) · (1 − d)equals the layer, darkened by d, blended over the surface darkened by d. Character and prop volumes darken only the stage materials.
Stage volumes (sshadowc, format
0x10), measured on the Palace variants
(st03/st13/st23, model 0 and the static models
8+):
- Closed regions, not extruded along the stage light. Model 0 has ~2250 triangles, of which ~1590 are zero-area (fattening quads, as on the 0x07 meshes) and ~690 real faces. Only 4 of those (st23: 56) lie along light set 0’s direction, so the mesh is not a silhouette pushed along that light; each variant has its own mesh (bounding boxes equal, faces differ). The vertex shader has no normal input, so nothing moves them at run time: they are fixed regions of space that count as shadow. The 5 open half-edges by position (st03; st23: 3, st13: 0) don’t leave holes: counted along the light on a 256 × 256 grid, every one of the ~23 000 rays through st03/st13/st23 model 0 crosses as many entry faces as exit faces, and the first crossing is always an entry.
- Why the game shows no wedges. z-fail counting gives, at each pixel, back faces behind the surface minus front faces behind it, which for a closed mesh is the number of volumes the surface point lies in, whatever the order of the faces. The data has no holes (above) and a consistent winding (all 14 components of model 0 enclose a positive volume), so the long false wedges we saw came from our REPLACE-only stencil (one mark/clear per part, no count), not from the meshes; which of its failure cases made them (depth ties or the order of faces within the one big part) was not isolated further.
- Godot
(
PdShadow.build_stage_volumes): the same count, taken along the light instead of the view ray (equal for a closed mesh). At stage load the faces not seen edge-on from the light are binned in a light-space grid (0.5 m cells; st03: 812 faces, 196 × 150 cells, 72 464 entries, 45 ms on the test machine, cached for reloads), and the stage shader counts the faces between the light and the surface point (texel fetches, no stencil). A point exactly on an edge two faces share counts for one of them only (a fill rule on edge values taken in a fixed end-point order), and each connected part’s winding is checked on its own (its face nearest the light must be an entry). Faces level with the surface pass a LESSEQUAL depth test (D3D’s default; the volume pass’s depth function isn’t traced) and so don’t count: the point is moved 2 cm along the light (away from it) for that. That is the same side as “just behind, seen from the camera” whenever the surface faces the light, and it is pure depth in light space, so no shadow edge moves with the camera (a move along the view ray shifted edges sideways by up to the 2 cm, differently per camera; on the Palace plaza that flipped 14 floor points between six cameras). The other rule (LESS, toward the camera) changes 0.2–0.4 % of the pixels of a Palace view, as thin lines along shadow edges. Darkening as in the pass above (shadow · a + scene · (1 − a)), once: the character-volume receiver pass skips pixels a stage volume already darkened.--no-stage-shadowsleaves them out (before/after).