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:
- u32 at 0x0C, flags: bit 4 = blending on with the mode word below (else blending off, alpha test “greater than 0” — an opaque draw); bit 9 = depth write (else depth test only); bit 7 = no culling. Effect materials: 0x11 (blend, no depth write) on almost all, 0x01 (opaque) on one material per fire-orb model: the orb’s core sphere.
- u16 at 0x14, blend mode word: bits 8–11 source factor, 12–15 destination factor, 5–7 op, through the exe’s tables: factors 0 zero, 1 one, 2 src color, 3 inv src color, 4 src alpha, 5 inv src alpha, 6 dst alpha, 7 inv dst alpha, 8 dst color, 9 inv dst color, 10 src alpha saturate; ops 0 add, 1 subtract, 2 reverse subtract, 3 min, 4 max. Seen over all 477 effect files (elements): one/one add 10728, src color/one 2243, src alpha/inv src alpha 1560, zero/inv src color 912, src alpha/one 794, dst color/one 548, src alpha/one reverse subtract 256 (darkening smoke), others below 100. The same word is 0x5400 on shadow maps (alpha blend) and 0x1100 on opaque stage materials (blending off there via the flags).
- u16 at 0x18 / 0x1A / 0x1C:
texture 0 / 1 / 2 (Esper-RE: texture, normal,
normal backup; the shader’s t0..t2). Effect
shaders such as
pdmtex01use t0 and t1; the capsule shaders also t2 (see above).
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.
- Item flags override (not used by effects). The material bind also reads a flags word on the draw item (copied from a global when the item is queued): when its bits 0 and 5 are 1 and 0, blending is forced on with the material’s mode word and the item’s alpha (bits 8–15) as the constant blend colour (state 0x4B), depth write from bit 2; bits 0 and 5 both set is the character near-camera fade. Effects queue with that word at 0, so their material flags stand (the fire orb’s core really is opaque); only one stage-object draw sets the forcing value.
- Element colour constant.
c35is the element’s interpolated colour, bytes × 1/255 (no 2× scale); the shader clamps the product to −1..1, so effect brightness comes only from stacking additive layers.
Shaders (cbuffer names from the RDEF):
pdeftbb01(and01r,01c, same code): VS color = vertex color ×c35(the element’s current color), rgb premultiplied by its alpha; UV = uv ×c_SCALES.z×cTEMP.xy+cTEMP.xy×cTEMP.zw+c34.xy. PS: texture × clamp(color), alpha = texture alpha × color alpha, discarded at or belowmisc_constant.x; the second target getsblend_colour.pdeftbb02: as 01 plus a second texture at a second UV set, mixed byc1.pdeftbb03: lit (ambient, one directional, one point light).pdeftbb04: color × facing (N·V), no premultiply.pdmtex01: texture 0 at the scrolled/flipbooked UV plus texture 1 at the plain UV, times texture 1’s alpha, times the color; alpha = color alpha (texture alpha unused).pdeftopt05/05c/05n: heat haze. All 1145 haze meshes use vertex format 0x01 (24 bytes: position, a packed normal at 12, UV at 16, BGRA color at 20; the normal is signed 11:11:10, x in bits 0–10, y in 11–21, z in 22–31, each over its maximum, and every one decodes to unit length). VS: color = vertex color ×c35(no premultiply), the pdeftbb UV (flipbookcTEMP, scrollc34), and the screen position of the vertex pushed against its normal byc36.xyz (projected, +cSCREENOFFSET, then x × 0.5 + 0.5, y × −0.5 − 0.5:c37is the constant (0.5, −0.5, 0.5, −0.5) at 0x1402f8ab0). PS: texture 0’s blue and green, made signed (2v − 1) by the stage’s color-sign state, which the pdeftopt05 setup sets (0xE0000000 = r, g, b signed; thergbsignedconstant), are turned by the stage-2 bump matrix (bumpenv2, cb0[21]) and added to the screen position; the frame copy (bound to stages 1–3 by the setup) is sampled there and multiplied by the clamped color; alpha test as pdeftbb.05nalso fades the alpha by N·V;05cis 05. Per-draw values (the opt03/05/05c/05n classes’ draw slot calls 0x1401a9020 every draw): with w = the element’s weight through the curveraw_f[11]names (the fourth curve; same three curve kinds as the others), the pushc36= lerp(raw_m[8],raw_m[10], w) game units, and the strength s = lerp(raw_m[9],raw_m[11], w) / 512 goes to stage 2’s bump states (ids 0x16..0x19 of the stage-state setter 0x140020c40, cached at 0x1404bafb0 + stage × 16 and copied to pixel constant 0x13 + stage) as the matrix (s, 0, s, 0): the offset is s × the signed (blue, green) texel. (The stage-1 bump states that the blade 0x14019ec80 sets and 0x1401162b0 resets are a different stage; opt05 never reads them.) Of the 1163 haze elements, 1031 have a strength and 621 a push. Godot:PdEffect.haze_atandshader_code(haze)with the screen texture.pdeftopt06(7 meshes, vertex format 0x1E, 28 bytes: position, packed normal at 12 as in 0x01, UV set 1 at 16, BGRA color at 20, UV set 2 at 24; all blend one/one add): stage 0 is the frame copy, read at the screen position of the vertex pushed against its normal byc36(the same push as opt05, set by 0x1401a96a0 withc37= the opt05 constant); stage 1 / 2 are the material’s textures 0 / 1 at two UV sets, each with its own scroll (c40,c41). With F = frame, c = clamped vertex color ×c35, k = clampedc35.rgb (the element color): rgb = F × (1 − k) + k × (F × T1 × c.rgb × c.a + T2 × c.rgb × c.a), alpha 1; each texture can discard where its alpha is 0 (alphakillflags). Godot:shader_code(copy). Not reproduced yet: the integer scroll counters (0x1401a9340 turnsraw_m[6]/raw_m[7]into integer steps, 0x1401a9400 writes c39..c41 from them; all 7 elements haveraw_m[7]= 240 or 241), so it is drawn unscrolled.
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).
raw_f[8]curve of: translationraw_f[4..6]× w (local units), rollraw_f[7]× w (whole degrees, the exe’s 15-bit angle), UV scrollc34.xy = raw_m[6..7]× w. (The earlier reading ofraw_m[7]as a spin rate was wrong: it scrolls the texture.)raw_f[9]curve of: scale = 1 + w ×raw_m[0..2]per axis.raw_f[10]curve of: color = start + (end − start) × w (bytes / 255). Whenraw_m[14]is not 0, odd frames use the two blink colors instead (361 meshes haveraw_m[14]= 1; the frame counter the exe tests is not traced). Godot (PdEffect.mesh_color_at) counts the odd frames from the window start (our reading) and blends the blink pair through the same color curve.- Flipbook:
cTEMP = (1/raw_f[0], 1/raw_f[1], T mod cols, floor(T / cols))with T the frame count from the window start wrapped over cols × rows:raw_f[0]×raw_f[1]is a texture atlas stepped one cell per frame (1 × 1 = none; 4×2, 4×4, 8×4 occur). raw_m[3], facing: 0 = the mesh faces the camera (the exe keeps the matrix’s column lengths and replaces its rotation), otherwise it keeps the effect’s orientation; 2 = no culling, else counter-clockwise faces are culled.raw_m[5]= loop flag (Godot: the local frame wraps over the window,PdEffect.local_frame; 145 meshes have a fractional value, 0.2 to 0.8, so the flag reading is unconfirmed).raw_m[12]selects the matrix source (the mesh setup 0x1401a5940, called from thepdeftbb01draw 0x14011bc30; int(raw_m[12]) through a jump table for 1..8, anything else = the live matrix). Cases: 1 the element’s matrix from its first drawn frame (a 256-entry table at context +0x11080 keyed by effect id and element: 0x14018e880 looks it up, 0x14018a9b0 adds it); 2 the same frozen matrix, but flagged; 3 the matrix that effect-context entry +0xA0 points to, and 4 the same, flagged; 5 a matrix 0xF0 past the effect’s context entry, flagged; 6 the live matrix, flagged; 7 a matrix returned by 0x14018a8b0; 8 the +0xA0 matrix with its translation replaced by the live one. “Flagged” means the draw-time update (0x1401a5ff0) swaps the rotation for the identity: it keeps the source’s position and takes the three axis lengths of the live matrix as the scale. Translation, roll and the facing path are then applied as usual. In the data: 0 → 10824 meshes, 1 → 3244, 6 → 336, 2 → 151, 5 → 131, 8 → 10, 3 → 8 (and a few odd floats in one effect that truncate to 0..9). Godot does 0, 1, 2 and 6 (PdEffect.mesh_source_xform). 3, 5 and 8 need the context matrices, which are not traced yet.- Godot: the spatial shader built per draw
variant in
PdEffect.mesh_materialfollows the two shaders above; the colors go out without a gamma→linear conversion (with it, the orb’s rim rendered dull red instead of the reference’s yellow).
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).