# Problems with Frustum Culling

This topic is 2089 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey,

I have problems implementing a frustum culling. I don't know why, but it seems that also BoundingBoxes around the NearPlane height are catched too. Its not easy to explain so here a picture:

[attachment=14388:FrustumCulling.JPG]

There you can see the Light-Frustum in the middle. My FrustumChecking for a Box draws me a red-box for "ContainmentType.Intersects", a green-box for "ContainmentType.Disjoint" and a blue-box for "ContainmentType.Contains".. So you can see there are some boxes outside the frustum which are red..

This is my code for building the Frustum with the Lights World and Proj Matrix:

    Public Sub BuildViewFrustum(ByVal ViewMatrix As Matrix, ByVal ProjMatrix As Matrix)
Dim viewProjection As Matrix = Matrix.Multiply(ViewMatrix, ProjMatrix)

'left plane
Planes(2) = New Plane(-viewProjection.M14 - viewProjection.M11,
-viewProjection.M24 - viewProjection.M21,
-viewProjection.M34 - viewProjection.M31,
-viewProjection.M44 - viewProjection.M41)

'right plane
Planes(3) = New Plane(-viewProjection.M14 + viewProjection.M11,
-viewProjection.M24 + viewProjection.M21,
-viewProjection.M34 + viewProjection.M31,
-viewProjection.M44 + viewProjection.M41)

'top plane
Planes(4) = New Plane(-viewProjection.M14 + viewProjection.M12,
-viewProjection.M24 + viewProjection.M22,
-viewProjection.M34 + viewProjection.M32,
-viewProjection.M44 + viewProjection.M42)

'bottom plane
Planes(5) = New Plane(-viewProjection.M14 - viewProjection.M12,
-viewProjection.M24 - viewProjection.M22,
-viewProjection.M34 - viewProjection.M32,
-viewProjection.M44 - viewProjection.M42)

'near plane
Planes(0) = New Plane(-viewProjection.M13,
-viewProjection.M23,
-viewProjection.M33,
-viewProjection.M43)

'far plane
Planes(1) = New Plane(-viewProjection.M14 + viewProjection.M13,
-viewProjection.M24 + viewProjection.M23,
-viewProjection.M34 + viewProjection.M33,
-viewProjection.M44 + viewProjection.M43)

For Each p In Planes
p.Normalize()
Next

'Corners
Dim Ray As Ray = ComputeIntersectionLine(Near, Left)
Corners(0) = ComputeIntersection(Top, Ray)
Corners(3) = ComputeIntersection(Bottom, Ray)

Ray = ComputeIntersectionLine(Right, Near)
Corners(1) = ComputeIntersection(Top, Ray)
Corners(2) = ComputeIntersection(Bottom, Ray)

Ray = ComputeIntersectionLine(Left, Far)
Corners(4) = ComputeIntersection(Top, Ray)
Corners(7) = ComputeIntersection(Bottom, Ray)

Ray = ComputeIntersectionLine(Far, Right)
Corners(5) = ComputeIntersection(Top, Ray)
Corners(6) = ComputeIntersection(Bottom, Ray)

End Sub



and this my Code for testing a box in the frustum

    Public Function Contains(ByVal Box As BoundingBox, ByVal worldMatrix As Matrix) As ContainmentType

BoundingBox.Minimum = Vector3.TransformCoordinate(BoundingBox.Minimum, worldMatrix)
BoundingBox.Maximum = Vector3.TransformCoordinate(BoundingBox.Maximum, worldMatrix)
Dim flag As Boolean = False

For Each P In Planes
Select Case BoundingBox.Intersects(Box, P)
Case PlaneIntersectionType.Front
Return ContainmentType.Disjoint

Case PlaneIntersectionType.Intersecting
flag = True
Exit For
End Select
Next
If not flag Then Return ContainmentType.Contains
Return ContainmentType.Intersects
End Function


What I'm doing wrong? I saw that there was an BoundingFrustum-Class in maybe older versions of SlimDX.. Why they are removed?

##### Share on other sites

Where did you get this routine from?  Are you sure that the algorithm should work, or is this something that you are making from scratch?  I would recommend taking a look at the Wild Magic engine and all of the geometric classes that it has for getting a good and known working implementation.

Once you have it working, I would recommend that you use that for a reference, and then you should set up some unit tests that can detect this type of behavior in your own intersection tests.  That will give you a good reference point from which to build, and you can be sure that you are handling the corner cases that are not working properly now.

1. 1
2. 2
3. 3
Rutin
24
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• ### Forum Statistics

• Total Topics
633650
• Total Posts
3013121
×