Effect drawing (material render state, shaders, mesh element update)

Decoded from PDUWP.exe (our reading of the machine code; addresses only in the branch report) and the .cso set (disassembled with converter/dxbc_dis.py). effectconv.py writes the results as named fields (effect.json version 2); pd_effect.gd draws them.

Render state comes from the material entry, not from the shader. The engine keeps the Xbox render-state numbering (a SetRenderState(state, value) emulation fills a D3D11 blend description: 0x39 ZFUNC, 0x3B alpha-blend enable, 0x3E/0x3F source/destination blend, 0x40 depth write, 0x4A blend op, 0x93 cull mode with 0 none / 0x901 counter-clockwise). The material bind reads, from the 0x4C-byte material entry:

Culling and triangle order. The D3D11 rasterizer description the emulation fills starts as fill solid, cull none, FrontCounterClockwise = 0; state 0x93 maps 0 → cull none, 0x900 → cull front, 0x901 → cull back. So 0x901 drops the triangles that are counter-clockwise on screen and keeps the clockwise ones, and the effect and capsule meshes are stored that way (the visible side of a closed sphere is clockwise seen from outside, in the game’s frame). Godot also draws clockwise faces and culls counter-clockwise ones, and the converter’s Z mirror (paired with the mirrored camera) leaves the image, and so the on-screen winding, unchanged: meshes built directly as Godot arrays keep the game’s index order. (glTF wants counter-clockwise front faces, which is why pdconv reverses the triangles it writes to glTF.) Until 11-03 pd_effect.gd and capsule_look.gd swapped every triangle “for the mirror”, which turned one-sided meshes inside out: the fire shot’s outer additive sphere lost its near half (so the opaque core’s dark texels showed), its camera-facing halo discs were culled entirely, and the capsule core showed its far inside.

Shaders (cbuffer names from the RDEF):

Mesh element update (per frame, from the 0x13 chunk; offsets below are raw_f/raw_m indices). Local frame t = frame − start, window n = end − start + 1. Each channel takes a weight w through the curve its selector names: 0 linear t / n, 1 ease-in t(t+1) / (n(n+1)), 2 ease-out t(2n−t+1) / (n(n+1)) (only 0–2 seen).

Blend, drawn exactly (PdEffect.blend_spec, every effect draw: meshes, particles, trails). The game’s result is op(src × F, dst × G) on a unorm target, so the pixel shader’s output s, a is clamped to 0..1 first. Godot has five fixed blends, so the source term s × F is computed in the shader and the fixed blend supplies the destination term: G = one → add (alpha 1); G = zero, inv src alpha, src alpha → premultiplied-alpha blend with alpha 1, a, 1 − a (dst × (1 − alpha) + rgb); F = zero with G = src color / inv src color → mul with s or 1 − s; reverse subtract with G = one → Godot’s sub (dst − rgb × alpha, alpha 1). dst color / one (548 elements) is dst × (1 + s), which can pass 1. Godot’s mul clamps the factor to 1 (on the compatibility renderer, 0.5 under a mul by 1.5 reads back 0.5), so this pair is drawn through the screen copy below. Dst color / one with reverse subtract is dst × (1 − s), which stays ≤ 1: a mul. The other pairs no fixed blend can make (plain sub src − dst, 2 elements; min / max, which ignore the factors, 5; a dst term in F with another G, 2; reverse subtract with G ≠ one, 1) are computed in full from Godot’s screen texture and written over it: exact over the opaque scene, but Godot copies the screen once before its transparent pass, so effect layers drawn earlier in the same frame are not seen. The frame’s alpha is taken as 1. All 26 pairs in the data (effectconv.py --stats) map to one of these.

pdeftopt06 UV scroll (0x1401a9340, then 0x1401a9400 sets c40..c42). int(raw_m[6]) and int(raw_m[7]) are four signed 4-bit fields each (a nibble above 7 counts as nibble − 16): u and v steps for UV sets 1, 2, 3, 4. Set k’s offset = (u_k, v_k) × the linear window weight t / n, so the texture moves a whole number of repeats over the window. The VS adds c40 to UV set 1 and c41 to UV set 2 after the flipbook. In the data, raw_m[7] = 240 or 241: UV set 2 moves v by −1 and, at 241, set 1 by +1. Godot: PdEffect.opt06_scroll.

pdeftopt05n (18 meshes) is opt05 with one change in its VS. The vertex alpha (vertex color × c35) is multiplied by N·V. N is the vertex normal through the world matrix rows c40..c42 (not normalised, so the world scale counts). V is the unit vector from the world position to cEYEPOS (c15). It is not clamped in the VS, but the PS clamps the color to −1..1, as for opt05. The PS is unchanged. Godot: shader_code(facing).