What should the Z coordinate be after transformed by the projection matrix?

by Kazade   Last Updated September 11, 2019 23:13 PM

I'm working on an OpenGL 1.x implementation for the Sega Dreamcast. Because the Dreamcast didn't have any hardware T&L the entire vertex transformation pipeline has to be done in software.

What also has to be done in software is clipping to the near-Z plane as failure to clip results in the polygon being dropped entirely from rendering by the hardware.

I'm having some trouble getting the transform -> clip -> perspective divide process working correctly and basically I can sum up the problem as follows:

  • I transform polygon vertices by the modelview and projection matrices
  • I clip each polygon against the W = 0.000001 plane
  • This results in new vertices on the near plane with a W of 0.000001, but a Z which is twice the near plane distance
  • At perspective divide vertex.z /= vertex.w results in an extreme value because we're dividing a Z value (e.g. 0.2) by 0.000001

Something seems very wrong here. The projection matrix is being generated in the same way as described in the glFrustum docs.

So my question is, if I have a coordinate on the near plane, should its Z value be zero after transform by the projection matrix or should it be the near-z distance, or something else?

After clipping polygons to the W = 0.000001 plane, should the generated Z coordinates be -0.000001?



Answers 1


Well that looks right to me. your projection matrix should be bringing you into normalized device coordinates which range from [-1,1], correct? The Z value should represent your depth and is used by the depth buffer, if I'm not mistaken. If you're in 2D using 4x4 matrices, I would imagine you should expect to see 0 in every Z output, as that zero should cancel out any final results, and if you aren't then I would certainly track down where that Z value is creeping from.

https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix

Jon Koelzer
Jon Koelzer
September 11, 2019 21:31 PM

Related Questions


Matrix for transforming a square to a quadrilateral

Updated March 20, 2019 05:13 AM

FreeGLUT - Making Planets Orbit at their own Speed

Updated April 16, 2018 13:13 PM

OpenGL model transforms wrong on AMD GPU

Updated April 19, 2015 20:05 PM

Coordinates estimation

Updated April 29, 2015 21:05 PM