3D Clipping from scratch

Started by
7 comments, last by Rompa 16 years, 2 months ago
I am trying to perform 3D clipping in software. Please see this link for the previous discussion: http://www.gamedev.net/community/forums/topic.asp?topic_id=479860 I am having trouble understand how to clip immediately after the application of the projection matrix but before the application of the perspective divide. I am using the same perspective matrix used by OpenGL so that the coordinates are normalized. If I perform clipping after the projection matrix but before the perspective divide, does that mean that I transform all the geometry with the perspective matrix, then I clip, then I divide by "W"?

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

Advertisement
Quote:Original post by Glass_Knife
If I perform clipping after the projection matrix but before the perspective divide, does that mean that I transform all the geometry with the perspective matrix, then I clip, then I divide by "W"?


Correct.
So what is happening to all geometry between the multiplying by the perspective matrix and dividing by "w"? I know the when both are done the coordinates are normalized. Do I just clip and leave the W part the same, or is there something that needs to be done with the W during the clipping.

I also do not understand what the clipping planes are? Are the coordinates still normalized, i.e. (1,1,1) (-1,-1,-1) before dividing by W?

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

OK... I have been playing with this, but I can not see the difference between just clipping the geometry to the frustum, and clipping after the perspective multiply but before the "W" divide.

If there is a difference, I don't know what it is. Any help understand this would be appreciated.

Thanks,

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

Quote:Original post by Glass_Knife
I can not see the difference between just clipping the geometry to the frustum, and clipping after the perspective multiply but before the "W" divide.


The difference is that in clip space the frustum planes have trivial equations (e.g., the left clipping plane is x = -1), while in camera space or world space they can have an arbitrary orientation.
Quote:Original post by Gage64
Quote:Original post by Glass_Knife
I can not see the difference between just clipping the geometry to the frustum, and clipping after the perspective multiply but before the "W" divide.


The difference is that in clip space the frustum planes have trivial equations (e.g., the left clipping plane is x = -1), while in camera space or world space they can have an arbitrary orientation.


I would also imagine that the precision of the clipping will be worse for the geo/frustum clipper, i.e more pixels would end up outside the screen when rendering the final geometry.
This is due to the fact that you do more math AFTER you applied your clipping.
Quote:Original post by Gage64
Quote:Original post by Glass_Knife
I can not see the difference between just clipping the geometry to the frustum, and clipping after the perspective multiply but before the "W" divide.


The difference is that in clip space the frustum planes have trivial equations (e.g., the left clipping plane is x = -1), while in camera space or world space they can have an arbitrary orientation.


I have tried to Google this, but I am not sure what the algorithm is called. If anyone could point me in the right direction, that would be great.

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

Quote:Original post by Glass_Knife
I have tried to Google this, but I am not sure what the algorithm is called.


If you mean a clipping algorithm, I describe one here.
For my clipper I use on the PSP, I clip in mesh space. The reason I do this is so the GPU can perform all transform and lighting, otherwise I'd have to do it all on the CPU which is way too expensive. The main overheads are getting the frustum planes in mesh space (which is actually not that expensive when you "extract" the frustum planes using Gill Gribb's method [sorry if I spelled the name wrong]), and splitting strips into multiple primitives (other strips and fans). The other reason to perform clipping in mesh space is you're dealing with the raw vertex data - it doesn't need to be transformed yet, and the precision is not altered by any transform having been applied later in the pipeline.
There's probably some open source clippers for PSP by homebrew guys somewhere?

This topic is closed to new replies.

Advertisement