# 3D Screen-Space Projected Lines

## Recommended Posts

And I'm trying to understand how the algorithm works. I'm currently testing it in Unity3D to first get a grasp of it and later port it to webgl.

What I'm having problems with is the space in which the calculations take place. First the author calculates the position in NDC and takes into account the aspect ratio of the screen.  Later, he calculates a displacement vector which he calls offset, and adds that to the position that is still in projective space, with the offset having a W value of 1. What's going on here? why can you add a vector in NDC to the resulting position of the projection? what's the relation there?. Also, what is that value of 1 in W doing? shouldn't it be 0 ?

Supposedly this algorithm makes the thickness of the line independent of the depth, but I'm failing to see why.

Any help is appreciated. Thanks

Edited by ramirofages

##### Share on other sites

When you apply a perspective projection matrix you are reducing your x coordinate to fitt on the front plane of your frustrum. The farther you are the more your x will be reduced.

This is a perspective projection matrix i got from there: https://gamedev.stackexchange.com/questions/120338/what-does-a-perspective-projection-matrix-look-like-in-opengl/120345

As you see your resulting x will be devided by aspect it's done when you do:

 position = projection * view * model * vPos;

So i think the autor is trying to remove the perspective effect.

I don't what the autor called nextScreen, currentScreen but maybe their difference is a constant and he use it to offset the resulting position.

the important thing here is how he compute his normal

vec2 normal = vec2(-dir.y, dir.x);

he take the perpendicular vector along the line your are trying to draw, y -> -y

and he modify the current position of your fragment by some amount along this normal, add a width to your line.

I aggree with you adding a vector with a w of 1 is a bit strange.

But in the end you gl_position will be divided by its own w, maybe adding 1 is not such a big deal.

Try to replace it by 0 and look the result.

## Create an account

Register a new account

1. 1
Rutin
34
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633332
• Total Posts
3011401
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

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!