Filed Under Programming

visits: 1334 | score: 1

posted by sysrpl on Tuesday October 13, 2009 1:13 PMDetermine the arc width θ of your smoothing distance, for example the arc across a pixel by diving your field of view by the number of vertical pixels in your scene.

Convert θ to foreshorten ratio ω using the equation ω = 1 / sin(θ). If your scene's resolution and aspect ratio won't change, this value ω may be held in a constant.

Account for the distance and slope of the surface by multipling ω, z depth, and then dividing by dot product of the eye vector to surface normal vectors to form Ω i.e. Ω = ω * z / dot(eye, normal).

Ω is now the of number world units you'll need to blend with when anti-aliasing your lines.

Example, if we were to create a shader to draw concentric "bullseye" circles:

// rings are spaced 1 unit apart var spacing = 1; // alternating red and white rings are sized equally var line = spacing / 2; // segment is the position of our current fragment inside a ring var segment = distance(fragment.xy, origin) % spacing; // we are going to aa only the right side if (segment < line) then color = red; // here is the aa part else if (segment < line + omega) color = mix(red, white, (segment - line) / omega); // and we are done else color = white;