Jump to content
  • Advertisement
Sign in to follow this  
Byron

Thick line drawing

This topic is 4367 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

This topic has probably come up a few times, so I apologise if I am re-hashing old ground here: I want to draw thick lines in my DX based renderer. Previously, the way I used to draw thick lines in a 2D system was to get the 'normal' of a line (-y,x) and then project the coordinates out along the normal in both directions to add some thickness to the line. Works fine in 2D but now I need it in 3D. My idea is to use the same method to derive the view coordinates as I do with billboards as seen here and simply work as if in 2D. This will at least allow me to use Z. Does anyone have a better idea or algorithm? I may need to texture the lines at some point... P.S. I have briefly looked at D3DXLine but even with the transform this seems to work in 2D only - i.e I couldn't see how to specify depth into the scene.

Share this post


Link to post
Share on other sites
Advertisement
Damn - thats the exact effect I need to implement but this code needs to run on a system that doesn't have shaders.

Share this post


Link to post
Share on other sites
I could even allow for software vertex shaders - how fast are they in reality, anybody got any experience in using them in anything other than a tech demo?

Share this post


Link to post
Share on other sites
I haven't seen any techdemo that utilizes sw vertex shader for this(or any other) effect, however a friend of mine used sw vertex shader at the times he was developing for really legacy HW(GF 2 and similar; without HW T&L) and it ran rather well. And it being a really simple shader I would give it a try

Share this post


Link to post
Share on other sites
Quote:
My idea is to use the same method to derive the view coordinates as I do with billboards as seen here and simply work as if in 2D. This will at least allow me to use Z.

If you just want straightforward thick lines, this will do the trick. But rather than drawing several parallel lines, which would cause confusion under different coordinate systems, you should use triangles. The technique is similar to billboarding, as you said:

Suppose the line is to be drawn from x0 to x1, and the normalised viewing direction is given by v, both in 3-space. I'll assume that the viewer is positioned at the origin to simplify the arithmetic. If this isn't the case, you'll need to translate everything before you start.
Calculate the direction vector representing the line:

x = x1 - x0

Then take the cross product to get a vector in 3-space that represents the orthogonal compement vector when projected to screen space:

u = Vec3Cross(x, v)

Using this vector, the lines will have uniform thickness regardless of the distance from the viewer. If you want them to thin out as they get further away, you need to normalise:

u = Vec3Normalize(u)

From here you are free to extrude the line into a rectangle

u_half = Vec3Scale(u, LINE_THICKNESS * 0.5f)
DrawTriangle(x0 - u_half, x0 + u_half, x1 + u_half)
DrawTriangle(x1 - u_half, x1 + u_half, x0 - u_half)

where LINE_THICKNESS is in the usual distance units.
Extending this to incorportae textures should be trivial.

Regards
Admiral

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!