Esempio n. 1
0
        public void TestPerspectiveCullingPlanes()
        {
            var vf = new ViewingFrustum (FrustumKind.Perspective, 2f, 2f, -1f, -100f);
            var cp = vf.CullingPlanes (new Mat4 (1f));

            Check.AreEqual (0f, cp[0].Distance);
            Check.AreEqual ((Dir3D.Right + Dir3D.Back).Normalized, cp[0].Normal);
            Check.AreEqual (0f, cp[1].Distance);
            Check.AreEqual ((Dir3D.Left + Dir3D.Back).Normalized, cp[1].Normal);
            Check.AreEqual (0f, cp[2].Distance);
            Check.AreEqual ((Dir3D.Up + Dir3D.Back).Normalized, cp[2].Normal);
            Check.AreEqual (0f, cp[3].Distance);
            Check.AreEqual ((Dir3D.Down + Dir3D.Back).Normalized, cp[3].Normal);
            Check.AreEqual (-1, cp[4].Distance);
            Check.AreEqual (Dir3D.Back, cp[4].Normal);
            Check.AreEqual (100, cp[5].Distance);
            Check.AreEqual (Dir3D.Front, cp[5].Normal);

            Check.IsFalse (InsideFrustum (cp, new Vec3 (-5f, 3f, -3f)));
            Check.IsTrue (InsideFrustum (cp, new Vec3 (-2, 3f, -3f)));
            Check.IsTrue (InsideFrustum (cp, new Vec3 (-3, 3f, -3f)));
            Check.IsFalse (InsideFrustum (cp, new Vec3 (-3, 3f, 0f)));
            Check.IsTrue (InsideFrustum (cp, new Vec3 (3, 3f, -100f)));
            Check.IsFalse (InsideFrustum (cp, new Vec3 (3, 3f, -101f)));
        }
Esempio n. 2
0
 public Camera(SceneGraph graph, Vec3 position, Vec3 target, Vec3 upDirection, ViewingFrustum frustum,
               float aspectRatio) : base(graph)
 {
     Position    = position;
     Target      = target;
     UpDirection = upDirection;
     Frustum     = frustum;
 }
Esempio n. 3
0
        public Mat4[] CameraToCsmProjections(Camera camera, int count)
        {
            var camToLight = Mat.LookAt(-DirectionInCameraSpace(camera), new Vec3(0f, 1f, 0f));

            return((from frustum in camera.SplitFrustumsForCascadedShadowMaps(count, 0.75f)
                    let corners = frustum.Corners.Map(p => camToLight.Transform(p))
                                  let orthoBox = ViewingFrustum.FromBBox(Aabb <Vec3> .FromPositions(corners))
                                                 select orthoBox.CameraToScreen *camToLight)
                   .ToArray());
        }
Esempio n. 4
0
 public Mat4 CameraToShadowProjection(Camera camera)
 {
     var extent = MaxShadowDepth * 0.5f;
     var lightLookAt = -DirectionInCameraSpace (camera);
     var camToLight = Mat.Translation<Mat4> (0f, 0f, -extent)
         * Mat.LookAt (lightLookAt, new Vec3 (0f, 1f, 0f))
         * Mat.Translation<Mat4> (0f, 0f, extent);
     var shadowFrustum = new ViewingFrustum (FrustumKind.Orthographic, MaxShadowDepth, MaxShadowDepth,
         0f, -MaxShadowDepth);
     return shadowFrustum.CameraToScreen * camToLight;
 }
Esempio n. 5
0
        public Mat4 CameraToShadowProjection(Camera camera)
        {
            var extent      = MaxShadowDepth * 0.5f;
            var lightLookAt = -DirectionInCameraSpace(camera);
            var camToLight  = Mat.Translation <Mat4> (0f, 0f, -extent)
                              * Mat.LookAt(lightLookAt, new Vec3(0f, 1f, 0f))
                              * Mat.Translation <Mat4> (0f, 0f, extent);
            var shadowFrustum = new ViewingFrustum(FrustumKind.Orthographic, MaxShadowDepth, MaxShadowDepth,
                                                   0f, -MaxShadowDepth);

            return(shadowFrustum.CameraToScreen * camToLight);
        }
Esempio n. 6
0
        private ViewingFrustum[] CreateSplitFrustums(int splitCount, float logarithmicWeight)
        {
            var splits = CSMFrustumSplit(splitCount, logarithmicWeight);
            var result = new ViewingFrustum[splitCount];

            for (int i = 0; i < splitCount; i++)
            {
                var nearPlane = _frustum.XYPlaneAtZ(splits[i]);
                result[i] = new ViewingFrustum(_frustum.Kind, nearPlane.X, nearPlane.Z, nearPlane.Y,
                                               nearPlane.W, splits[i], splits[i + 1]);
            }
            return(result);
        }
Esempio n. 7
0
        public void TestOrthographicCullingPlanes()
        {
            var vf = new ViewingFrustum (FrustumKind.Orthographic, 2f, 2f, -1f, -100f);
            var cp = vf.CullingPlanes (new Mat4 (1f));

            Check.AreEqual (1, cp[0].Distance);
            Check.AreEqual (Dir3D.Right, cp[0].Normal);
            Check.AreEqual (1, cp[1].Distance);
            Check.AreEqual (Dir3D.Left, cp[1].Normal);
            Check.AreEqual (1, cp[2].Distance);
            Check.AreEqual (Dir3D.Up, cp[2].Normal);
            Check.AreEqual (1, cp[3].Distance);
            Check.AreEqual (Dir3D.Down, cp[3].Normal);
            Check.AreEqual (-1, cp[4].Distance);
            Check.AreEqual (Dir3D.Back, cp[4].Normal);
            Check.AreEqual (100, cp[5].Distance);
            Check.AreEqual (Dir3D.Front, cp[5].Normal);
        }