Derivative Shaders Jun 2026

If one pixel in the quad executes the if block, and its neighbor executes the else block (or skips it), the GPU cannot compare the values. The calculation will fail or produce garbage data.

// The normal is the cross product of these two vectors vec3 normal = normalize(cross(dx, dy)); derivative shaders

For most game development and standard visual effects, the coarse derivatives are sufficient and performant. If one pixel in the quad executes the

// Get the rate of change of the world position vec3 dx = dFdx(worldPos); vec3 dy = dFdy(worldPos); // Get the rate of change of the

At their core, derivative shaders leverage — ddx and ddy in HLSL/GLSL. These functions measure how any value changes between neighboring pixels (in x and y screen directions). They’re automatic, free (in compute cost), and reveal the hidden topology of your render.

ddx(normal) approximates screen-space curvature. Use it to deposit “dirt” in concave creases or wear on convex edges. It’s physically inspired but runs at the cost of a few ALU ops.