Problems with screen space rects

Started by
4 comments, last by JoeJ 1 year, 4 months ago

I am having problems with screen space rects.

This is in 3D.

I am changing world space points into screen space points then making a rect from min / max screen points.

The problem I have is when point z is zero or z is less than one.

I have problems with half the rect going behind the camera.

What do I do when points are behind the camera?

How do I handle this?

Advertisement

Tharrior said:
What do I do when points are behind the camera?

You need to clip your polygons against the front clipping plane, but also the other planes of your frustum (cutting off the parts behind it).
Then you project the remaining vertices of the clipped polygons to screenspace, and calculate a bounding rectangle from them.

Unfortunately there is no easier way for robust results.
So basically you need to figure out how frustum clipping works, which was done for any software rasterizer before GPUs came up.

Found some code resources on the topic:

https://www.phatcode.net/res/224/files/html/ch65/65-03.html

https://www.gamers.org/dEngine/quake/papers/ddjclip.html

Thanks.

I know of plane line intersection.

The frustum holds planes and the triangles are made of lines.

That's all I know so far.

Tharrior said:
I know of plane line intersection.

Line intersections alone are not enough. E.g. in this case:

By using only lines to represent polygons, you would miss the (new and clipped) red vertex in the corner of the frustum.

Iirc, i tried something similar many years ago. I tried to use only the front clip plane, i tried to use only lines… but in the end there always were some failure cases.

Plane - polygon isn't hard to do, though. But you need to setup frustum planes, calculate them from a given projection matrix, etc. So it sure is some work…

This topic is closed to new replies.

Advertisement