PDA

View Full Version : Frustum planes



Strydon
02-05-2018, 03:31 AM
How can I extract the World view frustum from the mvp.
will the frustum change as the Model matrix changes (ideally I would think from world view the frustum should remain same ).:dejection:

GClements
02-05-2018, 07:03 AM
How can I extract the World view frustum from the mvp.
will the frustum change as the Model matrix changes (ideally I would think from world view the frustum should remain same
The model matrix transforms object space to world space, the view matrix transforms world space to eye space, the projection matrix transforms eye space to clip space. If you want to transform the frustum to world space, you need to use the view and projection matrices but not the model matrix. If you only have a combined model-view-projection matrix, you can only get the frustum in clip space or object space, not in any intermediate space.

If you have separate matrices, then transform a signed unit cube by the inverse of the view*projection matrix. Note that it's possible to construct a projection matrix with the far plane at infinity, in which case the resulting frustum will have vertices at infinity (with w=0). This may or may not be an issue, depending upon what you're planning on doing with the frustum.

mhagain
02-05-2018, 07:08 AM
This approach works well, and contains the mathematical basis and sample code for both OpenGL and D3D: http://gamedevs.org/uploads/fast-extraction-viewing-frustum-planes-from-world-view-projection-matrix.pdf

If the modelview matrix is based on the camera position and/or orientation, and if the camera position and/or orientation changes, then the modelview matrix will also change. Since MV is a component of MVP, it follows that the frustum planes will also change. You should therefore be extracting the frustum planes every frame: it's just a handful of additions/subtractions and a normalize per plane, so it's not like it's going to be even measurable on any performance graph.

Strydon
02-05-2018, 07:46 PM
The model matrix transforms object space to world space, the view matrix transforms world space to eye space, the projection matrix transforms eye space to clip space. If you want to transform the frustum to world space, you need to use the view and projection matrices but not the model matrix. If you only have a combined model-view-projection matrix, you can only get the frustum in clip space or object space, not in any intermediate space.

If you have separate matrices, then transform a signed unit cube by the inverse of the view*projection matrix. Note that it's possible to construct a projection matrix with the far plane at infinity, in which case the resulting frustum will have vertices at infinity (with w=0). This may or may not be an issue, depending upon what you're planning on doing with the frustum.
Thank you for the simplification , here's my dilemma :
http://opengl-tutorial.org/ : I downloaded this tutorial and was trying the tutorial17_rotations (this has two glDrawElements calls 1: Euler rotations 2: Quaternion rotations)
The Model matrix changes for each draw call changes, however the View & Projection matrix remain same for both the drawCalls , given this what/where in MESA/GPU generates the unified frustum for the single view that shows both the Euler & Quaternion objects drawn. (I could be looking at it the wrong way) I assumed that when you create a final scene with multiple draws (with multiple objects) there is a single MVP that actually is responsible for the whole scenes View and what lies outside the Camera View and what lies inside, now given multiple MVP (1 for each object how is the complete scene created), sorry for the long drawn query but any pointers will be helpful.

GClements
02-06-2018, 06:38 AM
Each vertex is transformed by all of the matrices to obtain a position in clip space. The clip-space positions are used for rendering. In clip space, the frustum is just a cube.

If each object has a different model transformation, then the view frustum will be different in each object's coordinate system. But there's rarely any reason to care about that; if you're doing e.g. frustum culling, you'd transform to world space, eye space or clip space for culling.