"Radar approach" to Frustum Culling: fail at first simple test?
Asked Answered
T

1

6

Trying to get at least the very simple part 1 of the Lighthouse3D Radar Frustum Culling tutorial to work... and am absolutely baffled that I can't even make that part work in my renderer.

So the first step is: you test if a point is in front the near-plane or behind the far-plane, and early-cull if that's the case. (If not, you'd then perform further tests but I'm stuck just with that first part.)

I use the world-space center (x1y2z3) of a 2x2 cube and have a camera that I can move around and rotate freely. All my vector and matrix stuff must be rather solid as the renderer otherwise works just fine. So here's my take (in Go) of this first part, the simple "Z vs near-or-far" testing:

func (cam *Camera) frustumHasPoint(point *Vec3) bool {
    var pc Vec3
    v := point.Sub(&cam.Controller.Pos)  // point minus camPos
    ref := cam.Controller.dir  // take a copy of camDir
    ref.Z = -ref.Z
    ref.Normalize() // camDir was already normalized but anyway...
    pc.Z = v.Dot(&ref)
    if pc.Z > cam.Perspective.ZFar || pc.Z < cam.Perspective.ZNear {
        return false
    }
    return true
}

Now why do I reverse the Z of ref? Because in the tutorial they write: "Notice that the referential in the figure is not a right hand system (as in OpenGL), because the orientation of Z has been reversed to make the tutorial more intuitive" -- well, in a GL tutorial of course this has the opposite effect...

Well if do reverse Z as above, it culls more than it should about 50% of the time; if I don't, then it "over-culls" about 98% of the time..

Wwhat am I missing?

Trossachs answered 7/3, 2013 at 2:36 Comment(2)
I believe all z coordinates should act alike. (e.g. v.z should be mirrored too.)Lamberto
What's cam.Controller.dir - the line-of-sight (the vector the camera is oriented along)? If so, you don't want to negate z. Assuming that both your camera and point are in world coordinates (i.e., with all transforms [e.g., translates, scales, etc.] applied to them), aside from the Z negation, the rest of your math looks reasonable. Reversing Z will make your dot product negative, which seems like it would cause almost all your points to be culled if your near and far values are positive.Norword
T
1

Resolved. Cause was brain malfunction... the tutorial clearly writes about getting the x/y/z axes first for describing the frustum, somehow I missed that..

Trossachs answered 9/3, 2013 at 2:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.