Beispiel #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 (debugParameters.ShouldUseForwardRenderingOnly())
            {
                return;
            }

            // Assume that the height of the projection window is 2 meters.
            float distanceToProjectionWindow = 1.0f / Mathf.Tan(0.5f * Mathf.Deg2Rad * hdCamera.camera.fieldOfView);

            m_CombineSubsurfaceScattering.SetFloat("_DistToProjWindow", distanceToProjectionWindow);
            m_CombineSubsurfaceScattering.SetFloat("_BilateralScale", 0.05f * sssParameters.bilateralScale);
            // TODO: use user-defined values for '_ProfileID' and '_FilterRadius.'
            m_CombineSubsurfaceScattering.SetVectorArray("_FilterKernel", sssParameters.profiles[0].filterKernel);
            m_CombineSubsurfaceScattering.SetFloat("_FilterRadius", 3.0f);

            MaterialPropertyBlock properties = new MaterialPropertyBlock();

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

            // Perform the vertical SSS filtering pass.
            properties.SetFloat("_DstBlend", (float)BlendMode.Zero); // TODO: this doesn't work for some reason...
            properties.SetFloat("_FilterHorizontal", 0);
            cmd.SetGlobalTexture("_IrradianceSource", m_CameraSubsurfaceBufferRT);
            Utilities.DrawFullscreen(cmd, m_CombineSubsurfaceScattering, hdCamera,
                                     m_CameraFilteringBufferRT, m_CameraStencilBufferRT, properties);

            // Perform the horizontal SSS filtering pass, and combine diffuse and specular lighting.
            properties.SetFloat("_DstBlend", (float)BlendMode.One);  // TODO: this doesn't work for some reason...
            properties.SetFloat("_FilterHorizontal", 1);
            cmd.SetGlobalTexture("_IrradianceSource", m_CameraFilteringBufferRT);
            Utilities.DrawFullscreen(cmd, m_CombineSubsurfaceScattering, hdCamera,
                                     m_CameraColorBufferRT, m_CameraStencilBufferRT, properties);

            context.ExecuteCommandBuffer(cmd);
            cmd.Dispose();
        }