front plane clipping

Started by
1 comment, last by Trenki 16 years, 3 months ago
ive got clipping working in my software renderer, the only problem im having is clipping with the front plane. i suspect the problem is due to the world view projection matrix causing the poly to be flipped/inverted/mirrored as it goes behind the focal point. my poly appears to be mirrored/flipped. Any tips on how to fix this problem?
Advertisement
You need to do clipping before you do the perspective projection. The usual way is to leave vertices in homogeneous space and then clip to [+w,-w] in each direction x,y,z (or for some APIs, z clips to [0,+w] instead). This sounds bizarre if you're not used to homogeneous math, but it's the simplest way to do things in the end. You should be able to find some decent summaries of this online - it's a standard part of any 3D pipeline.
The poly should never go through the focal point as it has to be clipped first, so that this case never happens.

The perspective transformation matrix transforms your geometry into clip space with -1 <= x/w, y/w, z/w <= 1. (If you are using the full unit cube as clip space like opengl does it. DirectX has another definition of clip space)

You have to clip triangles which has vertices which are outside this unit cube. This can be determined by simple tests with x < -w || w < x. Similarly for the other coordinates.

This topic is closed to new replies.

Advertisement