Jump to content
  • Advertisement

3D Screen-Space Projected Lines

Recommended Posts

Hello everyone, I was following this article:


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

Link to post
Share on other sites

I didn't read your article in depth but maybe i can help you.

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.

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

  • 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!