home/ atoms/ glsl-black-blown-frame-nan

A GLSL shader that compiles but outputs values outside 0..1 or produces NaN renders black or blown-out

A shader that compiles cleanly can still produce a black frame (NaN from 0.0/0.0, pow of negative, sqrt of negative) or a blown-out white frame (color channel > 1.0). Neither produces a compile error. The fix is to clamp the output: clamp(col, 0.0, 1.0) before assigning to gl_FragColor. Additionally, guard all divisions by zero and pow/sqrt of potentially-negative values, and ensure every path assigns gl_FragColor.

Examples

vec3 col = 0.5 + 0.5*cos(u_time + st.xyx + vec3(0,2,4)); is safe. float v = a/b; where b can be 0 → NaN → black.

Assessment

Name three GLSL operations that can silently produce a black or NaN frame, and write the output guard that prevents blow-out.

“Black / blown-out frame** (compiles fine) | color out of `0..1`, `NaN` from `0.0/0.0`, `pow` of negative, uninitialized value | **No error**”
context/ · L5-debug/glsl.md · chunk 1