示例#1
0
        void OnRenderImage(RenderTexture src, RenderTexture dst)
        {
            if (m_material == null)
            {
                m_material           = new Material(m_shader);
                m_material.hideFlags = HideFlags.DontSave;

                m_quad = MeshUtils.GenerateQuad();
            }
            UpdateRenderTargets();

            switch (m_quality)
            {
            case Quality.Fast: m_material.EnableKeyword("QUALITY_FAST"); break;

            case Quality.Medium: m_material.EnableKeyword("QUALITY_MEDIUM"); break;

            case Quality.High: m_material.EnableKeyword("QUALITY_HIGH"); break;

            case Quality.VeryHigh: m_material.EnableKeyword("QUALITY_ULTRA"); break;
            }

            m_reflection_buffers[1].filterMode = FilterMode.Point;
            m_material.SetVector("_Params0", new Vector4(m_intensity, m_raymarch_distance, m_ray_diffusion, m_falloff_distance));
            m_material.SetVector("_Params1", new Vector4(m_max_accumulation, m_ray_hit_radius, 0.0f, 0.0f));
            m_material.SetTexture("_ReflectionBuffer", m_reflection_buffers[1]);
            m_material.SetTexture("_AccumulationBuffer", m_accumulation_buffers[1]);
            m_material.SetTexture("_MainTex", src);

            m_rb[0] = m_reflection_buffers[0].colorBuffer;
            m_rb[1] = m_accumulation_buffers[0].colorBuffer;
            Graphics.SetRenderTarget(m_rb, m_reflection_buffers[0].depthBuffer);
            m_material.SetPass(0);
            Graphics.DrawMeshNow(m_quad, Matrix4x4.identity);

            m_reflection_buffers[0].filterMode = FilterMode.Bilinear;
            Graphics.SetRenderTarget(dst);
            m_material.SetTexture("_ReflectionBuffer", m_reflection_buffers[0]);
            m_material.SetTexture("_AccumulationBuffer", m_accumulation_buffers[0]);
            m_material.SetPass(1);
            Graphics.Blit(src, dst, m_material, 1);

            Swap(ref m_reflection_buffers[0], ref m_reflection_buffers[1]);
            Swap(ref m_accumulation_buffers[0], ref m_accumulation_buffers[1]);
        }
示例#2
0
 void Reset()
 {
     m_sh_gbuffer_copy      = AssetDatabase.LoadAssetAtPath <Shader>("Assets/Ist/GBufferUtils/Shaders/GBufferCopy.shader");
     m_sh_depth_to_velocity = AssetDatabase.LoadAssetAtPath <Shader>("Assets/Ist/GBufferUtils/Shaders/DepthToVelocity.shader");
     m_quad = MeshUtils.GenerateQuad();
 }
示例#3
0
        void OnRenderImage(RenderTexture src, RenderTexture dst)
        {
            GetComponent <GBufferUtils>().UpdateVelocityBuffer();

            if (m_material == null)
            {
                m_material           = new Material(m_shader);
                m_material.hideFlags = HideFlags.DontSave;

                m_quad = MeshUtils.GenerateQuad();
            }
            UpdateRenderTargets();

            switch (m_sample_count)
            {
            case SampleCount.Low:
                m_material.EnableKeyword("SAMPLES_LOW");
                m_material.DisableKeyword("SAMPLES_MEDIUM");
                m_material.DisableKeyword("SAMPLES_HIGH");
                break;

            case SampleCount.Medium:
                m_material.DisableKeyword("SAMPLES_LOW");
                m_material.EnableKeyword("SAMPLES_MEDIUM");
                m_material.DisableKeyword("SAMPLES_HIGH");
                break;

            case SampleCount.High:
                m_material.DisableKeyword("SAMPLES_LOW");
                m_material.DisableKeyword("SAMPLES_MEDIUM");
                m_material.EnableKeyword("SAMPLES_HIGH");
                break;
            }

            if (m_dangerous_samples)
            {
                m_material.EnableKeyword("ENABLE_DANGEROUS_SAMPLES");
            }
            else
            {
                m_material.DisableKeyword("ENABLE_DANGEROUS_SAMPLES");
            }

#if UNITY_EDITOR
            switch (m_debug_option)
            {
            case DebugOption.Off:
                m_material.EnableKeyword("DEBUG_OFF");
                m_material.DisableKeyword("DEBUG_SHOW_AO");
                m_material.DisableKeyword("DEBUG_SHOW_VELOCITY");
                m_material.DisableKeyword("DEBUG_SHOW_VIEW_NORMAL");
                break;

            case DebugOption.ShowAO:
                m_material.DisableKeyword("DEBUG_OFF");
                m_material.EnableKeyword("DEBUG_SHOW_AO");
                m_material.DisableKeyword("DEBUG_SHOW_VELOCITY");
                m_material.DisableKeyword("DEBUG_SHOW_VIEW_NORMAL");
                break;

            case DebugOption.ShowVelocity:
                m_material.DisableKeyword("DEBUG_OFF");
                m_material.DisableKeyword("DEBUG_SHOW_AO");
                m_material.EnableKeyword("DEBUG_SHOW_VELOCITY");
                m_material.DisableKeyword("DEBUG_SHOW_VIEW_NORMAL");
                break;

            case DebugOption.ShowViewNormal:
                m_material.DisableKeyword("DEBUG_OFF");
                m_material.DisableKeyword("DEBUG_SHOW_AO");
                m_material.DisableKeyword("DEBUG_SHOW_VELOCITY");
                m_material.EnableKeyword("DEBUG_SHOW_VIEW_NORMAL");
                break;
            }
#endif

            m_material.SetVector("_Params0", new Vector4(m_radius, m_intensity, m_max_accumulation, 0.0f));
            m_material.SetTexture("_AOBuffer", m_ao_buffer[1]);
            m_material.SetTexture("_MainTex", src);

            // accumulate ao
            Graphics.SetRenderTarget(m_ao_buffer[0]);
            m_material.SetPass(0);
            Graphics.DrawMeshNow(m_quad, Matrix4x4.identity);

            if (m_blur_size > 0.0f)
            {
                int w    = (int)(m_ao_buffer[0].width * 1.0f);
                int h    = (int)(m_ao_buffer[0].height * 1.0f);
                var tmp1 = RenderTexture.GetTemporary(w, h, 0, RenderTextureFormat.RGHalf);
                var tmp2 = RenderTexture.GetTemporary(w, h, 0, RenderTextureFormat.RGHalf);
                tmp1.filterMode = FilterMode.Trilinear;
                tmp2.filterMode = FilterMode.Trilinear;

                // horizontal blur
                Graphics.SetRenderTarget(tmp1);
                m_material.SetTexture("_AOBuffer", m_ao_buffer[0]);
                m_material.SetVector("_BlurOffset", new Vector4(m_blur_size / src.width, 0.0f, 0.0f, 0.0f));
                m_material.EnableKeyword("BLUR_HORIZONTAL");
                m_material.SetPass(1);
                Graphics.DrawMeshNow(m_quad, Matrix4x4.identity);
                m_material.DisableKeyword("BLUR_HORIZONTAL");

                // vertical blur
                Graphics.SetRenderTarget(tmp2);
                m_material.SetTexture("_AOBuffer", tmp1);
                m_material.SetVector("_BlurOffset", new Vector4(0.0f, m_blur_size / src.height, 0.0f, 0.0f));
                m_material.EnableKeyword("BLUR_VERTICAL");
                m_material.SetPass(1);
                Graphics.DrawMeshNow(m_quad, Matrix4x4.identity);
                m_material.DisableKeyword("BLUR_VERTICAL");

                // combine
                Graphics.SetRenderTarget(dst);
                m_material.SetTexture("_AOBuffer", tmp2);
                Graphics.Blit(src, dst, m_material, 2);

                RenderTexture.ReleaseTemporary(tmp2);
                RenderTexture.ReleaseTemporary(tmp1);
            }
            else
            {
                // combine
                Graphics.SetRenderTarget(dst);
                m_material.SetTexture("_AOBuffer", m_ao_buffer[0]);
                Graphics.Blit(src, dst, m_material, 2);
            }

            Swap(ref m_ao_buffer[0], ref m_ao_buffer[1]);
        }
示例#4
0
 void Reset()
 {
     m_quad             = MeshUtils.GenerateQuad();
     m_shader_composite = AssetDatabase.LoadAssetAtPath <Shader>("Assets/Ist/ScreenSpaceBoolean/Shaders/CompositeSub.shader");
 }
