Sign in to follow this  

The Near Plane on a software Rasterizer

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

If you intended to correct an error in the post then please contact us.

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 this post


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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this