@modoki/engine / rendering / nprFragmentOutput
Function: nprFragmentOutput()
nprFragmentOutput(
colorRGBA,preserve?):unknown
Helper for custom NodeMaterial shaders rendered into the NPR pass. Wraps a fragment color expression into an outputStruct that writes to all three MRT targets (output / normal / lineColor). Without this, NodeMaterial's fragmentNode path only writes target[0] and WebGPU validation discards the draw because targets[1]/[2] have no fragment output.
The lineColor target's ALPHA carries nprColorPreserve (0..1) — the composite blends the grayscale fill toward this fragment's true color by that amount, so shaders can keep their hue through NPR (see compositeNodes). preserve defaults to the material's nprColorPreserve property (0), so a shader that doesn't care stays fully NPR. A shader can pass a per-pixel node (e.g. a fresnel rim mask) to preserve color only where it wants.
Use from a shader file: mat.fragmentNode = nprFragmentOutput(vec4(myColorRgb, 1.0)); mat.fragmentNode = nprFragmentOutput(vec4(rgb, 1.0), rimMask); // per-pixel
⚠️ FOG HAZARD: if the scene has fog (Fog trait / syncFog), leaving this material's default fog = true breaks the draw. NodeMaterial.setupOutput() runs setupFog() on this outputStruct regardless of fragmentNode, and setupFog REPLACES the whole struct with a single vec4 — collapsing the 3 MRT targets down to 1, which is exactly the "targets[1]/[2] have no fragment output" case above, so WebGPU discards the draw. Prefer applyNprFragmentOutput below, which sets fog = false for you; only call this directly if you intend to handle fog yourself.
Parameters
colorRGBA
unknown
preserve?
unknown
Returns
unknown