static MatrixD CreateGlobalMatrix() { var verticesWorldSpace = new Vector3D[8]; MatrixD invView = MyEnvironment.InvViewProjection; Vector3D.Transform(m_cornersCS, ref invView, verticesWorldSpace); var centroid = verticesWorldSpace.Aggregate((x, y) => x + y) / 8f; var view = MatrixD.CreateLookAt(centroid, centroid - MyEnvironment.DirectionalLightDir, Vector3D.UnitY); var proj = MatrixD.CreateOrthographic(1, 1, 0, 1); return(view * proj * MyMatrixHelpers.ClipspaceToTexture); }