public Camera(SceneGraph graph, Vec3 position, Vec3 target, Vec3 upDirection, ViewingFrustum frustum, float aspectRatio) : base(graph) { Position = position; Target = target; UpDirection = upDirection; Frustum = frustum; }
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()); }
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); }
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); }