So, I'm trying to implement frustum culling. The thing here is that before I can do that, I need to understand some things.
First of which, is plane intersection:
My understanding is that a plane can be defined via 3 points; let's call them p0, p1, and p2
.
Given that, we know that the plane's normal can be computed as follows:
(psuedo-code)
vec3 edge0 = p1 - p0;
vec3 edge1 = p2 - p0;
vec3 normal = normalize( cross( edge0, edg1 ) ) // => edge1 X edge2 / length( edge1 X edge2 );
Now, let's say we have a function which basically tells us whether or not a given point "crosses" the plane in some way.
(moar pseudo-code)
bool crossesPlane( vec3 plane[3], vec3 point )
{
vec3 normal = getNormal( plane ); // perform same operations as described above
float D = dot( -normal, plane[ 0 ] ); // plane[ 0 ] is arbitrary - could just as well be the 2nd or 3rd point in the array
float dist = dot(normal, point) + D;
return dist >= 0; // dist < 0 means we're on the opposite side of the plane's normal.
}
The logical reasoning behind this is that, since the view-frustum contains six separate planes ( near, far, left, up, right, bottom ), we'd want to grab each of these six planes and essentially "pass" them to the crossesPlane()
function, for an individual point (one point, six tests for that point).
If one of these six calls to crossesPlane()
returns false
, then we want to cull the point in question, thus effectively resulting in the point being culled by the frustum, and of course the point won't be rendered.
Questions
Note
If there are any implementation differences worth mentioning between D3D and OpenGL for this, it would be certainly appreciated.