1
\$\begingroup\$

Looking at the pipeline of games, I am confused about the necessity of homogeneous coordinates.

For gameplay logic, a 4x3 matrix is enough to handle translation, rotation, and scale. I can't think of anything to require a 4th dimension unless we are making a game of theme about universe, blackhole, time, light speed.

For clipping space, homogeneous clip space just does these things to clip out unwanted parts; \begin{cases} \text{w>0}\\ \text{|x|<|w|}\\ \text{|y|<|w|}\\ \text{|z|<|w|}\\ \end{cases} However the w is the -z value before the final perspective projection. Without a 4th dimension, I can also clip in this way, and map z to the new z value in z-buffer as is. \begin{cases} \text{z<0}\\ \text{|x|<|z|}\\ \text{|y|<|z|}\\ \text{far<z<near}\\ \end{cases} The perspective devide can also be done by dividing z, so the point on your screen space is

\$(-x/z, -y/z, z)\$

Someone says we can tell if a vector is a direction or a point by using w==0 or w==1. But when we write shader or game logic, we probably know what is passed to our code and can just call the corresponding transform function.

\$\endgroup\$
8
  • 1
    \$\begingroup\$ What if you want an orthographic projection? You want a depth buffer, so Z must hold meaningful value, but if you force the division by Z, you get perspective and not orthographic. \$\endgroup\$ Nov 20 at 7:17
  • \$\begingroup\$ @HolyBlackCat maybe use an if-else statement to decide if divide by z? Or make orthographic as a state of gpu? \$\endgroup\$
    – lotsof one
    Nov 20 at 10:32
  • \$\begingroup\$ I also believe you need to allow an arbitrary factor to multiply Z by before doing the perspective division, to allow arbitrary FoV angles. (Or customizable range of Z for clipping and depth buffer, which is effectively the same thing.) \$\endgroup\$ Nov 22 at 9:41
  • \$\begingroup\$ Whether there's value in allowing X and Y to influence the W (aka using a 4x4 matrix) I don't know. \$\endgroup\$ Nov 22 at 9:42
  • \$\begingroup\$ Well, to apply arbitrary fov, I can insert a scale transform using a 3x3 matrix. At clipping step, z is simply compared with near and far. For the common 4x4 approach, in the final camera space, x and y will not affect the transformed w value. \$\endgroup\$
    – lotsof one
    Nov 23 at 10:40

0

You must log in to answer this question.

Browse other questions tagged .