Sign in to follow this  
DwarvesH

Is there a way to draw super precise lines?

Recommended Posts

So I'm creating a top down/2.5D/polygons + 2 top down camera game.

 

I snap the polygons to a grid but the game is not pixely.

 

I would also like to add borders to walls. How I did this is drawing the walls a second time, but this time with lines. 

 

But I have found that the rasterizer does not behave exactly as it does for filling polygons as it does for drawing lines. Randomly the end points are not draw, especially for horizontal lines.

 

One can see this in screenshots if you zoom in a bit:

https://dl.dropboxusercontent.com/u/45638513/sprite15.png

https://dl.dropboxusercontent.com/u/45638513/sprite16.spr.png

 

The outlines look a bit rounder at corners.

 

Is there a way to get DirectX to fill the exact border of a triangle with a line? In a portable way?

 

Or maybe I'm overthinking things and shouldn't really care about one pixel.

 

Share this post


Link to post
Share on other sites

Review the rasterization rules and compare them to your code; they are likely related to your issue.

 

Thanks!

 

It seems there is no way to do what I want based on those rules.

 

But I did find a solution that works: drawing the line list a second time, but this time as points.

 

Another problem was that as the lines were snapping to pixels as I was moving my character/camera, they had horrible temporal aliasing with them jittering up and down one pixel.

 

There is again no solution for this except for line AA:

https://dl.dropboxusercontent.com/u/45638513/sprite19.png

 

Or alternatively a post-processing edge detection algorithm.

 

Well, at least now I know how Door Kickers got those thin but soft lines: they must have used line AA too!

http://inthekillhouse.com/wordpress/wp-content/uploads/2013/08/2013_7_24_17_48_59.jpg

Share this post


Link to post
Share on other sites

To go back to the original problem, I find that I get better line drawn rectangles if I am consistent in the direction. So, if I render the lines, say, clockwise (imagine drawing the rectangle on paper without removing the pen), then I see nice corners. If I render, say, both vertical lines top-to-bottom then both horizontal lines left to right, then I get missing corners. I'm not sure if this behaviour is guaranteed or is just a tendency I've noticed across different APIs and hardware.

 

Drawing the dots is a pretty good workaround though.

 

For the jitter/temporal aliasing, would it look better if you could control the scrolling so that it moves only in whole pixels, so you don't get some lines creeping forward when others stay still?

Share this post


Link to post
Share on other sites

 

For the jitter/temporal aliasing, would it look better if you could control the scrolling so that it moves only in whole pixels, so you don't get some lines creeping forward when others stay still?

 

You could try to snap end points to some discrete intervals. 

Share this post


Link to post
Share on other sites

I'm not sure if this behaviour is guaranteed or is just a tendency I've noticed across different APIs and hardware.

This is guaranteed behavior.

 

This is the problem the original poster was having.  Fix it by drawing points in the corners or always drawing such that the current line segment connects to the end of the previous line segment.

 

 

L. Spiro

Share this post


Link to post
Share on other sites
If you want thicker/softer lines, the foolproof solution is to render a quad that bounds every pixel-center that could possibly need shading, and then in the pixel shader, derive an opacity/alpha value from that pixel's distance to the mathematical line.

Share this post


Link to post
Share on other sites

There is more info about rasterization in D3D11 here: https://msdn.microsoft.com/en-us/library/windows/desktop/cc627092%28v=vs.85%29.aspx

 

 


It seems there is no way to do what I want based on those rules.

 

Actually, there is: Have you tried drawing each line individually (i.e., use line list instead of line strip), and adding +1 to the end-points of all lines, in the direction the line is pointing?

 

This is because (from the article mentioned by Josh Petrie):

 

 

Non-antialiased line rendering rules are exactly the same as those for GDI lines.

Edited by tonemgub

Share this post


Link to post
Share on other sites

I honestly don't know how anyone could think "hardware" lines to be usable. Even assuming they get drawn "where expected" they still don't render "as expected" (they don't interact with zooming properly).

 

A relatively old NVidia article on filtered lines.

 

I also want to quote for emphasis:


If you want thicker/softer lines, the foolproof solution is to render a quad that bounds every pixel-center that could possibly need shading, and then in the pixel shader, derive an opacity/alpha value from that pixel's distance to the mathematical line.
I'd go that route myself... even though I've often been confronted with endpoint rendering, mitering and other issues in the past. It would probably be possible to do all this in a set of shaders nowadays and it would sure provide enough quality for 99% of uses in games.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this