PDA

View Full Version : Rending Lines On Hardware


tobeythorn
03-09-2009, 08:35 PM
I have been unable to find much information on rendering lines using shader pipelines. I've seen really amazing line effects in "demos". What kind of techniques do you use?

Goz
03-10-2009, 12:47 AM
WEll a nice easy way of drawing lines is to draw 2 very long and not very wide triangles as a rectangle. Then apply a texture to these triangles and bob's your mother's brother.

tobeythorn
03-10-2009, 09:00 AM
Goz,
Yes, but then there are issues if you look at the line-segment from nearly along it's axis. Perhaps there are ways to draw a line without using polygons or the fixed pipeline?

monjardin
03-10-2009, 12:33 PM
Point the lines at the camera like a billboard... and I thought Bob was your dad's brother?

JarkkoL
03-10-2009, 12:56 PM
You can render 1 pixel thick lines with line primitives.

Kenneth Gorking
03-10-2009, 01:09 PM
I'm pretty sure you can make them whatever thickness you want, consult the API docs for more info.

As for doing rendering with them, I would be surprised if it was any different than rendering with regular triangles...

JarkkoL
03-10-2009, 01:33 PM
Changing the line thickness isn't possible in D3D9 at least. Rendering with line primitives is just much simplier than using triangles.

TheNut
03-10-2009, 04:20 PM
DX9 doesn't support line thickness? That's primitive! (no pun intended ;)

While extremely odd, you could render a quad (ie: your canvas) to take up the full screen. Pass the quad into your vertex shader along with a point of origin, a vector, and a scalar value as variables. I take it you're familiar with the line equation, L = P + t (V)? The vertex shader would simply convert the values into tangent space (trivial with a quad), if not already done. Inside the fragment shader, you can render a pixel if the (U,V) values intersect or come within range of the line. You could do this for any shape or curve so long as the shader supports the math and instruction set. Although I can't fathom why anyone would want to go to such lengths.

Kenneth Gorking
03-11-2009, 07:47 AM
Changing the line thickness isn't possible in D3D9 at least.
Now that's just silly. Another fine reason to switch to OpenGL (a simple call to glLineWidth()) :lol:

If that is not an option, try looking into ID3DXLine (http://msdn.microsoft.com/en-us/library/bb174016(VS.85).aspx), it should do the trick.

JarkkoL
03-11-2009, 08:01 AM
You are pretty short in reasons if that's a reason to switch to OGL ;)

.oisyn
03-11-2009, 08:23 AM
Pfff, lines are so 1995 ;)

tobeythorn
03-11-2009, 09:39 AM
I suppose my question was what are techniques to draw lines that aren't "1995"

donutFingers
03-12-2009, 05:05 AM
Are you looking for something like this (http://www.ziggyware.com/readarticle.php?article_id=135)? It's XNA but I'm pretty sure the concept is the same?

Mihail121
03-12-2009, 06:19 AM
Pfff, lines are so 1995 ;)

1995 was a good year first and there are applications and applications second :) I'm sure you know very well that lines have their place under the sun.

.oisyn
03-12-2009, 06:42 AM
It was a joke, don't take it too seriously ;)

Mihail121
03-12-2009, 07:07 AM
It was a joke, don't take it too seriously ;)

Must....kill.... .oisyn.... must

tobeythorn
03-12-2009, 08:44 AM
donutFingers,
Yes, like that example, but also I have seen things like glowing lines, and a variety of different line effects. Can lines be drawn using fragment shaders?

Kenneth Gorking
03-12-2009, 09:55 AM
I would suspect so. Glow, however, is probably done in a post-processing pass.

juhnu
03-14-2009, 10:11 AM
donutFingers,
Yes, like that example, but also I have seen things like glowing lines, and a variety of different line effects. Can lines be drawn using fragment shaders?
Sure you can. All the techniques are more or less based on rendering two triangles per line segment. What you need to do in your fragment shader is to calculate the shortest distance of pixel being rendered from the ideal line and adjust opacity and color accordingly (the farther away you are less opaque the pixel should be). You can also use a gradient texture (instead of using math to calculate opacity values), which makes it easier to do different kind of lines and give more room for artist to experiment.