# The Near Plane on a software Rasterizer

This topic is 5079 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hey all Im using the projection matrix described in the Direct3D docs (D3DXMatrixPerspectiveFovRH for compatibility with my D3D apps) however, when verticies are behind the camera they are 'swapped', i mean the vector positions move to the other side of the neighbouring vector (exactly the same gradients, cept inverted). I have no idea whats causing it, and it could be anywhere in my code...does anyone have any ideas. Thanks for any help. Twixn

##### Share on other sites
this is what projection math does. it inverts stuff behind the camera. that's why you must clip to the near plan.

##### Share on other sites
Well, thats fair enough...thanks

Whats the best way to do it? simply shortening the triangle, and splitting it if nessesary? or is there a better way?

Twixn

[Edited by - Twixn on January 17, 2005 3:36:23 PM]

##### Share on other sites
There are several ways to do it; this is called view frustum culling. Here's a couple:

1. Average the z values of the verts in screen space and don't draw if less than some value.

2. Use Sutherland-Cohen clipping to clip a polygon to the planes bounding the frustum.

This is a really good article about (software) rendering pipelines.

##### Share on other sites
Generally, what you want to do is impliment a system whereby if a polygon is entirely outside of one side of the frustrum it is ignored alltogether, if the polygon stradles the frustrom edge it must be clipped (polygons entirely INSIDE the frustrum can be happily accepted :D )

At this point, you're verts should be in Homogenous Clip Space (where the flatened pyramid viewing volume has been squished into a cube.) This simplifies the clipping since each clipping plane will lay along a consistant coordinate, eliminating messy arbitrary plane calculations.

To clip, you find the vertices which are outside the HCS, and calculate the point at which the edge(with a vertex inside the HCS) crosses the appropriate plane. Choose that point as a new vertex and calculate the interpolated color, normal, UV, etc.

Its a little messy, but fairly straight forward.

Heres an excelent article, which goes into it a little bit more:
Clicky

Afterwards, you can head to his index page for all sorts of good reads:
Clicky

##### Share on other sites
Quote:
 To clip, you find the vertices which are outside the HCS, and calculate the point at which the edge(with a vertex inside the HCS) crosses the appropriate plane. Choose that point as a new vertex and calculate the interpolated color, normal, UV, etc.

Thats pretty much what i mean, but so far i transform the verts into view space( vertex is transformed by the ModelMatrix and the ViewMatrix but not the ProjectionMatrix) and clip to the near plane (simple z<=nearPlane, then re-adjust), ive hacked up my own code, still ironing out bugs tho.

Twixn

1. 1
2. 2
Rutin
21
3. 3
A4L
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633740
• Total Posts
3013621
×