示例#5
0
 void Reset()
 {
     m_sh_gbuffer_copy = AssetDatabase.LoadAssetAtPath("Assets/Ist/GBufferUtils/Shaders/GBufferCopy.shader", typeof(Shader)) as Shader;
     m_quad            = MeshUtils.GenerateQuad();
 }
        void OnRenderImage(RenderTexture src, RenderTexture dst)
        {
            GetComponent <GBufferUtils>().UpdateVelocityBuffer();

            if (m_material == null)
            {
                m_material = new Material(m_shader);
                m_quad     = MeshUtils.GenerateQuad();
            }
            UpdateRenderTargets();

            switch (m_sample_count)
            {
            case SampleCount.Low:
                m_material.EnableKeyword("SAMPLES_LOW");
                m_material.DisableKeyword("SAMPLES_MEDIUM");
                m_material.DisableKeyword("SAMPLES_HIGH");
                break;

            case SampleCount.Medium:
                m_material.DisableKeyword("SAMPLES_LOW");
                m_material.EnableKeyword("SAMPLES_MEDIUM");
                m_material.DisableKeyword("SAMPLES_HIGH");
                break;

            case SampleCount.High:
                m_material.DisableKeyword("SAMPLES_LOW");
                m_material.DisableKeyword("SAMPLES_MEDIUM");
                m_material.EnableKeyword("SAMPLES_HIGH");
                break;
            }
            if (m_pre_raymarch_pass)
            {
                m_material.EnableKeyword("ENABLE_PREPASS");
            }
            else
            {
                m_material.DisableKeyword("ENABLE_PREPASS");
            }

            if (m_dangerous_samples)
            {
                m_material.EnableKeyword("ENABLE_DANGEROUS_SAMPLES");
            }
            else
            {
                m_material.DisableKeyword("ENABLE_DANGEROUS_SAMPLES");
            }

            m_material.SetVector("_Params0", new Vector4(m_intensity, m_raymarch_distance, m_ray_diffusion, m_falloff_distance));
            m_material.SetVector("_Params1", new Vector4(m_max_accumulation, m_ray_hit_radius, m_step_boost, 0.0f));
            m_material.SetTexture("_ReflectionBuffer", m_reflection_buffers[1]);
            m_material.SetTexture("_AccumulationBuffer", m_accumulation_buffers[1]);
            m_material.SetTexture("_MainTex", src);



            // accumulate reflection
            m_rb[0] = m_reflection_buffers[0].colorBuffer;
            m_rb[1] = m_accumulation_buffers[0].colorBuffer;
            if (m_pre_raymarch_pass)
            {
                var prepass_buffer = RenderTexture.GetTemporary(
                    m_reflection_buffers[0].width / 4,
                    m_reflection_buffers[0].height / 4, 0, RenderTextureFormat.RHalf);
                prepass_buffer.filterMode = FilterMode.Bilinear;

                // raymarch in low-resolution buffer
                Graphics.SetRenderTarget(prepass_buffer);
                m_material.SetPass(3);
                Graphics.DrawMeshNow(m_quad, Matrix4x4.identity);

                // continue raymarch from pre-march result
                Graphics.SetRenderTarget(m_rb, m_reflection_buffers[0].depthBuffer);
                m_material.SetTexture("_PrePassBuffer", prepass_buffer);
                m_material.SetPass(0);
                Graphics.DrawMeshNow(m_quad, Matrix4x4.identity);

                RenderTexture.ReleaseTemporary(prepass_buffer);
            }
            else
            {
                Graphics.SetRenderTarget(m_rb, m_reflection_buffers[0].depthBuffer);
                m_material.SetPass(0);
                Graphics.DrawMeshNow(m_quad, Matrix4x4.identity);
            }


            var tmp1 = RenderTexture.GetTemporary(m_reflection_buffers[0].width, m_reflection_buffers[0].height, 0, RenderTextureFormat.ARGB32);
            var tmp2 = RenderTexture.GetTemporary(m_reflection_buffers[0].width, m_reflection_buffers[0].height, 0, RenderTextureFormat.ARGB32);

            tmp1.filterMode = FilterMode.Bilinear;
            tmp2.filterMode = FilterMode.Bilinear;

            if (m_blur_size > 0.0f)
            {
                // horizontal blur
                Graphics.SetRenderTarget(tmp1);
                m_material.SetTexture("_ReflectionBuffer", m_reflection_buffers[0]);
                m_material.SetVector("_BlurOffset", new Vector4(m_blur_size / src.width, 0.0f, 0.0f, 0.0f));
                m_material.SetPass(1);
                Graphics.DrawMeshNow(m_quad, Matrix4x4.identity);

                // vertical blur
                Graphics.SetRenderTarget(tmp2);
                m_material.SetTexture("_ReflectionBuffer", tmp1);
                m_material.SetVector("_BlurOffset", new Vector4(0.0f, m_blur_size / src.height, 0.0f, 0.0f));
                m_material.SetPass(1);
                Graphics.DrawMeshNow(m_quad, Matrix4x4.identity);
            }

            // combine
            Graphics.SetRenderTarget(dst);
            m_material.SetTexture("_ReflectionBuffer", m_blur_size > 0.0f ? tmp2 : m_reflection_buffers[0]);
            m_material.SetTexture("_AccumulationBuffer", m_accumulation_buffers[0]);
            Graphics.Blit(src, dst, m_material, 2);

            RenderTexture.ReleaseTemporary(tmp2);
            RenderTexture.ReleaseTemporary(tmp1);


            Swap(ref m_reflection_buffers[0], ref m_reflection_buffers[1]);
            Swap(ref m_accumulation_buffers[0], ref m_accumulation_buffers[1]);
        }