Exemplo n.º 1
0
        // Combines specular lighting and diffuse lighting with subsurface scattering.
        void CombineSubsurfaceScattering(HDCamera hdCamera, ScriptableRenderContext context, SubsurfaceScatteringParameters sssParameters)
        {
            // Currently, forward-rendered objects do not output split lighting required for the SSS pass.
            if (m_Owner.renderingSettings.ShouldUseForwardRenderingOnly())
            {
                return;
            }

            var cmd = new CommandBuffer()
            {
                name = "Subsurface Scattering Pass"
            };

            // Perform the vertical SSS filtering pass.
            m_FilterSubsurfaceScattering.SetMatrix("_InvProjMatrix", hdCamera.invProjectionMatrix);
            m_FilterSubsurfaceScattering.SetVectorArray("_FilterKernels", sssParameters.filterKernels);
            m_FilterSubsurfaceScattering.SetVectorArray("_HalfRcpWeightedVariances", sssParameters.halfRcpWeightedVariances);
            cmd.SetGlobalTexture("_IrradianceSource", m_CameraSubsurfaceBufferRT);
            Utilities.DrawFullScreen(cmd, m_FilterSubsurfaceScattering, hdCamera,
                                     m_CameraFilteringBufferRT, m_CameraStencilBufferRT);

            // Perform the horizontal SSS filtering pass, and combine diffuse and specular lighting.
            m_FilterAndCombineSubsurfaceScattering.SetMatrix("_InvProjMatrix", hdCamera.invProjectionMatrix);
            m_FilterAndCombineSubsurfaceScattering.SetVectorArray("_FilterKernels", sssParameters.filterKernels);
            m_FilterAndCombineSubsurfaceScattering.SetVectorArray("_HalfRcpWeightedVariances", sssParameters.halfRcpWeightedVariances);
            cmd.SetGlobalTexture("_IrradianceSource", m_CameraFilteringBufferRT);
            Utilities.DrawFullScreen(cmd, m_FilterAndCombineSubsurfaceScattering, hdCamera,
                                     m_CameraColorBufferRT, m_CameraStencilBufferRT);

            context.ExecuteCommandBuffer(cmd);
            cmd.Dispose();
        }
        void FilterCubemapCommon(CommandBuffer cmd,
                                 Texture source, RenderTexture target, int mipCount,
                                 Matrix4x4[] worldToViewMatrices)
        {
            // Solid angle associated with a texel of the cubemap.
            float invOmegaP = (6.0f * source.width * source.width) / (4.0f * Mathf.PI);

            m_GgxConvolveMaterial.SetTexture("_MainTex", source);
            m_GgxConvolveMaterial.SetTexture("_GgxIblSamples", m_GgxIblSampleData);
            m_GgxConvolveMaterial.SetFloat("_LastLevel", mipCount - 1);
            m_GgxConvolveMaterial.SetFloat("_InvOmegaP", invOmegaP);

            for (int mip = 1; mip < ((int)EnvConstants.SpecCubeLodStep + 1); ++mip)
            {
                string sampleName = String.Format("Filter Cubemap Mip {0}", mip);
                cmd.BeginSample(sampleName);

                for (int face = 0; face < 6; ++face)
                {
                    Vector4   faceSize  = new Vector4(source.width >> mip, source.height >> mip, 1.0f / (source.width >> mip), 1.0f / (source.height >> mip));
                    Matrix4x4 transform = SkyManager.ComputePixelCoordToWorldSpaceViewDirectionMatrix(0.5f * Mathf.PI, faceSize, worldToViewMatrices[face], true);

                    MaterialPropertyBlock props = new MaterialPropertyBlock();
                    props.SetFloat("_Level", mip);
                    props.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, transform);

                    Utilities.SetRenderTarget(cmd, target, ClearFlag.ClearNone, mip, (CubemapFace)face);
                    Utilities.DrawFullScreen(cmd, m_GgxConvolveMaterial, props);
                }
                cmd.EndSample(sampleName);
            }
        }
        public void Render(ScreenSpaceAmbientOcclusionSettings.Settings settings, HDRenderPipeline hdRP, HDCamera hdCamera, ScriptableRenderContext renderContext, CommandBuffer cmd, bool isForward)
        {
            const RenderTextureFormat    kTempFormat = RenderTextureFormat.ARGB32;
            const RenderTextureReadWrite kRWMode     = RenderTextureReadWrite.Linear;
            const FilterMode             kFilter     = FilterMode.Bilinear;

            // Note: Currently there is no SSAO in forward as we don't have normal buffer
            // If SSAO is disable, simply put a white 1x1 texture
            if (settings.enable == false || isForward)
            {
                cmd.SetGlobalTexture(HDShaderIDs._AmbientOcclusionTexture, UnityEngine.Rendering.PostProcessing.RuntimeUtilities.blackTexture); // Neutral is black, see the comment in the shaders
                cmd.SetGlobalFloat(HDShaderIDs._AmbientOcclusionDirectLightStrenght, 0.0f);
                return;
            }

            var width    = hdCamera.camera.pixelWidth;
            var height   = hdCamera.camera.pixelHeight;
            var downsize = settings.downsampling ? 2 : 1;

            // Provide the settings via uniforms.
            m_Material.SetFloat(Uniforms._Intensity, settings.intensity);
            m_Material.SetFloat(Uniforms._Radius, settings.radius);
            m_Material.SetFloat(Uniforms._Downsample, 1.0f / downsize);
            m_Material.SetFloat(Uniforms._SampleCount, settings.sampleCount);

            using (new Utilities.ProfilingSample("Screenspace ambient occlusion", cmd))
            {
                // AO estimation.
                cmd.GetTemporaryRT(Uniforms._TempTex1, width / downsize, height / downsize, 0, kFilter, kTempFormat, kRWMode);
                Utilities.DrawFullScreen(cmd, m_Material, Uniforms._TempTex1, null, 0);
                hdRP.PushFullScreenDebugTexture(cmd, Uniforms._TempTex1, hdCamera.camera, renderContext, FullScreenDebugMode.SSAOBeforeFiltering);

                // Denoising (horizontal pass).
                cmd.GetTemporaryRT(Uniforms._TempTex2, width, height, 0, kFilter, kTempFormat, kRWMode);
                cmd.SetGlobalTexture(Uniforms._MainTex, Uniforms._TempTex1);
                Utilities.DrawFullScreen(cmd, m_Material, Uniforms._TempTex2, null, 1);
                cmd.ReleaseTemporaryRT(Uniforms._TempTex1);

                // Denoising (vertical pass).
                cmd.GetTemporaryRT(Uniforms._TempTex1, width, height, 0, kFilter, kTempFormat, kRWMode);
                cmd.SetGlobalTexture(Uniforms._MainTex, Uniforms._TempTex2);
                Utilities.DrawFullScreen(cmd, m_Material, Uniforms._TempTex1, null, 2);
                cmd.ReleaseTemporaryRT(Uniforms._TempTex2);

                // Final filtering
                cmd.GetTemporaryRT(Uniforms._AOBuffer, width, height, 0, kFilter, GetAOBufferFormat(), kRWMode);
                cmd.SetGlobalTexture(Uniforms._MainTex, Uniforms._TempTex1);
                Utilities.DrawFullScreen(cmd, m_Material, Uniforms._AOBuffer, null, 3);
                cmd.ReleaseTemporaryRT(Uniforms._TempTex1);

                // Setup texture for lighting pass (automatic of unity)
                cmd.SetGlobalTexture(HDShaderIDs._AmbientOcclusionTexture, Uniforms._AOBuffer);
                cmd.SetGlobalFloat(HDShaderIDs._AmbientOcclusionDirectLightStrenght, settings.affectDirectLigthingStrenght);
                hdRP.PushFullScreenDebugTexture(cmd, Uniforms._AOBuffer, hdCamera.camera, renderContext, FullScreenDebugMode.SSAO);
            }
        }
        public override void RenderSky(BuiltinSkyParameters builtinParams, SkySettings skyParameters, bool renderForCubemap)
        {
            m_SkyHDRIMaterial.SetTexture(HDShaderIDs._Cubemap, m_HdriSkyParams.skyHDRI);
            m_SkyHDRIMaterial.SetVector(HDShaderIDs._SkyParam, new Vector4(m_HdriSkyParams.exposure, m_HdriSkyParams.multiplier, m_HdriSkyParams.rotation, 0.0f));

            // This matrix needs to be updated at the draw call frequency.
            MaterialPropertyBlock properties = new MaterialPropertyBlock();

            properties.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, builtinParams.pixelCoordToViewDirMatrix);

            Utilities.DrawFullScreen(builtinParams.commandBuffer, m_SkyHDRIMaterial, properties, renderForCubemap ? 0 : 1);
        }
        override public void RenderSky(BuiltinSkyParameters builtinParams, SkySettings skyParameters, bool renderForCubemap)
        {
            MaterialPropertyBlock properties = new MaterialPropertyBlock();

            // Define select preprocessor symbols.
            SetKeywords(builtinParams, m_ProceduralSkySettings, renderForCubemap);

            // Set shader constants.
            SetUniforms(builtinParams, m_ProceduralSkySettings, renderForCubemap, ref properties);

            Utilities.DrawFullScreen(builtinParams.commandBuffer, m_ProceduralSkyMaterial, properties);
        }
Exemplo n.º 6
0
        public override void RenderInit(CommandBuffer cmd)
        {
            if (m_isInit)
            {
                return;
            }

            using (new Utilities.ProfilingSample("Init PreFGD", cmd))
            {
                Utilities.DrawFullScreen(cmd, m_InitPreFGD, new RenderTargetIdentifier(m_PreIntegratedFGD));
            }
            m_isInit = true;
        }