LWJGL - 3D Frustum Issue

What is a typical set up for frustum culling?

I’ve looked at example codes but the culling is coming out wrong.

Chunks that shouldn’t be rendering are rendering and some aren’t rendering.

This is how I’m setting it up:


Matrix4f.mul(projMatrix, viewMatrix, combinedMatrix);
invProjViewMatrix.load(combinedMatrix);
invProjViewMatrix.invert();
frustum.update(invProjViewMatrix);

And I’m extracting the planes the typical way.

this is how I update my viewMatrix:


setIdentity();
rotate((float) Math.toRadians(camera.getPitch()), new Vector3f(1, 0, 0));
rotate((float) Math.toRadians(camera.getYaw()), new Vector3f(0, 1, 0));
Vector3f cameraPos = camera.getPosition();
translate(new Vector3f(-cameraPos.x, -cameraPos.y, -cameraPos.z));

What’s wrong?

EDIT: Heres what it looks like with me rotating the camera around: (It only renders wire mesh when its “outside” frustum. For debugging purposes.)

Big gif. Takes awhile to load.

UPDATE:

Analysis: When I point the camera at the origin (0,0,0) all chunks render (I have it counting chunks rendered). And as I rotate over to 180degrees away from the origin the chunks stop rendering at a consistent rate as I approach 180degrees. Then if I continue towards 360 back to origin they start rendering as same rate they were disappearing.

I’m stumped…

I think you need to confirm your camera works 100% first, then you will have a correct in to screen vector.

Things to remember when you have a camera like rotation

  1. When you start, up and down rotates around the x-axis
  2. When you rotate left/right around the y axis 90 degrees, up and down now rotates around the z axis
  3. When you rotate the camera matrix, rotate the frustrum at the same time or just rotate the in to the screen vector and then build the frustrum from that

Your image is what it is because your frustrum hasn’t been rotated (it just looks like the viewing angle you had at the start).

Thats what I figured. But the camera is rotating fine. So doesn’t that mean my viewMatrix is rotating? And the projectionMatrix shouldn’t change, right?

Can anyone point me in the right direction?

Not sure im following what your issue is…

can you be specific on what you want to have happen, expect to have happen and what your experiencing.

Will do my best to help

j.

[quote=“jmguillemette,post:6,topic:51392”]

i’m also not sure whats going on tbh.

My frustum isn’t culling properly when I move the camera around. Its hiding chunks and showing chunks completely incorrectly.

Minimal stateless c++ implementation that I use for everything. http://pastebin.com/3uJmYXPT

It’s work in any space you want.(Object, world, view)

If you have lot of shared state you can make it faster and precalculate most of the things but its already really fast(hundred million aabbs per seconds)

check out http://www.iquilezles.org/www/articles/frustumcorrect/frustumcorrect.htm

he’s pointing out what is usualy made wrong when culling frustum.

I tested that method on one of our game and it improved frustum culling accuracy by big 0.2% margin. Using object space aabb’s instead of world space was much bigger win with around 2.5% more objects culled.