mattdesl / webgl-lines

some interactive content for a blog post
http://mattdesl.svbtle.com/drawing-lines-is-hard
MIT License
415 stars 37 forks source link

Perspective not corrected #8

Open skrat opened 5 years ago

skrat commented 5 years ago

I checked out your code, adapted to my purposes, and noticed that the perspective doesn't seem to be corrected in the vertex shader. The lines further away from camera are indeed getting thinner. I then cloned your repo, played a bit with the view and projection matrices, and noticed that it does the same thing. Any idea what's going on and how to correct for perspective and have lines with constant width?

Imgur

Also, my code is here https://github.com/skrat/webgl-line-rendering

skrat commented 5 years ago

All right in case anyone ever needs this:

// vertex shader
float t = u_thickness*currentProjected.w;

// fragment, if you do your own anti-aliasing in fragment shader
float t = u_thickness/gl_FragCoord.w;