0
\$\begingroup\$

So how I'm doing this is a little sketchy but I plan on changing it to either AABBs or spheres once I get it working. So the problem I'm having right now is that the frustum culling I've implemented is only working at certain angles and is not even close to accurate, personally I believe that the problem is at a calculation level. I am fairly new to 3D game development so I just whipped up this class fairly quickly based on some thread I read. My ViewFrustum class can be found here: https://www.dropbox.com/s/3b97bgcwoyh2oq8/ViewFrustum.java?dl=0

So all I'm doing outside this class is calling the update method from my renderer class and I have an ungodly amount of if statements checking if an entity's xyz is within the min and max xyz of the frustum (This is temporary).

So my main question is, am I calculating the frustum right or did I make any mistakes?

Values (when game starts, rotation matrix is a identity matrix) :

  • centerNear: [134.49167, 7.3502045, -271.4365]
  • centerFar : [134.49167, 7.3502045, -1170.7365]
  • points[0-7] :
    • [0] 2607.2214 1714.3507 -621.8992 1.0
    • [1] -2338.238 1714.3507 -621.8992 1.0
    • [2] 2607.2214 -899.70605 -1573.3379 1.0
    • [3] -2338.238 -899.70605 -1573.3379 1.0
    • [4] 136.4149 100.760254 -252.18294 1.0
    • [5] 132.56844 100.760254 -252.18294 1.0
    • [6] 136.4149 98.727104 -252.92294 1.0
    • [7] 132.56844 98.727104 -252.92294 1.0
\$\endgroup\$
  • \$\begingroup\$ It is difficult to take your ViewFrustum class, out of context, and simply "plug it in" to a compatible engine we happen to have handy. Would you please distill your dropbox entry into: "Here's example input: X. Here's the output: Y." We can easily "plug" the camera parameters into a couple of matrices and use a known-good frustum creation method to verify whether the frustums you create are correct or not. Then again, so could you. \$\endgroup\$ – Jon Mar 16 '16 at 0:12
  • \$\begingroup\$ Jon, here is a link to the whole engine: github.com/Zormion/DiodeEngine3D \$\endgroup\$ – Genthorn Mar 16 '16 at 1:54
  • \$\begingroup\$ The main classes of interest would be the 'ViewFrustum' and 'MasterRenderer' classes \$\endgroup\$ – Genthorn Mar 16 '16 at 1:58
  • \$\begingroup\$ Jon, so I changed the rotation matrix to an identity matrix and when walking in an angle that seems -90 degrees from the original angle of the camera when spawned the culling works perfectly until a certain distance away where entities are stopped from rendering right in front of the camera. \$\endgroup\$ – Genthorn Mar 16 '16 at 2:43
  • \$\begingroup\$ Within calculateFrustumVertices, using Identity rotation, please add to your question, the values of: centerNear, centerFar, and points[0-7] \$\endgroup\$ – Jon Mar 16 '16 at 2:50
0
\$\begingroup\$

The effective algorithm here was:

  1. Compute the 8 frustum points (correctly)
  2. Rotate them all by the viewmatrix
  3. Create an AABB that contains the double-rotated frustum
  4. Process entities whose location is contained by the AABB

With no rotation, the coordinates for the frustum corners are relatively straight-forward; most easily noticed is that the FARPLANE's Z-value should be FARPLANE. The included output points have incorrect Z-values. Testing with a rotation of 90 around any axis should produce all of the same magnitudes, just in different components. In both cases, the coordinates were correct up until the very end where they were being transformed by the viewmatrix a second time due to a copy-and-paste error.

That was being obscured by the fact that the frustum tests were being performed against an AABB that contains all of the frustum's corners, rather than the actual frustum. It was probably the correct volume at cardinal directions but in the wrong place. Everywhere else, it was just double wrong. That made testing points against the AABB a crapshoot, at best.

OP intends on replacing current AABB if-else test with typical plane-dot and sphere methods using the corrected frustum.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.