• 9
• 9
• 11
• 13
• 9

# D3D/OGL Antialiased line rendering

This topic is 901 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi,

I use FXAA in all my rendering code and for the editor I have lot of line rendering which are aliased.

The only way to have them antialiased is to render them in a render target using MSAA and blend the result on the final target ?

Thanks

Edited by Alundra

##### Share on other sites

Do you draw your lines as line primitives, or as triangles/quads? In the latter case, you can look at the method presented in this article under "Antialiasing":

https://www.mapbox.com/blog/drawing-antialiased-lines/

You basically set a "feather" value in your shader, and when drawing the lines you calculate the line normal for each vertex (thus it needs to be rendered using quads), and by using the interpolated normal value in the pixel shader you can perform manual antialiasing:

        out.vColor = in.vColor;

if(in.width >= FEATHER + 0.01f)
{
float width = length(in.vNormal) * in.width;

// test whether pixel lies outside of the line, or in the feather range
if(width > in.width)
out.vColor.a = 0.0f;
else if(width > in.width - FEATHER)
out.vColor.a *= (in.width - width) / FEATHER; // modify opacity to create antialiasing-effect
}

Though I don't belive this will work for 1-pixel wide lines, at least for me I couldn't get it to render anything with 1-pixel lines & using a feather...

So if you are already using quads to draw lines wider than 1 pixel, this is an somewhat easy alternative to using a separate render target.ö

Edited by Juliean