예제 #1
0
파일: Camera.cs 프로젝트: johtela/Compose3D
 public Camera(SceneGraph graph, Vec3 position, Vec3 target, Vec3 upDirection, ViewingFrustum frustum,
               float aspectRatio) : base(graph)
 {
     Position    = position;
     Target      = target;
     UpDirection = upDirection;
     Frustum     = frustum;
 }
예제 #2
0
파일: Lights.cs 프로젝트: johtela/Compose3D
        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());
        }
예제 #3
0
파일: Lights.cs 프로젝트: johtela/Compose3D
        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);
        }
예제 #4
0
파일: Camera.cs 프로젝트: johtela/Compose3D
        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);
        }