|
|
|
|
|
|
public Matrix4x4 viewProjectionMatrix; |
|
|
|
public Matrix4x4 invViewProjectionMatrix; |
|
|
|
public Matrix4x4 invProjectionMatrix; |
|
|
|
public Vector4 invProjectionParam; |
|
|
|
} |
|
|
|
|
|
|
|
public class GBufferManager |
|
|
|
|
|
|
|
|
|
|
public void PushGlobalParams(HDCamera hdCamera, ScriptableRenderContext renderContext, SubsurfaceScatteringParameters sssParameters) |
|
|
|
{ |
|
|
|
var cmd = new CommandBuffer {name = "Push Global Parameters"}; |
|
|
|
|
|
|
|
cmd.SetGlobalVector("_ScreenSize", hdCamera.screenSize); |
|
|
|
cmd.SetGlobalMatrix("_ViewProjMatrix", hdCamera.viewProjectionMatrix); |
|
|
|
cmd.SetGlobalMatrix("_InvViewProjMatrix", hdCamera.invViewProjectionMatrix); |
|
|
|
cmd.SetGlobalMatrix("_InvProjMatrix", hdCamera.invProjectionMatrix); |
|
|
|
cmd.SetGlobalVector("_InvProjParam", hdCamera.invProjectionParam); |
|
|
|
|
|
|
|
// TODO: cmd.SetGlobalInt() does not exist, so we are forced to use Shader.SetGlobalInt() instead.
|
|
|
|
|
|
|
|
if (m_SkyManager.IsSkyValid()) |
|
|
|
{ |
|
|
|
m_SkyManager.SetGlobalSkyTexture(); |
|
|
|
|
|
|
|
|
|
|
// Broadcast SSS parameters to all shaders.
|
|
|
|
Shader.SetGlobalInt("_TransmissionFlags", sssParameters.transmissionFlags); |
|
|
|
Shader.SetGlobalFloatArray("_ThicknessRemaps", sssParameters.thicknessRemaps); |
|
|
|
Shader.SetGlobalVectorArray("_HalfRcpVariancesAndLerpWeights", sssParameters.halfRcpVariancesAndLerpWeights); |
|
|
|
cmd.SetGlobalFloatArray("_ThicknessRemaps", sssParameters.thicknessRemaps); |
|
|
|
cmd.SetGlobalVectorArray("_HalfRcpVariancesAndLerpWeights", sssParameters.halfRcpVariancesAndLerpWeights); |
|
|
|
Shader.EnableKeyword("_SUBSURFACE_SCATTERING"); |
|
|
|
cmd.EnableShaderKeyword("_SUBSURFACE_SCATTERING"); |
|
|
|
Shader.DisableKeyword("_SUBSURFACE_SCATTERING"); |
|
|
|
cmd.DisableShaderKeyword("_SUBSURFACE_SCATTERING"); |
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
// 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); |
|
|
|