• Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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

Share this post


Link to post
Share on other sites

I'm using line rendering but I already saw the quad method but never tried, on the case of a quad rendering a lerp can surely do the job based on uv too.

Maybe it's good to have a line rendering using quad, convert the line array to quad into the dynamic buffer.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement