void OnRenderObject() { _motionVectorMaterial.SetMatrix("_PreviousM", _previousModelMatrix); _motionVectorMaterial.SetMatrix("_PreviousVP", CameraMatrixProvider.GetPreviousVPMatrix(Camera.current)); _motionVectorMaterial.SetMatrix("_NonJitteredVP", CameraMatrixProvider.GetVPMatrix(Camera.current)); _commandBuffer.Clear(); _commandBuffer.SetRenderTarget(BuiltinRenderTextureType.MotionVectors, BuiltinRenderTextureType.CameraTarget); _commandBuffer.DrawMesh(_mesh, transform.localToWorldMatrix, _motionVectorMaterial, 0, 0); Graphics.ExecuteCommandBuffer(_commandBuffer); }
void DrawMotionVectors(ScriptableRenderContext context, Camera camera) { if (motionVectorsRT == null) { // TODO: initializing to 1920x1080 because dynamic scale doesn't work motionVectorsRT = RTHandles.Alloc(new Vector2(1920, 1080), TextureXR.slices, colorFormat: GraphicsFormat.R32G32_SFloat, depthBufferBits: DepthBits.None, dimension: TextureDimension.Tex2D, useDynamicScale: true, name: "MotionVectors"); buffer.SetGlobalTexture("_MotionVectors", motionVectorsRT); } if (motionVectorsDepthRT == null) { // TODO: initializing to 1920x1080 because dynamic scale doesn't work motionVectorsDepthRT = RTHandles.Alloc(new Vector2(1920, 1080), TextureXR.slices, colorFormat: GraphicsFormat.None, depthBufferBits: DepthBits.Depth32, dimension: TextureDimension.Tex2D, useDynamicScale: true, name: "MotionVectorsDepth", filterMode: FilterMode.Bilinear); motionVectorsDepthPrevRT = RTHandles.Alloc(new Vector2(1920, 1080), TextureXR.slices, colorFormat: GraphicsFormat.R32_SFloat, depthBufferBits: DepthBits.None, dimension: TextureDimension.Tex2D, useDynamicScale: true, name: "MotionVectorsDepthPrev", filterMode: FilterMode.Bilinear); buffer.SetGlobalTexture("_MotionVectorsDepth", motionVectorsDepthRT); buffer.SetGlobalTexture("_MotionVectorsDepthPrev", motionVectorsDepthPrevRT); } // swap depth buffer.Blit(motionVectorsDepthPrevRT, motionVectorsDepthPrevRT, motionVecsCopyDepthMat); buffer.SetRenderTarget(motionVectorsRT, motionVectorsDepthRT); buffer.ClearRenderTarget(true, true, Color.clear); buffer.SetGlobalMatrix("_PreviousVP", CameraMatrixProvider.GetPreviousVPMatrix(camera)); buffer.SetGlobalMatrix("_NonJitteredVP", CameraMatrixProvider.GetVPMatrix(camera)); foreach (var component in MotionVectorData.instances) { var materialProps = new MaterialPropertyBlock(); materialProps.SetMatrix("_PreviousM", component.previousModelMatrix); buffer.DrawMesh(component.mesh, component.transform.localToWorldMatrix, motionVectorMat, 0, 0, materialProps); } buffer.SetRenderTarget(BuiltinRenderTextureType.CameraTarget); ExecuteBuffer(context, camera); }