“雷达方法”用于视锥体剔除:在第一个简单测试中失败了吗?

huangapple go评论86阅读模式
英文:

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

问题

尝试至少使Lighthouse3D雷达视锥体裁剪教程的第一部分工作...但是我完全不明白为什么我甚至不能使我的渲染器中的那部分工作。

所以第一步是:测试一个点是否在近平面前面或远平面后面,并在这种情况下进行早期裁剪。(如果不是,则进行进一步的测试,但我只卡在了第一部分。)

我使用一个2x2立方体的世界空间中心(x1y2z3),并且有一个可以自由移动和旋转的相机。我的向量和矩阵处理必须相当可靠,因为渲染器本身工作得很好。所以这是我对这个第一部分的理解(使用Go语言),简单的“Z vs近平面或远平面”测试:

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
}

现在为什么要反转ref的Z?因为在教程中他们写道:“请注意,图中的参考系不是右手坐标系(如OpenGL中的),因为Z的方向已经被反转,以使教程更直观” - 好吧,在GL教程中当然会产生相反的效果...

如果像上面那样反转Z,它会比应该裁剪的多裁剪约50%的时间;如果不这样做,它会在大约98%的时间内“过度裁剪”...

我错过了什么吗?

英文:

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?

答案1

得分: 1

已解决。原因是大脑功能失调...教程明确写道,首先获取x/y/z轴来描述视锥体,不知何故我错过了这一点..

英文:

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..

huangapple
  • 本文由 发表于 2013年3月7日 10:36:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/15262048.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定