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?

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.

- ServerfaultXchanger
- SuperuserXchanger
- UbuntuXchanger
- WebappsXchanger
- WebmastersXchanger
- ProgrammersXchanger
- DbaXchanger
- DrupalXchanger
- WordpressXchanger
- MagentoXchanger
- JoomlaXchanger
- AndroidXchanger
- AppleXchanger
- GameXchanger
- GamingXchanger
- BlenderXchanger
- UxXchanger
- CookingXchanger
- PhotoXchanger
- StatsXchanger
- MathXchanger
- DiyXchanger
- GisXchanger
- TexXchanger
- MetaXchanger
- ElectronicsXchanger
- StackoverflowXchanger
- BitcoinXchanger
- EthereumXcanger