欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

AABB是否和视锥体相交

程序员文章站 2022-03-13 13:48:34
...

https://www.iquilezles.org/www/articles/frustumcorrect/frustumcorrect.htm
https://old.cescg.org/CESCG-2002/DSykoraJJelinek/
https://zhuanlan.zhihu.com/p/55915345
Optimized View Frustum Culling Algorithms for Bounding Boxes

主要参考:https://old.cescg.org/CESCG-2002/DSykoraJJelinek/

AABB是否和视锥体相交

Figure 2 demonstrates the fact that the conversion of the AABB to the bounding sphere is not exact. If we measure the entire radius of the sphere and the distance from the center of the AABB we can see that we only need to compare its projection to the direction of the normal vector of the tested plane. There is one more dot product compared with the simple sphere-plane test. The following pseudo-code describes more implementation details of this method:

int AABBvsFrustum(AABB *b, FRUSTUM *f)
{
	 float m, n; int i, result = INSIDE;
	 for (i = 0; i < 6; i++) 
	 { PLANE *p = f->plane + i;
	     m = (b->mx * p->a) + (b->my * p->b) + (b->mz * p->c) + p->d;
	     n = (b->dx * fabs(p->a)) + (b->dy * fabs(p->b)) + (b->dz * fabs(p->c));
	     if (m + n < 0) return OUTSIDE;
	     if (m - n < 0) result = INTERSECT;
	 } 
	 return result;
}

Vector (mx,my,mz) represents the center of the AABB. Absolute values of the normal vector of the plane (a,b,c) transform all possible values to the first octant so its dot product with the vector representing a half of the AABB diagonal (dx,dy,dz) will be always positive.

Three different values are possible as the output of the test that determines the continuation of the rendering pipeline.

OUTSIDE: Bounding box is totally outside of the VF so the bounded volume is also outside. The object or the dot hierarchy is eliminated from the further processing.
INSIDE: Bounding box is totally inside of the VF. There is no need for further culling of the geometry of the bounded object or down traversal the hierarchy. This state is also useful information for the software renderer that could avoid the low-level polygon clipping.
INTERSECT: Object could intersect the VF. The down traversal the hierarchy is needed and in the case of leafs the sending of the entire object for culling on the level of the object geometry.

相关标签: Unity