home/ atoms/ sdf-map-vec4-auxiliary-channels

Extending map() to return a vec4 provides auxiliary channels for UV coordinates, occlusion, and per-material signals

When map() returns only a vec2 (distance, material ID), the shading pass has no way to access per-surface data computed during geometry evaluation — UVs, local occlusion signals, or blend weights. Extending the return type to vec4 adds two free-use channels (z and w) that propagate alongside the winning material. These can carry procedurally computed occlusion (mouth darkness, candy shadow), UVs for texture application, or any scalar that varies across the surface. The union operator must propagate the full vec4, replacing it whenever the closer material wins. The technique avoids re-evaluating geometry in the shading pass.

Examples

vec4 map(vec3 p){ vec4 res=vec4(1e9,0,1,0); float d=sdEllipsoid(p,r); if(d<res.x) res=vec4(d,2.,1.-smoothstep(0.,0.1,-mouthDist),0.); return res; }

Assessment

Describe one artifact that could occur if the union operator forgets to also copy the z and w channels of the closer material when doing the distance comparison.

“we need to return more things, I'm gonna make this a VEC4, so we can return up to four things, distance, ID, and two arbitrary signals that we are gonna be returning”
corpus · inigo-quilez-live-coding-happy-jumping-video · chunk 24