Advertisement

Screen-Space Projected Lines

Started by November 18, 2017 05:24 PM
1 comment, last by Thibault Ober 7 years, 2 months ago

Hello everyone, I was following this article:

https://mattdesl.svbtle.com/drawing-lines-is-hard#screenspace-projected-lines_2

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

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

C9PST.jpg

 

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.

This topic is closed to new replies.

Advertisement