• Advertisement
Sign in to follow this  

Need help with basic frustum culling

This topic is 818 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

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/

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement