// NOTE:
// All those properties are public because of how HDRenderPipelineInspector retrieve those properties via serialization/reflection
// Those that are not will be refatored later.
public GlobalDebugParameters globalDebugParameters = new GlobalDebugParameters ( ) ;
public GlobalDebugSettings globalDebugSettings = new GlobalDebugSettings ( ) ;
public RenderingParameters renderingParameters = new RenderingParameters ( ) ;
public RenderingSettings renderingSettings = new RenderingSettings ( ) ;
[SerializeField] ShadowSettings m_ShadowSettings = ShadowSettings . Default ;
public SubsurfaceScatteringParameters localSssParameters ;
[SerializeField] TextureSettings m_TextureSettings = TextureSettings . Default ;
// Renderer Settings (per "scene")
[SerializeField] private CommonSettings . Settings m_CommonSettings = CommonSettings . Settings . s_Defaultsettings ;
[SerializeField] private SkyParameters m_SkyParameter s ;
[SerializeField] private SkySettings m_SkySetting s ;
public CommonSettings . Settings commonSettingsToUse
{
}
}
public SkyParameters skyParameter s
public SkySettings skySetting s
get { return m_SkyParameter s ; }
set { m_SkyParameter s = value ; }
get { return m_SkySetting s ; }
set { m_SkySetting s = value ; }
public SkyParameters skyParameter sToUse
public SkySettings skySetting sToUse
if ( SkyParameter sSingleton . overrideSettings )
return SkyParameter sSingleton . overrideSettings ;
if ( SkySetting sSingleton . overrideSettings )
return SkySetting sSingleton . overrideSettings ;
return m_SkyParameter s ;
return m_SkySetting s ;
}
}
return localSssParameters ;
}
}
public void ApplyDebugParameter s ( )
public void ApplyDebugSetting s ( )
m_ShadowSettings . enabled = globalDebugParameters . lightingDebugParameter s . enableShadows ;
m_ShadowSettings . enabled = globalDebugSettings . lightingDebugSetting s . enableShadows ;
LightingDebugParameters lightDebugParameters = globalDebugParameters . lightingDebugParameter s ;
Vector4 debugModeAndAlbedo = new Vector4 ( ( float ) lightDebugParameter s . lightingDebugMode , lightDebugParameter s . debugLightingAlbedo . r , lightDebugParameter s . debugLightingAlbedo . g , lightDebugParameter s . debugLightingAlbedo . b ) ;
Vector4 debugSmoothness = new Vector4 ( lightDebugParameter s . overrideSmoothness ? 1.0f : 0.0f , lightDebugParameter s . overrideSmoothnessValue , 0.0f , 0.0f ) ;
LightingDebugSettings lightDebugSettings = globalDebugSettings . lightingDebugSetting s ;
Vector4 debugModeAndAlbedo = new Vector4 ( ( float ) lightDebugSetting s . lightingDebugMode , lightDebugSetting s . debugLightingAlbedo . r , lightDebugSetting s . debugLightingAlbedo . g , lightDebugSetting s . debugLightingAlbedo . b ) ;
Vector4 debugSmoothness = new Vector4 ( lightDebugSetting s . overrideSmoothness ? 1.0f : 0.0f , lightDebugSetting s . overrideSmoothnessValue , 0.0f , 0.0f ) ;
Shader . SetGlobalVector ( "_DebugLightModeAndAlbedo" , debugModeAndAlbedo ) ;
Shader . SetGlobalVector ( "_DebugLightingSmoothness" , debugSmoothness ) ;
public void OnValidate ( )
{
globalDebugParameter s . OnValidate ( ) ;
globalDebugSetting s . OnValidate ( ) ;
public class RenderingParameter s
public class RenderingSetting s
{
public bool useForwardRenderingOnly = false ; // TODO: Currently there is no way to strip the extra forward shaders generated by the shaders compiler, so we can switch dynamically.
public bool useDepthPrepass = false ;
readonly SkyManager m_SkyManager = new SkyManager ( ) ;
private readonly BaseLightLoop m_LightLoop ;
private GlobalDebugParameters globalDebugParameter s
private GlobalDebugSettings globalDebugSetting s
get { return m_Owner . globalDebugParameter s ; }
get { return m_Owner . globalDebugSetting s ; }
}
public HDRenderPipelineInstance ( HDRenderPipeline owner )
m_LightLoop . Build ( owner . textureSettings ) ;
m_SkyManager . Build ( ) ;
m_SkyManager . skyParameter s = owner . skyParameter sToUse ;
m_SkyManager . skySetting s = owner . skySetting sToUse ;
}
public override void Dispose ( )
// 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 . skyParameter s = m_Owner . skyParameter sToUse ;
m_SkyManager . skySetting s = m_Owner . skySetting sToUse ;
m_SkyManager . Resize ( camera . nearClipPlane , camera . farClipPlane ) ; // TODO: Also a bad naming, here we just want to realloc texture if skyparameters change (usefull for lookdev)
if ( m_LightLoop = = null )
if ( m_LightLoop ! = null )
m_LightLoop . NewFrame ( ) ;
m_Owner . ApplyDebugParameter s ( ) ;
m_Owner . ApplyDebugSetting s ( ) ;
m_Owner . UpdateCommonSettings ( ) ;
// Set Frame constant buffer
cmd . Dispose ( ) ;
}
if ( globalDebugParameters . materialDebugParameter s . debugViewMaterial ! = 0 )
if ( globalDebugSettings . materialDebugSetting s . debugViewMaterial ! = 0 )
{
RenderDebugViewMaterial ( cullResults , hdCamera , renderContext ) ;
}
void RenderOpaqueRenderList ( CullResults cull , Camera camera , ScriptableRenderContext renderContext , string passName , RendererConfiguration rendererConfiguration = 0 )
{
if ( ! globalDebugParameters . renderingDebugParametr s . displayOpaqueObjects )
if ( ! globalDebugSettings . renderingDebugSetting s . 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 ( ! globalDebugParameters . renderingDebugParametr s . displayTransparentObjects )
if ( ! globalDebugSettings . renderingDebugSetting s . displayTransparentObjects )
return ;
var settings = new DrawRendererSettings ( cull , camera , new ShaderPassName ( passName ) )
{
// If we are forward only we will do a depth prepass
// TODO: Depth prepass should be enabled based on light loop settings. LightLoop define if they need a depth prepass + forward only...
if ( ! m_Owner . renderingParameter s . useDepthPrepass )
if ( ! m_Owner . renderingSetting s . useDepthPrepass )
return ;
using ( new Utilities . ProfilingSample ( "Depth Prepass" , renderContext ) )
void RenderGBuffer ( CullResults cull , Camera camera , ScriptableRenderContext renderContext )
{
if ( m_Owner . renderingParameter s . ShouldUseForwardRenderingOnly ( ) )
if ( m_Owner . renderingSetting s . ShouldUseForwardRenderingOnly ( ) )
{
return ;
}
bool debugLighting = globalDebugParameters . lightingDebugParameters . lightingDebugMode ! = LightingDebugMode . None ;
bool debugLighting = globalDebugSettings . lightingDebugSettings . lightingDebugMode ! = LightingDebugMode . None ;
// setup GBuffer for rendering
Utilities . SetRenderTarget ( renderContext , m_gbufferManager . GetGBuffers ( ) , m_CameraDepthStencilBufferRT ) ;
{
// If we are forward only we don't need to render ForwardOnlyOpaqueDepthOnly object
// But in case we request a prepass we render it
if ( m_Owner . renderingParameter s . ShouldUseForwardRenderingOnly ( ) & & ! m_Owner . renderingParameter s . useDepthPrepass )
if ( m_Owner . renderingSetting s . ShouldUseForwardRenderingOnly ( ) & & ! m_Owner . renderingSetting s . useDepthPrepass )
return ;
using ( new Utilities . ProfilingSample ( "Forward opaque depth" , renderContext ) )
{
Utilities . SetRenderTarget ( renderContext , m_CameraColorBufferRT , m_CameraDepthStencilBufferRT , Utilities . kClearAll , Color . black ) ;
Shader . SetGlobalInt ( "_DebugViewMaterial" , ( int ) globalDebugParameters . materialDebugParameter s . debugViewMaterial ) ;
Shader . SetGlobalInt ( "_DebugViewMaterial" , ( int ) globalDebugSettings . materialDebugSetting s . debugViewMaterial ) ;
if ( ! m_Owner . renderingParameter s . ShouldUseForwardRenderingOnly ( ) )
if ( ! m_Owner . renderingSetting s . ShouldUseForwardRenderingOnly ( ) )
m_DebugViewMaterialGBuffer . SetFloat ( "_DebugViewMaterial" , ( float ) globalDebugParameters . materialDebugParameter s . debugViewMaterial ) ;
m_DebugViewMaterialGBuffer . SetFloat ( "_DebugViewMaterial" , ( float ) globalDebugSettings . materialDebugSetting s . debugViewMaterial ) ;
// m_gbufferManager.BindBuffers(m_DebugViewMaterialGBuffer);
// TODO: Bind depth textures
void RenderDeferredLighting ( HDCamera hdCamera , ScriptableRenderContext renderContext )
{
if ( m_Owner . renderingParameter s . ShouldUseForwardRenderingOnly ( ) | | m_LightLoop = = null )
if ( m_Owner . renderingSetting s . ShouldUseForwardRenderingOnly ( ) | | m_LightLoop = = null )
{
return ;
}
// Output split lighting for materials tagged with the SSS stencil bit.
m_LightLoop . RenderDeferredLighting ( hdCamera , renderContext , globalDebugParameters . lightingDebugParameter s , colorRTs , m_CameraStencilBufferRT , true ) ;
m_LightLoop . RenderDeferredLighting ( hdCamera , renderContext , globalDebugSettings . lightingDebugSetting s , colorRTs , m_CameraStencilBufferRT , true ) ;
m_LightLoop . RenderDeferredLighting ( hdCamera , renderContext , globalDebugParameters . lightingDebugParameter s , colorRTs , m_CameraStencilBufferRT , false ) ;
m_LightLoop . RenderDeferredLighting ( hdCamera , renderContext , globalDebugSettings . lightingDebugSetting s , colorRTs , m_CameraStencilBufferRT , false ) ;
}
// Combines specular lighting and diffuse lighting with subsurface scattering.
if ( m_Owner . renderingParameters . ShouldUseForwardRenderingOnly ( ) ) return ;
if ( m_Owner . renderingSettings . ShouldUseForwardRenderingOnly ( ) ) return ;
// Load the kernel data.
Vector4 [ ] kernelData = new Vector4 [ SubsurfaceScatteringParameters . maxNumProfiles * SubsurfaceScatteringProfile . numVectors ] ;
{
// TODO: Currently we can't render opaque object forward when deferred is enabled
// miss option
if ( ! m_Owner . renderingParameter s . ShouldUseForwardRenderingOnly ( ) & & renderOpaque )
if ( ! m_Owner . renderingSetting s . ShouldUseForwardRenderingOnly ( ) & & renderOpaque )
return ;
using ( new Utilities . ProfilingSample ( "Forward Pass" , renderContext ) )
if ( m_LightLoop ! = null )
m_LightLoop . RenderForward ( camera , renderContext , renderOpaque ) ;
bool debugLighting = globalDebugParameters . lightingDebugParameter s . lightingDebugMode ! = LightingDebugMode . None ;
bool debugLighting = globalDebugSettings . lightingDebugSetting s . lightingDebugMode ! = LightingDebugMode . None ;
string forwardPassName = debugLighting ? "ForwardDebugLighting" : "Forward" ;
if ( renderOpaque )
if ( m_LightLoop ! = null )
m_LightLoop . RenderForward ( camera , renderContext , true ) ;
bool debugLighting = globalDebugParameters . lightingDebugParameter s . lightingDebugMode ! = LightingDebugMode . None ;
bool debugLighting = globalDebugSettings . lightingDebugSetting s . lightingDebugMode ! = LightingDebugMode . None ;
RenderOpaqueRenderList ( cullResults , camera , renderContext , debugLighting ? "ForwardOnlyOpaqueDebugLighting" : "ForwardOnlyOpaque" , Utilities . kRendererConfigurationBakedLighting ) ;
}
}
using ( new Utilities . ProfilingSample ( "Velocity Pass" , renderContext ) )
{
// If opaque velocity have been render during GBuffer no need to render it here
if ( ( ShaderConfig . s_VelocityInGbuffer = = 1 ) | | m_Owner . renderingParameter s . ShouldUseForwardRenderingOnly ( ) )
if ( ( ShaderConfig . s_VelocityInGbuffer = = 1 ) | | m_Owner . renderingSetting s . ShouldUseForwardRenderingOnly ( ) )
return ;
int w = camera . pixelWidth ;
void RenderDistortion ( CullResults cullResults , Camera camera , ScriptableRenderContext renderContext )
{
if ( ! globalDebugParameters . renderingDebugParametr s . enableDistortion )
if ( ! globalDebugSettings . renderingDebugSetting s . enableDistortion )
return ;
using ( new Utilities . ProfilingSample ( "Distortion Pass" , renderContext ) )
debugCB . name = "Debug Overlay" ;
float x = 0 ;
float overlayRatio = globalDebugParameter s . debugOverlayRatio ;
float overlayRatio = globalDebugSetting s . debugOverlayRatio ;
LightingDebugParameters shadowDebug = globalDebugParameters . lightingDebugParameter s ;
LightingDebugSettings shadowDebug = globalDebugSettings . lightingDebugSetting s ;
if ( shadowDebug . shadowDebugMode ! = ShadowDebugMode . None )
{
cmd . GetTemporaryRT ( m_CameraDepthStencilBufferCopy , w , h , 2 4 , FilterMode . Point , RenderTextureFormat . Depth ) ;
cmd . GetTemporaryRT ( m_CameraStencilBuffer , w , h , 2 4 , FilterMode . Point , RenderTextureFormat . Depth ) ;
if ( ! m_Owner . renderingParameter s . ShouldUseForwardRenderingOnly ( ) )
if ( ! m_Owner . renderingSetting s . ShouldUseForwardRenderingOnly ( ) )
{
m_gbufferManager . InitGBuffers ( w , h , cmd ) ;
}
}
// Clear GBuffers
if ( ! m_Owner . renderingParameter s . ShouldUseForwardRenderingOnly ( ) )
if ( ! m_Owner . renderingSetting s . ShouldUseForwardRenderingOnly ( ) )
{
using ( new Utilities . ProfilingSample ( "Clear GBuffer" , renderContext ) )
{