Exemple #1
0
        public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
        {
            // Get MotionData
            var        camera = renderingData.cameraData.camera;
            MotionData motionData;

            if (!m_MotionDatas.TryGetValue(camera, out motionData))
            {
                motionData = new MotionData();
                m_MotionDatas.Add(camera, motionData);
            }

            // Calculate motion data
            CalculateTime();
            UpdateMotionData(camera, motionData);

            // Motion vector pass
            m_MotionVectorRenderPass.Setup(motionData);
            renderer.EnqueuePass(m_MotionVectorRenderPass);

            // Motion blur pass
            var stack      = VolumeManager.instance.stack;
            var motionBlur = stack.GetComponent <MotionBlur>();

            if (motionBlur.IsActive() && !renderingData.cameraData.isSceneViewCamera)
            {
                m_MotionBlurRenderPass.Setup(motionBlur);
                renderer.EnqueuePass(m_MotionBlurRenderPass);
            }
        }
        public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
        {
            // Get MotionData
            var camera = renderingData.cameraData.camera;

            // These flags are still required in SRP or the engine won't compute previous model matrices...
            camera.depthTextureMode |= DepthTextureMode.MotionVectors | DepthTextureMode.Depth;

            MotionData motionData;

            if (!m_MotionDatas.TryGetValue(camera, out motionData))
            {
                motionData = new MotionData();
                m_MotionDatas.Add(camera, motionData);
            }

            // Calculate motion data
            CalculateTime();
            UpdateMotionData(camera, motionData);

            // Motion vector pass
            m_MotionVectorRenderPass.Setup(motionData);
            renderer.EnqueuePass(m_MotionVectorRenderPass);

            // Motion blur pass
            var stack      = VolumeManager.instance.stack;
            var motionBlur = stack.GetComponent <MotionBlur>();

            if (motionBlur.IsActive() && !renderingData.cameraData.isSceneViewCamera)
            {
                m_MotionBlurRenderPass.Setup(motionBlur);
                renderer.EnqueuePass(m_MotionBlurRenderPass);
            }
        }
        void UpdateMotionData(Camera camera, MotionData motionData)
        {
            // The actual projection matrix used in shaders is actually massaged a bit to work across all platforms
            // (different Z value ranges etc.)
            var gpuProj = GL.GetGPUProjectionMatrix(camera.projectionMatrix, true); // Had to change this from 'false'
            var gpuView = camera.worldToCameraMatrix;

            var gpuVP = gpuProj * gpuView;

            // Set last frame data
            // A camera could be rendered multiple times per frame, only updates the previous view proj & pos if needed
            if (motionData.lastFrameActive != Time.frameCount)
            {
                motionData.isFirstFrame = false;

                if (RecalculatePrevVPWithCurrentP)
                {
                    //Previous View With Current Projection
                    var prevVP = motionData.isFirstFrame ? gpuVP : gpuProj * motionData.viewMatrix;
                    motionData.previousViewProjectionMatrix = prevVP;
                }
                else
                {
                    motionData.previousViewProjectionMatrix = motionData.isFirstFrame ?
                                                              gpuVP : motionData.viewProjectionMatrix;
                }
            }

            // Set current frame data
            motionData.viewMatrix           = gpuView;
            motionData.viewProjectionMatrix = gpuVP;
            motionData.lastFrameActive      = Time.frameCount;
        }
 internal void Setup(MotionData motionData)
 {
     // Set data
     m_MotionData     = motionData;
     m_CameraMaterial = new Material(Shader.Find(kCameraShader));
     m_ObjectMaterial = new Material(Shader.Find(kObjectShader));
 }
Exemple #5
0
 internal void Setup(MotionData motionData, MotionBlur motionBlur, int layerMask)
 {
     // Set data
     m_MotionData     = motionData;
     m_MotionBlur     = motionBlur;
     m_layerMask      = layerMask;
     m_CameraMaterial = new Material(Shader.Find(kCameraShader));
     m_ObjectMaterial = new Material(Shader.Find(kObjectShader));
 }
Exemple #6
0
 internal void Setup(MotionData motionData)
 {
     // Set data
     m_MotionData = motionData;
 }