Exemple #1
0
 private GTCommands()
 {
     settingsCommands    = new SettingsCommands();
     calibrationCommands = new CalibrationCommands();
     autotuneCommands    = new AutotuneCommands();
     videoViewerCommands = new TrackerViewerCommands();
     cameraCommands      = new CameraCommands();
 }
Exemple #2
0
        void OnWillRenderObject()
        {
            var cam = Camera.current;

            if (cam.cameraType == CameraType.Preview)
            {
                return;
            }

            if (!sm_cameraCommands.ContainsKey(cam))
            {
                var copyBackground = new CommandBuffer();
                copyBackground.name = "Copy fluid background";
                int fluidBackgroundID = Shader.PropertyToID("_FluidBackground");
                copyBackground.GetTemporaryRT(fluidBackgroundID, -1, -1, 0);
                copyBackground.Blit(BuiltinRenderTextureType.CurrentActive, fluidBackgroundID);
                cam.AddCommandBuffer(CAMERA_EVENT, copyBackground);
                var cameraCommands = new CameraCommands();
                cameraCommands.copyBackground = copyBackground;
                sm_cameraCommands.Add(cam, cameraCommands);
                if (sm_cameraCommands.Count == 1)
                {
                    Camera.onPostRender += RemoveCommandBuffer;
                }
            }

            int depthPass     = m_prepareFluidMaterial.FindPass("FluidDepth".ToUpper());
            int depthBlurPass = m_prepareFluidMaterial.FindPass("FluidDepthBlur".ToUpper());

            if (depthPass != -1 && depthBlurPass != -1 && m_indexBuffer != null)
            {
                RenderTexture active = RenderTexture.active;

                // Depth texture
                RenderTextureDescriptor depthDesc = new RenderTextureDescriptor(cam.pixelWidth, cam.pixelHeight);
                depthDesc.colorFormat     = RenderTextureFormat.RGFloat;
                depthDesc.depthBufferBits = 24;
                RenderTexture depth = RenderTexture.GetTemporary(depthDesc);
                Graphics.SetRenderTarget(depth);
                GL.Clear(true, true, new Color(cam.farClipPlane, cam.farClipPlane, 0, 0), 1.0f);
                m_prepareFluidMaterial.SetBuffer("_Indices", m_indexBuffer);
                m_prepareFluidMaterial.SetBuffer("_Positions", m_positionBuffer);
                m_prepareFluidMaterial.SetBuffer("_Anisotropy1", m_anisotropy1Buffer);
                m_prepareFluidMaterial.SetBuffer("_Anisotropy2", m_anisotropy2Buffer);
                m_prepareFluidMaterial.SetBuffer("_Anisotropy3", m_anisotropy3Buffer);
                if (cam.stereoActiveEye != Camera.MonoOrStereoscopicEye.Mono)
                {
                    m_prepareFluidMaterial.SetMatrixArray("_ViewMatrix", new[] { cam.GetStereoViewMatrix(Camera.StereoscopicEye.Left), cam.GetStereoViewMatrix(Camera.StereoscopicEye.Right) });
                    m_prepareFluidMaterial.SetMatrixArray("_ProjMatrix", new[] { GL.GetGPUProjectionMatrix(cam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left), active != null), GL.GetGPUProjectionMatrix(cam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right), active != null) });
                    m_prepareFluidMaterial.SetInt("_EyeCount", 2);
                    m_prepareFluidMaterial.SetPass(depthPass);
                    Graphics.DrawProceduralNow(MeshTopology.Points, m_indexBuffer.count);
                }
                else
                {
                    m_prepareFluidMaterial.SetMatrixArray("_ViewMatrix", new[] { cam.worldToCameraMatrix, Matrix4x4.identity });
                    m_prepareFluidMaterial.SetMatrixArray("_ProjMatrix", new[] { GL.GetGPUProjectionMatrix(cam.projectionMatrix, active != null), Matrix4x4.identity });
                    m_prepareFluidMaterial.SetInt("_EyeCount", 1);
                    m_prepareFluidMaterial.SetPass(depthPass);
                    Graphics.DrawProceduralNow(MeshTopology.Points, m_indexBuffer.count);
                }
                Graphics.SetRenderTarget(active);

                // Blur texture
                RenderTextureDescriptor depthBlurDesc = new RenderTextureDescriptor(cam.pixelWidth, cam.pixelHeight);
                depthBlurDesc.colorFormat     = RenderTextureFormat.RGFloat;
                depthBlurDesc.depthBufferBits = 0;
                RenderTexture depthBlur = RenderTexture.GetTemporary(depthBlurDesc);
                Graphics.SetRenderTarget(depthBlur);
                GL.Clear(false, true, new Color(cam.farClipPlane, cam.farClipPlane, 0, 0));
                m_prepareFluidMaterial.SetFloat("_FarPlane", cam.farClipPlane);
                m_prepareFluidMaterial.SetVector("_InvScreen", new Vector2(1.0f / cam.pixelWidth, 1.0f / cam.pixelHeight));
                m_prepareFluidMaterial.SetTexture("_DepthTex", depth);
                Graphics.Blit(null, m_prepareFluidMaterial, depthBlurPass);

                RenderTexture.ReleaseTemporary(depth);
                sm_cameraCommands[cam].fluidDepths.Add(depthBlur);

                m_fluidMaterial.SetTexture("_DepthTex", depthBlur);
                m_fluidMaterial.SetFloat("FLEX_FLIP_Y", active ? 1.0f : 0.0f);
            }
        }