Culling(Partially outside)

I am trying to describe my problem with the image below. Actually the only thing I want to render is the blue sphere. My problem is that both the yellow one and the purple spheres will be partially inside as I understand. How to handle this?

I am trying to use the technique described here,
http://www.gamedev.net/community/forums/topic.asp?topic_id=224424&whichpage=1
under the “Behold the magic:” topic.

So how do you handle this situation?

Best regards

You transform the points of the objects’ bounding boxes manually using the perspective and modelview matrices and perform the W divide, the results being in the range of -1 to 1 on all axes, -1 and 1 being the boundaries of the frustum. If all are beyond the same frustum boundary, it’s culled. This applies to the near/far planes too so the purple is culled. The yellow is culled because all of its points are outside of the bottom plane.

I did find a few undocumented tricks; for a start, if a point’s Z coordinate in eye space is negative, invert its clip X and Y to correct them as they seem to flip when they cross eye zero.

Thanks for your replay, but what is the W divide? Google is only giving wakeboard suggestions so I guess thats wrong. :slight_smile:

When transforming a point into clip space, you have to take the entire unused row of the 4x4 matrix (the W component) and divide the XYZ components by it.

No, that’s not the W divide. The W divide, a.k.a. perspective divide, is dividing the XYZ coordinates of each point by that point’s own W coordinate. There is no matrix multiplication at all. That’s the standard conversion from homogeneous coordinates to Euclidean coordinates.

That’s what I meant. It’s not exactly obvious what the W coordinate is though. I can’t think of anywhere else it’s used. It’s built from the W row of the matrix.

I do have a working frustum culling implementation. Which is something I’m pretty proud of given I didn’t take A-level Maths so I had to teach myself my own perspective on 3D math and my terminology is often a bit off.

I do get your point though, it sounds like I’m telling him to divide it by the matrix rather than the point generated by it.

I know there’s a lot of confusion about the W coordinate in OpenGL land. Typically you start out with Euclidean geometry (i.e., just an X, Y and Z coordinate for each vertex). In such cases, OpenGL assigns a W coordinate with a value of 1.0 to each such point when it is first loaded into the GL pipeline. This converts your vertices to homogeneous form, though they’re still Euclidean since all the W are 1.0 .

For the typical perspective transform, the projection matrix just causes each vertex’s Z coordinate to be copied to its W coordinate. For an orthographic projection, each vertex’s W coordinate is left alone by the projection matrix. (There are other projections possible than just these two types. But whatever it is, it involves defining the W coordinate in some way.)

When the OpenGL pipeline does its perspective divide for each vertex before the rasterization step, it divides the X, Y, and Z by W. This is true even in the programmable shaders pipeline.

Dividing X, Y, and Z by W is actually the standard mathematical way of transforming homogeneous coordinates to Euclidean coordinates, which is why OpenGL uses this seemingly screwy way of doing the perspective divide.

Anyway, nothing says you have to use Euclidean geometry with OpenGL. You don’t have to implicitly or explicitly define the vertices of your geometry with W coordinates that equal one. In fact, if you ever work with rational geometry, you will need to define your vertices with W coordinates that are not all equal to one. If you do this, then you can’t do things in OpenGL the way they are typically done, though. At some point, you will have to convert your geometry from your homogeneous coordinate system to Euclidean by dividing your X, Y, and Z by your W, then assign 1.0 to W and then you can go about all the stuff the way people usually do in OpenGL for the projection transformation.

You might wonder, fine, but does anybody ever actually use rational geometry with W coordinates that don’t all equal one? The answer is: Yes! Rational Bezier curves and surfaces (and by extension NURBS curves and surfaces) all use the W coordinate to do their thing. They need to do this in order to represent any conic sections exactly, the most important of which are circles and circular arcs, but also ellipses and hyperbola (parabolas can be represented exactly without resorting to rational representations). This all gets really interesting with programmable shaders.

I… see.

Sorry
I don’t get this. Do I have to multiply each bounding box vertex with the perspective and view matrix, before I do the culling. Isn’t this very expensive?

My VF are defiened i world space? I is moving around but are in the range 0-3000 far and near.

I don’t get this. Do I have to multiply each bounding box vertex with the perspective and view matrix, before I do the culling. Isn’t this very expensive?

Yeah, it is, so don’t do it unless you also need to do the so-called contribution cull, where you cull away AABBs (or whatever), whose projections are too small for your taste.

No I don’t need the contribution cull. I just wont the cull the purple and yellow spheres. I don’t understand how to avoid the partially outside from being rendered as I described in my first post.

Shouldn’t I bather with the yellow and purple spehers?
Because they are partially outside the view frustum. Right?
Sorry for not understanding this yet.