SubsurfaceScatteringParameters PrepareSubsurfaceScatteringParameters(HDCamera hdCamera)
        {
            var parameters = new SubsurfaceScatteringParameters();

            parameters.subsurfaceScatteringCS       = m_SubsurfaceScatteringCS;
            parameters.subsurfaceScatteringCSKernel = hdCamera.frameSettings.IsEnabled(FrameSettingsField.MSAA) ? m_SubsurfaceScatteringKernelMSAA : m_SubsurfaceScatteringKernel;
            parameters.needTemporaryBuffer          = NeedTemporarySubsurfaceBuffer() || hdCamera.frameSettings.IsEnabled(FrameSettingsField.MSAA);
            parameters.copyStencilForSplitLighting  = m_SSSCopyStencilForSplitLighting;
            parameters.combineLighting    = m_CombineLightingPass;
            parameters.texturingModeFlags = m_SSSTexturingModeFlags;
            parameters.numTilesX          = ((int)hdCamera.screenSize.x + 15) / 16;
            parameters.numTilesY          = ((int)hdCamera.screenSize.y + 15) / 16;
            parameters.numTilesZ          = hdCamera.viewCount;

            parameters.worldScales            = m_SSSWorldScales;
            parameters.filterKernels          = m_SSSFilterKernels;
            parameters.shapeParams            = m_SSSShapeParams;
            parameters.diffusionProfileHashes = m_SSSDiffusionProfileHashes;

            return(parameters);
        }
예제 #2
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();
        }
예제 #3
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();
        }
예제 #4
0
        public void PushGlobalParams(HDCamera hdCamera, ScriptableRenderContext renderContext, SubsurfaceScatteringParameters sssParameters)
        {
            if (m_SkyManager.IsSkyValid())
            {
                m_SkyManager.SetGlobalSkyTexture();
                Shader.SetGlobalInt("_EnvLightSkyEnabled", 1);
            }
            else
            {
                Shader.SetGlobalInt("_EnvLightSkyEnabled", 0);
            }

            // Broadcast SSS parameters to all shaders.
            Shader.SetGlobalInt("_TransmittanceFlags", sssParameters.transmittanceFlags);
            Shader.SetGlobalFloatArray("_ThicknessScales", sssParameters.thicknessScales);
            Shader.SetGlobalVectorArray("_HalfRcpVariancesAndLerpWeights", sssParameters.halfRcpVariancesAndLerpWeights);

            var cmd = new CommandBuffer {
                name = "Push Global Parameters"
            };

            cmd.SetGlobalVector("_ScreenSize", hdCamera.screenSize);
            cmd.SetGlobalMatrix("_ViewProjMatrix", hdCamera.viewProjectionMatrix);
            cmd.SetGlobalMatrix("_InvViewProjMatrix", hdCamera.invViewProjectionMatrix);

            renderContext.ExecuteCommandBuffer(cmd);
            cmd.Dispose();

            if (m_LightLoop != null)
            {
                m_LightLoop.PushGlobalParams(hdCamera.camera, renderContext);
            }
        }