Advertisement

Need help with basic frustum culling

Started by January 26, 2016 02:27 PM
1 comment, last by eppo 8 years, 7 months ago

I'm making a 3D RTS, and I want to see if a tile is in the window or not. I have been told to multiply the MVP matrix by the vector position (im using the center position) of the tiles, and I am to somehow get some value between -1 and 1 to see if it is in view.

I am confused how I get a value like this from a vec4. Also when I multiply by the position, do I just put 0.0 for the w component?

My view frustum is extremely simple. The tiles will always be within the near and far planes, it's always guaranteed a single tile will not fill the screen etc. I'm looking for fast, but asking people and searching google has not yielded a demonstration of the vec4*mat4 approach.

Help is appreciated/

Put 1 for the w component before the multiply, then divide the resulting vector by the w value after the multiply


// first you find the clipping space matrix
clippingSpacePoint = MVP_matrix * vec4(x, y, z, 1)
// then you normalize the point by dividing by w
clippingSpacePoint.x /= w
clippingSpacePoint.y /= w
clippingSpacePoint.z /= w
// now any point that is on screnn will have a clippingSpacePoint x and y coordinate between -1 and 1
To do this accurately you will need to transform 4 corners of the tile and determine if any point lies inside the -1 to 1 range. You will also need to determine if a tile edge intersect the frustrum. It is possible for a tile edge to be on screen with none of the corners on screen.
My current game project Platform RPG
Advertisement

If you check against w itself, you don't have to do the divide.

Simplest way to test if a tile can be culled is to see if all of its four vertices lie outside at least one of the clipping planes.

This topic is closed to new replies.

Advertisement