public void Execute() { if (isOrtho) { OrthoCam cam = new OrthoCam { forward = forward, up = up, right = right, position = 0 }; cam.UpdateTRSMatrix(); viewProj = mul(proj, cam.worldToCameraMatrix); } else { PerspCam cam = new PerspCam { forward = forward, up = up, right = right, position = 0 }; cam.UpdateTRSMatrix(); viewProj = mul(proj, cam.worldToCameraMatrix); } invViewProj = inverse(viewProj); }
public override void FrameUpdate(PipelineCamera camera, ref PipelineCommandData data) { float4x4 proj = GL.GetGPUProjectionMatrix(camera.cam.nonJitteredProjectionMatrix, false); float4x4 viewProj; if (camera.cam.orthographic) { OrthoCam cam = new OrthoCam { forward = camera.cam.transform.forward, up = camera.cam.transform.up, right = camera.cam.transform.right, position = 0 }; cam.UpdateTRSMatrix(); viewProj = mul(proj, cam.worldToCameraMatrix); } else { PerspCam cam = new PerspCam { forward = camera.cam.transform.forward, up = camera.cam.transform.up, right = camera.cam.transform.right, position = 0 }; cam.UpdateTRSMatrix(); viewProj = mul(proj, cam.worldToCameraMatrix); } CommandBuffer buffer = data.buffer; buffer.SetGlobalMatrix(_InvSkyVP, inverse(viewProj)); buffer.SetRenderTarget(color: camera.targets.renderTargetIdentifier, depth: ShaderIDs._DepthBufferTexture); buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, skyboxMaterial, 0, 0); }
public static void GetOrthoCullingPlanes(ref OrthoCam orthoCam, float4 *planes) { planes[0] = MathLib.GetPlane(orthoCam.forward, orthoCam.position + orthoCam.forward * orthoCam.farClipPlane); planes[1] = MathLib.GetPlane(-orthoCam.forward, orthoCam.position + orthoCam.forward * orthoCam.nearClipPlane); planes[2] = MathLib.GetPlane(-orthoCam.up, orthoCam.position - orthoCam.up * orthoCam.size); planes[3] = MathLib.GetPlane(orthoCam.up, orthoCam.position + orthoCam.up * orthoCam.size); planes[4] = MathLib.GetPlane(orthoCam.right, orthoCam.position + orthoCam.right * orthoCam.size); planes[5] = MathLib.GetPlane(-orthoCam.right, orthoCam.position - orthoCam.right * orthoCam.size); }
public static void GetFrustumPlanes(ref OrthoCam ortho, float4 *planes) { planes[0] = MathLib.GetPlane(ortho.up, ortho.position + ortho.up * ortho.size); planes[1] = MathLib.GetPlane(-ortho.up, ortho.position - ortho.up * ortho.size); planes[2] = MathLib.GetPlane(ortho.right, ortho.position + ortho.right * ortho.size); planes[3] = MathLib.GetPlane(-ortho.right, ortho.position - ortho.right * ortho.size); planes[4] = MathLib.GetPlane(ortho.forward, ortho.position + ortho.forward * ortho.farClipPlane); planes[5] = MathLib.GetPlane(-ortho.forward, ortho.position + ortho.forward * ortho.nearClipPlane); }
public static void GetFrustumCorner(ref OrthoCam orthoCam, float distance, float3 *corners) { float3 farPoint = orthoCam.position + distance * orthoCam.forward; float3 upVec = orthoCam.size * orthoCam.up; float3 rightVec = orthoCam.size * orthoCam.right; corners[0] = farPoint - upVec - rightVec; corners[1] = farPoint - upVec + rightVec; corners[2] = farPoint + upVec - rightVec; corners[3] = farPoint + upVec + rightVec; }
public static void GetFrustumCorner(ref OrthoCam orthoCam, float3 *corners) { float3 upVec = orthoCam.size * orthoCam.up; float3 rightVec = orthoCam.size * orthoCam.right; void GetCorner(ref OrthoCam ortho, float dist) { float3 farPoint = ortho.position + dist * ortho.forward; corners[0] = farPoint - upVec - rightVec; corners[1] = farPoint - upVec + rightVec; corners[2] = farPoint + upVec - rightVec; corners[3] = farPoint + upVec + rightVec; corners += 4; } GetCorner(ref orthoCam, orthoCam.nearClipPlane); GetCorner(ref orthoCam, orthoCam.farClipPlane); }
public override void FrameUpdate(PipelineCamera camera, ref PipelineCommandData data) { SkyboxMatrixData skyData = IPerCameraData.GetProperty(camera, () => new SkyboxMatrixData(), this); float4x4 proj = GL.GetGPUProjectionMatrix(camera.cam.nonJitteredProjectionMatrix, false); float4x4 viewProj; if (camera.cam.orthographic) { OrthoCam cam = new OrthoCam { forward = camera.cam.transform.forward, up = camera.cam.transform.up, right = camera.cam.transform.right, position = 0 }; cam.UpdateTRSMatrix(); viewProj = mul(proj, cam.worldToCameraMatrix); } else { PerspCam cam = new PerspCam { forward = camera.cam.transform.forward, up = camera.cam.transform.up, right = camera.cam.transform.right, position = 0 }; cam.UpdateTRSMatrix(); viewProj = mul(proj, cam.worldToCameraMatrix); } CommandBuffer buffer = data.buffer; buffer.SetGlobalMatrix(_InvSkyVP, inverse(viewProj)); buffer.SetGlobalMatrix(_LastSkyVP, skyData.lastVP); targets[0] = camera.targets.renderTargetIdentifier; targets[1] = camera.targets.motionVectorTexture; buffer.SetRenderTarget(colors: targets, depth: camera.targets.depthBuffer); buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, skyboxMaterial, 0, 0); skyData.lastVP = viewProj; }