frustum culling, box outside but still inside

Started by
13 comments, last by nts 19 years, 11 months ago
Using a sphere instead of a box should work in this case.
Say we have a plane Ax+By+Cz+D (one of the 6 frustum planes),
and a sphere of radius R located at position px,py,pz,
if we want to know whether any part of the sphere lies within the frustum or not, we calculate a K factor this way:

K=A*px+B*py+C*pz+D

Now if K+R is negative the sphere is outside the frustum volume.

NOTE: If K+R isn''t negative means that the sphere might be inside the frustum, so we need to keep calculating with the rest of the planes.
Advertisement

I do a sphere check at the beginning before checking all the points of the box. The sphere check fails though, i am using the exact same formula that you listed.
i think you simply missed a little detail. all points of the box have to be outside the SAME frustum plane.
f@dzhttp://festini.device-zero.de
Behold the magic:
void AxisAlignedBox::initLut(){	vertices[0]=Vector3(max[0], max[1], max[2]); vertices[1]=Vector3(max[0], max[1], min[2]);	vertices[2]=Vector3(max[0], min[1], max[2]); vertices[3]=Vector3(max[0], min[1], min[2]);	vertices[4]=Vector3(min[0], max[1], max[2]); vertices[5]=Vector3(min[0], max[1], min[2]);	vertices[6]=Vector3(min[0], min[1], max[2]); vertices[7]=Vector3(min[0], min[1], min[2]);}intersect_type AxisAlignedBox::classifyPlane(const Plane3& p) const{	Vector3 n(p.getNormal());	//const static float EPS(10e-7);	/* Three bit bit mask that is used to indicate sign of the	 * components of the planes normal. lowest bit is z-component	 * and highest is x.	 */	unsigned char bitMask=0;	if(n[0]<0.0f)		bitMask |= (unsigned char)4;	if(n[1]<0.0f)		bitMask |= (unsigned char)2;	if(n[2]<0.0f)		bitMask |= (unsigned char)1;	Vector3 vP(vertices[bitMask]);	Vector3 vN(vertices[(unsigned char)7-bitMask]);	float a=p.getDistance(vN);	if(a>0)		return OUTSIDE;	float b=p.getDistance(vP);	if(b>0)		return INTERSECT;	return INSIDE;}intersect_type AxisAlignedBox::classifyFrustum(const Plane3* p) const{	bool intersecting=false;	for(int i=0; i<6; i++){		intersect_type t=classifyPlane(p[i]);		if(OUTSIDE==t)			return t;		if(INTERSECT==t)			intersecting=true;	}	if(intersecting)		return INTERSECT;	else		return INSIDE;}


There''s a paper explaining the technique: "Optimized View Frustum Culling Algorithms for Bounding Boxes" by Thomas Möller and Ulf Assarsson.
Isn't a box outside the frustum IF and ONLY IF all its points are outside the SAME plane ?
Otherwise in many cases you may cull an object that IS inside the frustum.

(in that case, in rare cases you may select objects that are outside the frustum, but the graphic chip should get ride of that rather quickly. Better send something invisible rather than forget to send something visible)


-* So many things to do, so little time to spend. *-


[edited by - Ingenu on May 10, 2004 7:19:49 AM]
-* So many things to do, so little time to spend. *-

This topic is closed to new replies.

Advertisement