Derivative shaders can generate "flat" surface normals on the fly without requiring pre-baked normal maps or vertex normals. By taking the derivatives of the world-space position (reconstructed from depth), a shader can calculate a face normal using a cross product of the horizontal and vertical rates of change. Common Functions and Syntax Function (GLSL) Function (HLSL) Description dFdx(v) ddx(v)
: Because this happens in hardware at the SIMD (Single Instruction, Multiple Data) level, it provides a "free" way to understand how surface properties are changing without complex mathematical modeling. Primary Applications 1. Automatic Mipmap Selection derivative shaders
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. Derivative shaders can generate "flat" surface normals on