Sign in to follow this  
necro1895

Yet another BoundingFrustum-Thread

Recommended Posts

Hy there,
as you can read i still need some hints with the bounding-topics. Some quick information about the stuff i'm trying to do.
I'm coding a small planetary engine with procedural landscapes. Thats working well so far and so i want to implement view dependent LoD. That means i calculate each turn all patches which i have to render. To allocate the concerned patches i need the information whether the patch is in view frustum (camera view) or not.

My camera class is calculating the bounding frustum each turn via multiplying the view and projection matrix. You can see the matrices on the debug messages from the screenshots. The screenshots are showing three states.
1) - Start phase, the patch have to be rendered - you can see the bounding box of it
2) - I'm moving on the x-Axis but the patch is still in view
3) - I'm moving further on the x-Axis and the patch disappears from the view, but the BoundingFrustum doesnt detect that fact. You can see this on the bottom of the debug information (third-last line)

This behaviour is odd and i dont know why. There are less examples for the bounding-topic - especially for BoundingFrustum. So i have to ask you to share your experiences with that topic.

Please ask if you need more information or anything else.

Up vector is y-Axis, and i have a mouseLook camera which is calculating the view matrix from quaternions.

[img]https://lh6.googleusercontent.com/-KLoxtceWoBg/T_mPa4bkV-I/AAAAAAAAA34/ahJdblGxYKY/s1477/+120708153900.png[/img][img]https://lh4.googleusercontent.com/-s9_QVuJXcWc/T_mPbKdHmlI/AAAAAAAAA38/6G9gy6ZdcZw/s1477/+120708153904.png[/img][img]https://lh6.googleusercontent.com/-gfiIJD0naSY/T_mPbIR5RFI/AAAAAAAAA4A/PEOIXMzSMyY/s1477/+120708153916.png[/img]

Share this post


Link to post
Share on other sites
Ok, i found out, that the Frustum is working correctly if i check the containment against a single point. So I'll have to do some researches about the BoundingBoxes. How annoying.. -.-

Share this post


Link to post
Share on other sites
One thing I like to do when debugging frustum culling issues is to add a "freeze culling mode", where the bounding frustum gets locked in place but you can still move the camera around. Then if you draw the frustum and the bounding boxes/spheres, you can see whether or not they actually intersect. Drawing a frustum is pretty easy: just take 8 points that start on the unit cube (-1 <= x <= 1, -1 <= y <= 1, 0 <= z <= 1) and transform them by the inverse of your view * projection matrix, and you'll have the 8 points of the frustum.

Share this post


Link to post
Share on other sites
Nice formula, i will try that. I will compare the result of this with the computed frustum of xna -> frustum.getCorners() should deliver the same values.

Share this post


Link to post
Share on other sites
[color=#000000][font=arial, sans-serif][size=3]After playing around with some matrices i didnt find any matrix which fits the bounding frustum cube. The first one is the inverted matrix of view * projection. The second one was computed by xna via boundingFrustum.Matrix. [/size][/font][/color]

[color=#000000][font=arial, sans-serif][size=3]The screenshot shows the frustum on the start position. I freezed the frustum for strafing rightwards.[/size][/font][/color]

[color=#000000][font=arial, sans-serif][size=3]Whats wrong with these matrices? There are in no cases a trapezium. [/size][/font][/color]

[color=#000000][font=arial, sans-serif][size=3]Btw, i got the same matrix without inverting the view*projection matrix like the frustum matrix. There is something really odd with that. [/size][/font][/color]

[color=#000000][font=arial, sans-serif][size=3]I'm using this[/size][/font][/color]
[color=#000000][font=arial, sans-serif][size=3][CODE]
cubeFrustum.Initialize(Matrix.Invert(camera.matrixView * camera.matrixProjection));
[/CODE][/size][/font][/color]
[color=#000000][font=arial, sans-serif][size=3]and this[/size][/font][/color]
[color=#000000][font=arial, sans-serif][size=3][CODE]
cubeFrustum.Initialize(camera.boundingFrustum.Matrix);
[/CODE][/size][/font][/color]
[color=#000000][font=arial, sans-serif][size=3]and they are calling these function:[/size][/font][/color]
[color=#000000][font=arial, sans-serif][size=3][CODE]
public static Vector3[] CreateCube()
{
Vector3[] cube = new Vector3[8];
int idx = 0;
cube[idx++] = new Vector3(-1, 1, 1);
cube[idx++] = new Vector3(1, 1, 1);
cube[idx++] = new Vector3(1, -1, 1);
cube[idx++] = new Vector3(-1, -1, 1);
cube[idx++] = new Vector3(-1, 1, -1);
cube[idx++] = new Vector3(1, 1, -1);
cube[idx++] = new Vector3(1, -1, -1);
cube[idx++] = new Vector3(-1, -1, -1);
return cube;
}
public static Vector3[] CreateCube(Matrix _transform)
{
Vector3[] cube = EngineHelper.CreateCube();
for (int idx = 0; idx < cube.Length; idx++)
{
cube[idx] = Vector3.Transform(cube[idx], _transform);
}
return cube;
}
[/CODE][/size][/font][/color]
[color=#000000][font=arial, sans-serif][size=3]It works for[/size][/font][/color]
[color=#000000][font=arial, sans-serif][size=3][CODE]
cubeFrustum.InitializeFromVertices(camera.boundingFrustum.GetCorners());
[/CODE] So i just dont understand, why its not the same as the formula above.[/size][/font][/color]
[color=#000000][font=arial, sans-serif][size=3][img]https://lh3.googleusercontent.com/-M-jTVWzGZAI/T_xsLAsJKjI/AAAAAAAAA44/HsL5zlykrD8/s1477/+120710195143.png[/img][img]https://lh6.googleusercontent.com/-fCPGQoceN8s/T_xsMQghc2I/AAAAAAAAA5A/cvrdWEhp018/s1477/+120710195120.png[/img][/size][/font][/color] Edited by necro1895

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this