readonly GBufferManager m_gbufferManager = new GBufferManager ( ) ;
// Various set of material use in render loop
readonly Material m_FilterAndCombineSubsurfaceScattering ;
Material m_FilterAndCombineSubsurfaceScattering ;
readonly Material m_FilterSubsurfaceScattering ;
Material m_FilterSubsurfaceScattering ;
// <<< Old SSS Model
Material m_DebugViewMaterialGBuffer ;
// Various buffer
readonly int m_CameraColorBuffer ;
readonly int m_CameraSubsurfaceBuffer ;
// Old SSS Model >>>
// <<< Old SSS Model
readonly int m_VelocityBuffer ;
readonly int m_DistortionBuffer ;
m_CameraColorBuffer = Shader . PropertyToID ( "_CameraColorTexture" ) ;
m_CameraSubsurfaceBuffer = Shader . PropertyToID ( "_CameraSubsurfaceTexture" ) ;
m_CameraFilteringBuffer = Shader . PropertyToID ( "_CameraFilteringBuffer" ) ;
m_FilterAndCombineSubsurfaceScattering = Utilities . CreateEngineMaterial ( "Hidden/HDRenderPipeline/CombineSubsurfaceScattering" ) ;
m_CameraFilteringBuffer = Shader . PropertyToID ( "_CameraFilteringBuffer" ) ;
m_FilterSubsurfaceScattering = Utilities . CreateEngineMaterial ( "Hidden/HDRenderPipeline/CombineSubsurfaceScattering" ) ;
m_FilterSubsurfaceScattering . DisableKeyword ( "SSS_FILTER_HORIZONTAL_AND_COMBINE" ) ;
m_FilterSubsurfaceScattering . SetFloat ( "_DstBlend" , ( float ) BlendMode . Zero ) ;
m_FilterAndCombineSubsurfaceScattering . EnableKeyword ( "SSS_FILTER_HORIZONTAL_AND_COMBINE" ) ;
m_FilterAndCombineSubsurfaceScattering . SetFloat ( "_DstBlend" , ( float ) BlendMode . One ) ;
CreateSssMaterials ( sssSettings . useDisneySSS ) ;
// <<< Old SSS Model
InitializeDebugMaterials ( ) ;
m_DebugFullScreen = Utilities . CreateEngineMaterial ( m_Asset . renderPipelineResources . debugFullScreenShader ) ;
}
// Old SSS Model >>>
public void CreateSssMaterials ( bool useDisneySSS )
{
Utilities . Destroy ( m_FilterSubsurfaceScattering ) ;
m_FilterSubsurfaceScattering = Utilities . CreateEngineMaterial ( "Hidden/HDRenderPipeline/CombineSubsurfaceScattering" ) ;
Utilities . SelectKeyword ( m_FilterSubsurfaceScattering , "SSS_MODEL_DISNEY" , "SSS_MODEL_BASIC" , useDisneySSS ) ;
m_FilterSubsurfaceScattering . DisableKeyword ( "SSS_FILTER_HORIZONTAL_AND_COMBINE" ) ;
m_FilterSubsurfaceScattering . SetFloat ( "_DstBlend" , ( float ) BlendMode . Zero ) ;
Utilities . Destroy ( m_FilterAndCombineSubsurfaceScattering ) ;
m_FilterAndCombineSubsurfaceScattering = Utilities . CreateEngineMaterial ( "Hidden/HDRenderPipeline/CombineSubsurfaceScattering" ) ;
Utilities . SelectKeyword ( m_FilterAndCombineSubsurfaceScattering , "SSS_MODEL_DISNEY" , "SSS_MODEL_BASIC" , useDisneySSS ) ;
m_FilterAndCombineSubsurfaceScattering . EnableKeyword ( "SSS_FILTER_HORIZONTAL_AND_COMBINE" ) ;
m_FilterAndCombineSubsurfaceScattering . SetFloat ( "_DstBlend" , ( float ) BlendMode . One ) ;
}
// <<< Old SSS Model
public void OnSceneLoad ( )
{
// Recreate the textures which went NULL
if ( sssSettings . useDisneySSS )
{
Utilities . SelectKeyword ( m_FilterAndCombineSubsurfaceScattering , "SSS_MODEL_DISNEY" , "SSS_MODEL_BASIC" , true ) ;
cmd . SetGlobalTexture ( "_IrradianceSource" , m_CameraSubsurfaceBufferRT ) ; // Cannot set a RT on a material
m_FilterAndCombineSubsurfaceScattering . SetFloatArray ( "_WorldScales" , sssParameters . worldScales ) ;
m_FilterAndCombineSubsurfaceScattering . SetFloatArray ( "_FilterKernelsNearField" , sssParameters . filterKernelsNearField ) ;
}
else
{
Utilities . SelectKeyword ( m_FilterSubsurfaceScattering , "SSS_MODEL_DISNEY" , "SSS_MODEL_BASIC" , false ) ;
Utilities . SelectKeyword ( m_FilterAndCombineSubsurfaceScattering , "SSS_MODEL_DISNEY" , "SSS_MODEL_BASIC" , false ) ;
cmd . SetGlobalTexture ( "_IrradianceSource" , m_CameraSubsurfaceBufferRT ) ; // Cannot set a RT on a material
cmd . SetGlobalTexture ( "_IrradianceSource" , m_CameraSubsurfaceBufferRT ) ;
context . ExecuteCommandBuffer ( cmd ) ; // Does not work if I don't execute the command buffer in between the draws.
cmd . SetGlobalTexture ( "_IrradianceSource" , m_CameraFilteringBufferRT ) ; // Cannot set a RT on a material
cmd . SetGlobalTexture ( "_IrradianceSource" , m_CameraFilteringBufferRT ) ;
Utilities . DrawFullScreen ( cmd , m_FilterAndCombineSubsurfaceScattering , hdCamera , m_CameraColorBufferRT , m_CameraDepthStencilBufferRT ) ;
}
cmd . GetTemporaryRT ( m_CameraColorBuffer , w , h , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear , 1 , true ) ; // Enable UAV
cmd . GetTemporaryRT ( m_CameraSubsurfaceBuffer , w , h , 0 , FilterMode . Point , RenderTextureFormat . RGB111110Float , RenderTextureReadWrite . Linear , 1 , true ) ; // Enable UAV
// Old SSS Model >>>
// <<< Old SSS Model
if ( ! m_Asset . renderingSettings . ShouldUseForwardRenderingOnly ( ) )
{
Utilities . SetRenderTarget ( renderContext , m_CameraSubsurfaceBufferRT , m_CameraDepthStencilBufferRT , ClearFlag . ClearColor , Color . black ) ;
}
// Old SSS Model >>>
// <<< Old SSS Model
// TEMP: As we are in development and have not all the setup pass we still clear the color in emissive buffer and gbuffer, but this will be removed later.