Skip to content

Instantly share code, notes, and snippets.

@AMZN-alexpete
Created April 6, 2022 20:50
Show Gist options
  • Save AMZN-alexpete/bd2e71d322a0d0175c443b8d733359d3 to your computer and use it in GitHub Desktop.
Save AMZN-alexpete/bd2e71d322a0d0175c443b8d733359d3 to your computer and use it in GitHub Desktop.
Thin line rendering ala Avalanche

From https://www.humus.name/Articles/Persson_GraphicsGemsForGames.pdf Phone-wire AA Siggraph 2012 presentation, Emil Persson, Avalanche Studios

  • Phone wires are long cylinder shapes, define center points, normal and radius
  • Avoid going sub-pixel by clamping radius to half-pixel size, then fade with radius reduction ratio to simulate sub-pixel coverage.
  • Also useful for railings, bars, antenna towers etc.
  • Still need to apply MSAA or other AA solution on top to smooth jaggies
// compute view-space w
float w = dot(viewproj[3], float4(In.Position.xyz, 1.0f));

// compute the radias a pixel wide wire would have
float pixelRadius = w * PixelScale; // Pixel scale is constant derived from projection

// clamp radius to pixel size and fade with reduction in radius vs original.
float radius = max(actualRadius, pixelRadius);
float fade = actualRadius / radius;

// compute final position
float3 position = In.Position + radius * normalize(In.Normal);

Also consider this version of orbit mesh component that used a dynamic torus (from the dynamic mesh component) and scaled the radius based on camera distance/pixel size. https://bitbucket.org/petrocket/flite/commits/d630bc0fb7ea97dcdccc8486c8b0685ef7ce6fbb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment