lovr icon indicating copy to clipboard operation
lovr copied to clipboard

Frustum Culling Tools

Open bjornbytes opened this issue 7 years ago • 3 comments

LÖVR should give you the tools you need to do frustum culling (without actually trying to do it for you).

This is an interesting problem for VR because there are two cameras and each one has a frustum. Some magic math will need to be used to combine the two frusta into a single one. That combined frustum can be exposed by lovr.headset. I'm not sure what format is best to represent a frustum: mat4? 6 planes? How are planes represented?

From there, there's probably something in lovr.math like mat4:contains or lovr.math.testFrustum that is able to test things against frusta. You could use your own or the one returned from lovr.headset.

When doing the actual tests, need to think about:

  • What sorts of shapes can you test? Points, spheres, AABBs, OBBs?
  • Does it return In/Out or In/Out/Intersects? The latter can be used to optimize certain spatial hashes.

bjornbytes avatar Dec 12 '18 00:12 bjornbytes

i've got more around somewhere, but here's the aabb-frustum test i use in my games https://github.com/excessive/ludum-dare-43/blob/master/src/math/Intersect.hx#L41

shakesoda avatar Dec 12 '18 04:12 shakesoda

lovr.graphics.frustum to render a frustum? Mostly for debugging probably.

bjornbytes avatar Dec 12 '18 05:12 bjornbytes

lovr.graphics can just frustum cull primitives internally because it knows the camera and knows the AABBs of its primitives (can also use AABBs of Models/Meshes when they are provided). It needs to be configurable in case you have a weird vertex shader. Not sure if culling each primitive individually as it's about to be drawn isn't too slow/awful compared to something more fancy.

But also the new physics stuff will also have some kind of Frustum object in case you want to do custom tests/culling/clustering. Headset still ought to expose getFrustum that returns data for one of these objects.

bjornbytes avatar Mar 05 '20 17:03 bjornbytes