Cause and mechanism
Step switches abruptly at a threshold. If that boundary is finer than a screen pixel, it can alias or shimmer. DDX and DDY estimate how a value changes across neighboring pixels, letting you scale a Smoothstep edge fade to its screen size. A fixed UV width does not keep that fade consistent when the object changes size.
Check and correct the setup
- Compute fwidth(Value) in the fragment stage.
Compare final resolution, edges and flicker - Clamp width above zero and smooth around the threshold using a half-width on each side.
Compare final resolution, edges and flicker - Derivatives across discontinuities can spike. High-frequency patterns may also require integration, LOD, or suitable filtering.
Compare final resolution, edges and flicker
// Custom Function: String mode; Fragment stage
// Inputs: Threshold, Value. Output: Out.
float width = max(fwidth(Value), 1e-5);
Out = smoothstep(Threshold - width * 0.5,
Threshold + width * 0.5, Value);Limits and verification
This approximates a pixel-scale transition; it does not eliminate every moire or temporal artifact. Test distance, resolution, and motion.
A focused diagnostic setup
Compare Step, fixed-width Smoothstep and fwidth on one black/white boundary before testing repeated patterns.
Test in this order
- Compute threshold width from the same fragment-stage value.
Compare final resolution, edges and flicker - Vary distance/resolution and compare pixel-scale transitions.
Compare final resolution, edges and flicker - Restore fine repetition and motion to inspect residual moire/flicker.
Compare final resolution, edges and flicker
Interpret the result
Smoothing one edge cannot reconstruct all subpixel repetition. Discontinuities and high frequencies need appropriate filtering too. Keep derivative work in the supported fragment context.