0
votes

If we have a point in NDC space and we want to transform it to view space using inverse perspective projection, why do we need to apply perspective divide at the end? Shouldn't it be perspective multiplication, since applying the forward perspective projection from view to NDC space has the perspective divide?

I found it here: http://www.cse.chalmers.se/edu/course/TDA362/tutorials/ssao.html

float fragmentDepth = texture(depthTexture, texCoord).r;

// Normalized Device Coordinates (clip space)
vec4 ndc = vec4(texCoord.x * 2.0 - 1.0, texCoord.y * 2.0 - 1.0, 
            fragmentDepth * 2.0 - 1.0, 1.0);

// Transform to view space
vec3 vs_pos = homogenize(inverseProjectionMatrix * ndc);

where

vec3 homogenize(vec4 v) { return vec3((1.0 / v.w) * v); }
1

1 Answers

0
votes

If you want to transform a Homogeneous coordinate to a Cartesian coordinate, you have to transform it so that the w component is 1:

(x, y, z, w) -> (x', y', z', 1)

Therefore you have to divide the 4 components of the coordinate by the w component of the coordinate:

(x, y, z, w) -> (x/w, y/w, z/w, w/w)

When you transform from clip space to normalized device space, this is called Perspective divide.

Note that when transforming from normalized device space to view space, the coordinate is transformed by the inverse projection matrix and not by the projection matrix. You also have to divide by the w component after the inverse projection.
Alternatively you can multiply the normalized device coordinate (x', y', z', 1) by a value selected in such a way that the w component is 1 after the transformation with the inverse projection matrix. However, there is no good reason to go through the effort of finding this value before transforming.