readonly SkyManager m_SkyManager = new SkyManager ( ) ;
readonly LightLoop m_LightLoop = new LightLoop ( ) ;
readonly ShadowSettings m_ShadowSettings = new ShadowSettings ( ) ;
// Debugging
public DebugDisplaySettings m_DebugDisplaySettings = new DebugDisplaySettings ( ) ;
public SubsurfaceScatteringSettings sssSettings
{
get { return m_Asset . sssSettings ; }
}
private CommonSettings . Settings m_CommonSettings = CommonSettings . Settings . s_Defaultsettings ;
private SkySettings m_SkySettings ;
private DebugDisplaySettings debugDisplaySettings
public CommonSettings . Settings commonSettingsToUse
get { return m_Asset . debugDisplaySettings ; }
get
{
if ( CommonSettingsSingleton . overrideSettings )
return CommonSettingsSingleton . overrideSettings . settings ;
return m_CommonSettings ;
}
public SubsurfaceScatteringSettings sssSettings
public SkySettings skySettingsToUse
get { return m_Asset . sssSettings ; }
get
{
if ( SkySettingsSingleton . overrideSettings )
return SkySettingsSingleton . overrideSettings ;
return m_SkySettings ;
}
public HDRenderPipeline ( HDRenderPipelineAsset asset )
{
m_Asset = asset ;
m_LitRenderLoop . Build ( asset . renderPipelineResources ) ;
m_LightLoop . Build ( asset . renderPipelineResources , asset . tileSettings , asset . textureSettings ) ;
m_LightLoop . Build ( asset . renderPipelineResources , asset . tileSettings , asset . textureSettings , asset . shadowInitParams , m_ShadowSettings ) ;
m_SkyManager . skySettings = asset . skySettingsToUse ;
m_SkyManager . skySettings = skySettingsToUse ;
m_DebugDisplaySettings . RegisterDebug ( ) ;
}
void InitializeDebugMaterials ( )
// TODO: This is the wrong way to handle resize/allocation. We can have several different camera here, mean that the loop on camera will allocate and deallocate
// the below buffer which is bad. Best is to have a set of buffer for each camera that is persistent and reallocate resource if need
// For now consider we have only one camera that go to this code, the main one.
m_SkyManager . skySettings = m_Asset . skySettingsToUse ;
m_SkyManager . skySettings = skySettingsToUse ;
m_SkyManager . Resize ( camera . nearClipPlane , camera . farClipPlane ) ; // TODO: Also a bad naming, here we just want to realloc texture if skyparameters change (useful for lookdev)
bool resolutionChanged = camera . pixelWidth ! = m_CurrentWidth | | camera . pixelHeight ! = m_CurrentHeight ;
}
// Broadcast SSS parameters to all shaders.
Shader . SetGlobalInt ( "_EnableSSS" , d ebugDisplaySettings. renderingDebugSettings . enableSSS ? 1 : 0 ) ;
Shader . SetGlobalInt ( "_EnableSSS" , m_D ebugDisplaySettings. renderingDebugSettings . enableSSS ? 1 : 0 ) ;
Shader . SetGlobalInt ( "_TexturingModeFlags" , ( int ) sssParameters . texturingModeFlags ) ;
Shader . SetGlobalInt ( "_TransmissionFlags" , ( int ) sssParameters . transmissionFlags ) ;
cmd . SetGlobalFloatArray ( "_ThicknessRemaps" , sssParameters . thicknessRemaps ) ;
cmd . Dispose ( ) ;
}
public void UpdateCommonSettings ( )
{
var commonSettings = commonSettingsToUse ;
m_ShadowSettings . maxShadowDistance = commonSettings . shadowMaxDistance ;
m_ShadowSettings . directionalLightNearPlaneOffset = commonSettings . shadowNearPlaneOffset ;
}
public override void Render ( ScriptableRenderContext renderContext , Camera [ ] cameras )
{
base . Render ( renderContext , cameras ) ;
// Do anything we need to do upon a new frame.
m_LightLoop . NewFrame ( ) ;
m_Asset . ApplyDebugDisplaySettings ( ) ;
m_Asset . UpdateCommonSettings ( ) ;
ApplyDebugDisplaySettings ( ) ;
UpdateCommonSettings ( ) ;
// Set Frame constant buffer
// TODO...
CopyDepthBufferIfNeeded ( renderContext ) ;
}
if ( d ebugDisplaySettings. IsDebugMaterialDisplayEnabled ( ) )
if ( m_D ebugDisplaySettings. IsDebugMaterialDisplayEnabled ( ) )
{
RenderDebugViewMaterial ( cullResults , hdCamera , renderContext ) ;
}
{
// TODO: Everything here (SSAO, Shadow, Build light list, material and light classification can be parallelize with Async compute)
m_SsaoEffect . Render ( m_Asset . ssaoSettingsToUse , hdCamera , renderContext , GetDepthTexture ( ) , m_Asset . renderingSettings . useForwardRenderingOnly ) ;
m_LightLoop . PrepareLightsForGPU ( m_Asset . s hadowSettings , cullResults , camera ) ;
m_LightLoop . PrepareLightsForGPU ( m_S hadowSettings , cullResults , camera ) ;
m_LightLoop . RenderShadows ( renderContext , cullResults ) ;
renderContext . SetupCameraProperties ( camera ) ; // Need to recall SetupCameraProperties after m_ShadowPass.Render
m_LightLoop . BuildGPULightLists ( camera , renderContext , m_CameraDepthStencilBufferRT ) ;
void RenderOpaqueRenderList ( CullResults cull , Camera camera , ScriptableRenderContext renderContext , string passName , RendererConfiguration rendererConfiguration = 0 )
{
if ( ! d ebugDisplaySettings. renderingDebugSettings . displayOpaqueObjects )
if ( ! m_D ebugDisplaySettings. renderingDebugSettings . displayOpaqueObjects )
return ;
var settings = new DrawRendererSettings ( cull , camera , new ShaderPassName ( passName ) )
void RenderTransparentRenderList ( CullResults cull , Camera camera , ScriptableRenderContext renderContext , string passName , RendererConfiguration rendererConfiguration = 0 )
{
if ( ! d ebugDisplaySettings. renderingDebugSettings . displayTransparentObjects )
if ( ! m_D ebugDisplaySettings. renderingDebugSettings . displayTransparentObjects )
return ;
var settings = new DrawRendererSettings ( cull , camera , new ShaderPassName ( passName ) )
return ;
}
string passName = d ebugDisplaySettings. IsDebugDisplayEnabled ( ) ? "GBufferDebugDisplay" : "GBuffer" ;
string passName = m_D ebugDisplaySettings. IsDebugDisplayEnabled ( ) ? "GBufferDebugDisplay" : "GBuffer" ;
using ( new Utilities . ProfilingSample ( passName , renderContext ) )
{
RenderTargetIdentifier [ ] colorRTs = { m_CameraColorBufferRT , m_CameraSubsurfaceBufferRT } ;
if ( d ebugDisplaySettings. renderingDebugSettings . enableSSS )
if ( m_D ebugDisplaySettings. renderingDebugSettings . enableSSS )
m_LightLoop . RenderDeferredLighting ( hdCamera , renderContext , d ebugDisplaySettings, colorRTs , m_CameraDepthStencilBufferRT , new RenderTargetIdentifier ( GetDepthTexture ( ) ) , true ) ;
m_LightLoop . RenderDeferredLighting ( hdCamera , renderContext , m_D ebugDisplaySettings, colorRTs , m_CameraDepthStencilBufferRT , new RenderTargetIdentifier ( GetDepthTexture ( ) ) , true ) ;
m_LightLoop . RenderDeferredLighting ( hdCamera , renderContext , d ebugDisplaySettings, colorRTs , m_CameraDepthStencilBufferRT , new RenderTargetIdentifier ( GetDepthTexture ( ) ) , false ) ;
m_LightLoop . RenderDeferredLighting ( hdCamera , renderContext , m_D ebugDisplaySettings, colorRTs , m_CameraDepthStencilBufferRT , new RenderTargetIdentifier ( GetDepthTexture ( ) ) , false ) ;
}
// Combines specular lighting and diffuse lighting with subsurface scattering.
if ( m_Asset . renderingSettings . ShouldUseForwardRenderingOnly ( ) ) return ;
if ( ! d ebugDisplaySettings. renderingDebugSettings . enableSSS ) return ;
if ( ! m_D ebugDisplaySettings. renderingDebugSettings . enableSSS ) return ;
var cmd = new CommandBuffer ( ) { name = "Subsurface Scattering" } ;
if ( ! m_Asset . renderingSettings . ShouldUseForwardRenderingOnly ( ) & & renderOpaque )
return ;
string passName = d ebugDisplaySettings. IsDebugDisplayEnabled ( ) ? "ForwardDisplayDebug" : "Forward" ;
string passName = m_D ebugDisplaySettings. IsDebugDisplayEnabled ( ) ? "ForwardDisplayDebug" : "Forward" ;
using ( new Utilities . ProfilingSample ( passName , renderContext ) )
{
// Render material that are forward opaque only (like eye), this include unlit material
void RenderForwardOnlyOpaque ( CullResults cullResults , Camera camera , ScriptableRenderContext renderContext )
{
string passName = d ebugDisplaySettings. IsDebugDisplayEnabled ( ) ? "ForwardOnlyOpaqueDisplayDebug" : "ForwardOnlyOpaque" ;
string passName = m_D ebugDisplaySettings. IsDebugDisplayEnabled ( ) ? "ForwardOnlyOpaqueDisplayDebug" : "ForwardOnlyOpaque" ;
using ( new Utilities . ProfilingSample ( passName , renderContext ) )
{
void RenderDistortion ( CullResults cullResults , Camera camera , ScriptableRenderContext renderContext )
{
if ( ! d ebugDisplaySettings. renderingDebugSettings . enableDistortion )
if ( ! m_D ebugDisplaySettings. renderingDebugSettings . enableDistortion )
return ;
using ( new Utilities . ProfilingSample ( "Distortion" , renderContext ) )
}
}
public void ApplyDebugDisplaySettings ( )
{
m_ShadowSettings . enabled = m_DebugDisplaySettings . lightingDebugSettings . enableShadows ;
LightingDebugSettings lightingDebugSettings = m_DebugDisplaySettings . lightingDebugSettings ;
Vector4 debugAlbedo = new Vector4 ( lightingDebugSettings . debugLightingAlbedo . r , lightingDebugSettings . debugLightingAlbedo . g , lightingDebugSettings . debugLightingAlbedo . b , 0.0f ) ;
Vector4 debugSmoothness = new Vector4 ( lightingDebugSettings . overrideSmoothness ? 1.0f : 0.0f , lightingDebugSettings . overrideSmoothnessValue , 0.0f , 0.0f ) ;
Shader . SetGlobalInt ( "_DebugViewMaterial" , ( int ) m_DebugDisplaySettings . GetDebugMaterialIndex ( ) ) ;
Shader . SetGlobalInt ( "_DebugLightingMode" , ( int ) m_DebugDisplaySettings . GetDebugLightingMode ( ) ) ;
Shader . SetGlobalVector ( "_DebugLightingAlbedo" , debugAlbedo ) ;
Shader . SetGlobalVector ( "_DebugLightingSmoothness" , debugSmoothness ) ;
}
void RenderDebugOverlay ( Camera camera , ScriptableRenderContext renderContext )
{
debugCB . name = "Debug Overlay" ;
float x = 0 ;
float overlayRatio = d ebugDisplaySettings. debugOverlayRatio ;
float overlayRatio = m_D ebugDisplaySettings. debugOverlayRatio ;
LightingDebugSettings lightingDebug = d ebugDisplaySettings. lightingDebugSettings ;
LightingDebugSettings lightingDebug = m_D ebugDisplaySettings. lightingDebugSettings ;
if ( lightingDebug . displaySkyReflection )
{
renderContext . ExecuteCommandBuffer ( debugCB ) ;
m_LightLoop . RenderDebugOverlay ( camera , renderContext , d ebugDisplaySettings, ref x , ref y , overlaySize , camera . pixelWidth ) ;
m_LightLoop . RenderDebugOverlay ( camera , renderContext , m_D ebugDisplaySettings, ref x , ref y , overlaySize , camera . pixelWidth ) ;
}
void InitAndClearBuffer ( Camera camera , ScriptableRenderContext renderContext )