Shader code Cg noob here: I’ve created a radial timer with smoothstep shapes inside the fragment shader. Looks great up close, but from a distance the antialiasing is lost. I’ve read mentions that this is common and can be solved with Screen Space derivatives? I there an example of how this is done, or is there a simpler solution? Thanks!
FYI I found a solution using fwidth()
change this:
//Draw progress ring with smoothstep
float alpha = smoothstep(_Inner - _Soften,_Inner, length(i.position.xy))
- smoothstep(_Outer, _Outer + _Soften, length(i.position.xy));
fixed4 finalRingColor = fixed4(_RingColor.rgb, alpha);
to this:
float dist = length(i.position.xy);
float pwidth = fwidth(dist);
float alpha = smoothstep(_Outer, _Outer - pwidth * 1.0, dist)
- smoothstep(_Inner, _Inner - pwidth * 1.5, dist);
fixed4 finalRingColor = fixed4(_RingColor.rgb, alpha);
Better antialiasing from a distance