transformation - OpenGL GL_Position 3D to 2D Screen Space -


i trying understand maths associated converting 3d point 2d screen position. understand process involves moving object space->worldspace->eye space -> clip space -> ndc space -> viewport space (final 2d position on screen)

vertexshader:

gl_position =  projection matrix * view matrix * model matrix * vec(position,1); => clip space. 

fragmentshader:

(pseudo code)   //assuming gl_position received vec4 input variable    vec2 gl_position_ndc = (gl_position.xy/gl_position.w)/2+ .5;    (gl_position_ndc -> gl_fragcolor) after perspective division , converting normalized device coordinate space 

do these automatic perspective divides , ndc conversion in fragment shader happen automatically gl_position received vertex shader described above in fragment shader?

yes, division w automatic after output clip-space vertex in vertex shader.

it happens before rasterization, , therefore before fragment shader runs. now, 1 interesting quirk in window-space (gl_fragcoord) in fragment shader, w = 1/clip_w. if try divide again using gl_fragcoord, undo perspective division , things weird.

there reasons might want divide 1/clip.w, not 1 of them.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -