Advertisement

frustum culling in detail

Started by November 23, 2002 06:23 AM
2 comments, last by trigger 22 years, 3 months ago
hi all, this post is about frustum culling. up to know i understand every part in this process beside the extracting of the 4 planes. well lets go a bit more into detail. i know that i have to extract the 6 clipping planes and that this is done by multiplying the projection with the modelview matrix and then extracting the plane data, but what i dont know is why i have to multiply both matrices ( i only know what the modelview matrix represents. from the projection matrix i just know that it projects the 3d data to 2d space). i am also not sure what the combined matrix represenst and because of this i have no clue why to extract the plane equations in the way it is done in most frustum culling code/tutorials. i found out that especially in this for understanding important part most tutorials lack. to sum it up. i need some infromations on why to multiply both matrics(projection and modelview), what the new matrix represents, and an in detail explaination how to extract the planes and why it is donethat way. best regeards trigger aka johannes diemke
http://trigger.xenyon.net/
ok,

first things first,

when a point is drawn on the screen in openGL, it is on screen if it is between -1 and 1 on the x and y axis. (i'm not entirly sure on this point, but for the point of this explination, just assume it is)

Now, the model view matrices job is pretty simple. Any vertex that gets rendererd needs to be moved and rotated inverse realtive to the camera position.. Ie, if the camera is at 0,10,0, then all verticies must have 0,10,0 subtracted from their position... They should also be rotated, etc.

The projection matrix, it's job is also pretty simple. I'll get on to that...

Now, consider what would happen if we didn't use a projection matrix...

any vertex that goes in for processing, goes through the model view matrix, and comes out as a position about the camera..

say the camera was at 0,0,0 and wasn't rotated in any way (ie, the model view matrix is an identity matrix), then all vertices do not get modified in any way...

this would mean, that in order for a vertex to be displayed on screen, it would have to be in the range:
x: -1 to 1
y: -1 to 1
z: anything (ignoring z buffer right now)

but hold on, that isn't right...
as something gets further away from the camera (z gets bigger) then it's position on screen (in terms of -1 to 1) gets smaller... ie, a vertex at 0.5,0,1 will appear at 0.5,0 on screen, and a vertex at 0.5,0,10 should appear at 0.05,0 on screen... but as it is now, that won't happen...

This is what the projection matrix is for, it makes that final step from a world coordinate to a screen coordinate... (it also scales z values to between 0 and 1 for storage in the depth buffer)..
To get an idea of how this works mathematically, you'd need to look into multiplying a vector as a 1x4 matrix with a 4x4 translation matrix (which is what the projection matrix and modelview matrix both are)

ie, the final vector used for on screen positioning is the original vector * modelview * projection.. but since the model view and projection matrices are, well, matricies, you can just multiply them together first to save the extra multiplication... This has no effect on the final answer...
ie,
vector*modelview*projection is the same as vector*(modelview*projection)...
hence there is no point in wasting the extra calculations.. they can be done once for all the millions of verticies that will eventually be drawn...


that said, this is why you must multiply the two matrices together in order to get the frustum clipping planes...
so... to get the planes,
When a vector is multiplied through this matrix,
for all vectors that come out with z as -1, they form the near clip plane, where z comes out as 1, you get the far clip plane..
for all vectors that come with x as -1 you get the left clip plane, etc...
This is the rough idea behind how the planes are calculated..

I wouldn't recommend you try and work it out yourself, as there is plenty of code out there that gets these planes for you, but it is important that you know what is actually happening.

I'm pleased you asked, instead of, say, making an assumption to how it works... When you know how things are working behind the scenes you can exploit them

| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |

[edited by - RipTorn on November 23, 2002 10:42:23 PM]
Advertisement
Trigger, quite simply put,

The projection matrix stores the view frustum parameters.

The modelviewview matrix stores your current orientation.

So, the product stores the oriented frustum, which is what you need, since the view may move/rotate.

Hope this helps.

Regs,
HellSpawn
(^-^)
hi,

thanks guys! another problem solved by the help of the gamedev.net community! in addition i got a nice doc about the theory of extracting the planes out of the conmbination of both matrices.

best regards
trigger^a - #opengl [IRCnet]
http://trigger.xenyon.net/

This topic is closed to new replies.

Advertisement