예제 #1
0
 /// <summary>
 /// Update projections
 /// </summary>
 private void UpdateLens()
 {
     if (this.mode == CameraModes.Ortho)
     {
         this.Projection = Matrix.OrthoLH(
             this.viewportWidth,
             this.viewportHeight,
             this.nearPlaneDistance,
             this.farPlaneDistance);
     }
     else
     {
         this.Projection = Matrix.PerspectiveFovLH(
             this.fieldOfView,
             this.aspectRelation,
             this.nearPlaneDistance,
             this.farPlaneDistance);
     }
 }
예제 #2
0
        /// <summary>
        /// Updates the matrix set
        /// </summary>
        /// <param name="camera">Camera</param>
        /// <param name="lightDirection">Light direction</param>
        public void Update(Camera camera, Vector3 lightDirection)
        {
            // Find the view matrix
            lightPosition = camera.Position + camera.Direction * cascadeTotalRange * 0.5f;
            Vector3 lookAt     = lightPosition + (lightDirection) * camera.FarPlaneDistance;
            Vector3 up         = Vector3.Normalize(Vector3.Cross(lightDirection, Vector3.Left));
            Matrix  shadowView = Matrix.LookAtLH(lightPosition, lookAt, up);

            // Get the bounds for the shadow space
            ExtractFrustumBoundSphere(
                camera,
                cascadeRanges.First(),
                cascadeRanges.Last(),
                out BoundingSphere boundingSphere);

            // Expand the radius to compensate for numerical errors
            shadowBoundRadius = Math.Max(shadowBoundRadius, boundingSphere.Radius);

            // Find the projection matrix
            Matrix shadowProj = Matrix.OrthoLH(
                shadowBoundRadius,
                shadowBoundRadius,
                -shadowBoundRadius,
                shadowBoundRadius);

            // The combined transformation from world to shadow space
            worldToShadowSpace = shadowView * shadowProj;

            toCascadeOffsetX = Vector4.Zero;
            toCascadeOffsetY = Vector4.Zero;
            toCascadeScale   = Vector4.Zero;

            if (this.AntiFlicker)
            {
                UpdateAntiFlicker(camera, shadowView);
            }
            else
            {
                UpdateSimple(camera);
            }
        }