Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit3bb1da2647

README.md

surface_flags

The per-pixel surface-flag field, and the one encoding of it.

A screen-space pass sees a pixel's colour, depth and normal — enough to ask where a surface is and which way it faces, and not enough to ask what kind of surface it is. This field answers that: the geometry pass writes a small set of per-pixel surface properties into the alpha of the G-buffer normal, and any pass that reads @scene.normal reads them back.

ZERO_SURFACE_FLAG_FOG_EXEMPT is the one a material controls today. The pbr shader's receives_fog property drives it, and the screen-space fog passes — heightFog and aerialPerspective — leave an exempt pixel at the colour it shaded to however deep in the medium it stands.

The field is 2 bits, carried in the alpha of an Rgb10a2Unorm target, because the pass that fills the G-buffer already holds the 128 bits of colour a pixel a tile-based GPU keeps on chip at its full tile size. A pixel no geometry wrote reads 0 — no flags — so every flag is opt-in and the sky behaves as an ordinary participating surface.

Pure math, no bindings.

#include "@builtin::shaderModules.surface_flags"

let n = textureLoad(scene_normal, coord, 0);
if !zero_surface_takes_fog(n.a) {
    textureStore(out, gid.xy, base);
    return;
}

A shader that wants a surface exempt declares it from surface() or fragment():

zero_set_fog_exempt(true);   // this pixel takes no fog

The field is a G-buffer channel, so the deferred G-buffer fragment entry is what writes it: an opaque draw on the deferred path. A draw that goes through the forward fragment entry — every draw on the forward path, and the transparent phase on either path — leaves the pixel carrying whatever the surface behind it wrote.