3
votes

On perspective projection, if I use simple projection matrix like:

1 0 0 0

0 1 0 0

0 0 1 0

0 0 1/near 0

, which is just projecting onto the image plane. It can be easily get view space coordinates by discarding and normalizing, I think.

If on orthogonal projection, it even does not need the projection matrix.

But, OpenGL graphics pipeline has the above process, though the perspective projection causes a depth precision error.

Why does it need mapping to clip coordinates and normalized device coordinates?

Added

If I use the above projection matrix,

      1 0 0   0
p = ( 0 1 0   0 )
      0 0 1   0
      0 0 1/n 0

v_eye = (x y z 1)

v_clip = p * v_eye = (x y z z/n)

v_ndc = v_clip / v_clip.w = (nx/z ny/z n 1)

Then, v_ndc can be clipped by discarding values over top, bottom, left, right.
Values over far also can be clipped in the same way before multiplying the projection matrix.

Well, it looks like silly though, I think it's easier than before.

ps. I noticed that the depth buffer can't be written in this way. Then, can't it be written before the projection?
Sorry for silly question and gibberish...

2
I still don't get it. How do you want to clip v_ndc before multiplying by the projection matrix? It doesn't exist before the multiplication. You could only clip v_eye, but in eye space the viewing frustum is not a cube but a truncated pyramid which makes it very hard to clip.BDL
My guess is that device normalized coordinates where introduced because of: 1. they simplify and speed up the HW interpolators for filling polygons. 2. better use the bit depth of HW supported interpolator variables to increase the precision (less pixelated interpolation)Spektre
@Spektre Your interpretation seems to say that NDC was introduced as an optimization. However, it is a necessary space to bring points living in different 4D spaces into a single 3D space, the NDC space. This is done by perspective division.legends2k
@Spektre: actually, rasterization and interpolation happens in window space, not in NDC.derhass

2 Answers

1
votes

In case of orthographic projections, you are right: The perspective divide is not required, but it des not introduce any error, since it is a division by 1. (A orthographic projection matrix contains always [0, 0, 0, 1] in the last row).

For perspective projection, this is a bit more complex: Let's look at the simplest perspective projection:

      1  0  0  0
P = ( 0  1  0  0 )
      0  0  1  0
      0  0  1  0

Then a vector v=[x,y,z,1] (in view space) gets projected to

v_p = P * v = [x, y, z, z],

which is in projektive space.

Now the perspectve divide is needed to get the perspectve effect (objects closer to the viewer look larger):

v_ndc = v / v.w = [x'/z y'/z, z'/z, 1]

I don't see how this could be achieved without the perspective divide.

0
votes

Why does it need mapping to clip coordinates and normalized device coordinates?

The space where the programmer leaves the vertices to the GL to be taken care of is the clip space. It's the 4D homogeneous space where the vertices exist before normalization / perspective division. This division, useful to perform perspective projection, is the mapping needed to transform the vertices from clip space to NDC (3D). Why? Similar triangles.

View Space                               Point
                                           *
                                         / |
                            Proj       /-  |
              Y  ^          Plane   /--    |
                 |               /--       |
                 |            *--          |y
                 |        /-- |            |
                 |     /--    |y'          |
                 | /---       |            |
           <-----+------------+------------+-------
         Z     O | 
                 |-----d------|            |
                 |------------z------------|

Perspective projection is where rays from the eye/origin cuts through a projection plane hitting the points present in the space. The point where the ray intersects the plane is the projection of the point hit. Lets say we want to project point P on to the projection plane, where all points have z = d. The projected location of P i.e. P' needs to be found. We know that z' will be d (since projection planes lies there). To find y', we know

y ⁄ z = y' ⁄ z' (similar triangles)
y ⁄ z = y' ⁄ d  (z' = d by defn. of proj. plane)

y' = (d * y) ⁄ z

This division by z is called the perspective division. This shows that in perspective projection, objects farther, with larger z, appear smaller and objects closer, will smaller z, appear larger.

Another thing which convenient to perform in clip space is, obviously, clipping. In 4D, clipping is which is just checking if the points lie within a range as opposed to the costlier division.

In case of orthographic projection, the projection isn't a frustum but a cuboid — parallel rays come from infinity and not the origin. Hence for point P = (x, y, z), the Z values are just dropped, giving P' = (x, y). Thus the perspective division does nothing (divides by 1) in this case.