I have some weird problem going on in my openGL shader.
First,, I pass the viewspace position from the vertex shader to the fragment shader like this:
vec4 view_pos = V * M * vec4(world_position.xyz, 1.0);
Then, in the fragment shader, I do this:
vec4 clip_pos = P * view_pos; vec2 ndc_xy = clip_pos.xy / clip_pos.w vec2 ndc_fragcoord = 2.0 * gl_FragCoord.xy / viewport_wh - 1.0
I would expect that
ndc_xy is the same as
ndc_fragcoord; however, when rendering them to textures, they are not nearly the same:
Can someone explain to me the differences? How can I get the same result in
ndc_fragcoord by using view space position or vice versa?
This is important information for me for a later stage, when reconstructing the view space position from the depth. I have already been sitting on this the whole day, and am close to despair.