Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


Problems with Frustum Culling


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 thmfrnk   Members   -  Reputation: 109

Like
0Likes
Like

Posted 21 March 2013 - 12:41 PM

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:

 

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?



Sponsor:

#2 Jason Z   Crossbones+   -  Reputation: 5454

Like
0Likes
Like

Posted 21 March 2013 - 08:42 PM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS