Пример #1
0
        public void SetupViewProj(BoundingBox worldBBox)
        {
            Vector3 lightPos = worldBBox.Center() - LightDir;
            Vector3 up = Vector3.Up;
            LightView = Matrix.CreateLookAt(lightPos, worldBBox.Center(), up);
            Vector3[] corners = worldBBox.GetCorners();
            Vector3[] transformedCorners = new Vector3[8];
            for(int i = 0; i < 8; i++)
            {
                transformedCorners[i] = Vector3.Transform(corners[i], LightView);
            }

            BoundingBox transformedBBox = new BoundingBox { Min = MathFunctions.Min(transformedCorners), Max = MathFunctions.Max(transformedCorners) };

            float width = transformedBBox.Max.X - transformedBBox.Min.X;
            float height = transformedBBox.Max.Y - transformedBBox.Min.Y;
            float near = transformedBBox.Min.Z - 10;
            float far = transformedBBox.Max.Z + 10;
            LightProj = Matrix.CreateOrthographic(width, height, near, far);
            //LightProj = Matrix.CreatePerspective(ShadowWith, ShadowHeight, 0.1f, 10000);
            //LightProj = Matrix.CreatePerspectiveFieldOfView(MathHelper.Pi - 0.5f, 1f, 1f, 1000f);
        }