private HDRenderPipeline ( )
{ }
[SerializeField]
private LightLoopProducer m_LightLoopProducer ;
public LightLoopProducer lightLoopProducer
{
get { return m_LightLoopProducer ; }
set { m_LightLoopProducer = value ; }
}
[SerializeField]
private CommonSettings . Settings m_CommonSettings = CommonSettings . Settings . s_Defaultsettings ;
protected override IRenderPipeline InternalCreatePipeline ( )
{
return new HDRenderPipelineInstance ( this ) ;
}
// NOTE:
// All those properties are public because of how HDRenderPipelineInspector retrieve those properties via serialization/reflection
// Debugging
public GlobalDebugParameters globalDebugParameters = new GlobalDebugParameters ( ) ;
// Renderer Settings (per project)
public RenderingParameters renderingParameters = new RenderingParameters ( ) ;
[SerializeField] ShadowSettings m_ShadowSettings = ShadowSettings . Default ;
[SerializeField] SubsurfaceScatteringParameters m_SssParameters = SubsurfaceScatteringParameters . Default ;
[SerializeField] TextureSettings m_TextureSettings = TextureSettings . Default ;
public ShadowSettings shadowSettings { get { return m_ShadowSettings ; } }
public SubsurfaceScatteringParameters sssParameters { get { return m_SssParameters ; } }
public TextureSettings textureSettings { get { return m_TextureSettings ; } set { m_TextureSettings = value ; } }
// Renderer Settings (per "scene")
[SerializeField] private CommonSettings . Settings m_CommonSettings = CommonSettings . Settings . s_Defaultsettings ;
[SerializeField] private SkyParameters m_SkyParameters ;
{
{
if ( CommonSettingsSingleton . overrideSettings )
return CommonSettingsSingleton . overrideSettings . settings ;
[SerializeField]
private SkyParameters m_SkyParameters ;
public SkyParameters skyParameters
{
}
}
[SerializeField]
private LightLoopProducer m_LightLoopProducer ;
public LightLoopProducer lightLoopProducer
{
get { return m_LightLoopProducer ; }
set { m_LightLoopProducer = value ; }
}
protected override IRenderPipeline InternalCreatePipeline ( )
{
return new HDRenderPipelineInstance ( this ) ;
}
// Debugging
public GlobalDebugParameters globalDebugParameters = new GlobalDebugParameters ( ) ;
readonly DebugParameters m_DebugParameters = new DebugParameters ( ) ;
public DebugParameters debugParameters
{
get { return m_DebugParameters ; }
}
[SerializeField]
ShadowSettings m_ShadowSettings = ShadowSettings . Default ;
public ShadowSettings shadowSettings
{
get { return m_ShadowSettings ; }
}
[SerializeField]
SubsurfaceScatteringParameters m_SssParameters = SubsurfaceScatteringParameters . Default ;
public SubsurfaceScatteringParameters sssParameters
{
get { return m_SssParameters ; }
}
[SerializeField]
TextureSettings m_TextureSettings = TextureSettings . Default ;
public TextureSettings textureSettings
{
get { return m_TextureSettings ; }
set { m_TextureSettings = value ; }
}
public void ApplyDebugParameters ( )
{
m_ShadowSettings . enabled = globalDebugParameters . lightingDebugParameters . enableShadows ;
}
}
[Serializable]
public class RenderingParameters
{
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 ;
// we have to fallback to forward-only rendering when scene view is using wireframe rendering mode --
// as rendering everything in wireframe + deferred do not play well together
public bool ShouldUseForwardRenderingOnly ( )
{
return useForwardRenderingOnly | | GL . wireframe ;
}
}
public struct HDCamera
{
public Camera camera ;
}
public class GBufferManager
{
public const int MaxGbuffer = 8 ;
public void SetBufferDescription ( int index , string stringId , RenderTextureFormat inFormat , RenderTextureReadWrite inSRGBWrite )
{
IDs [ index ] = Shader . PropertyToID ( stringId ) ;
RTIDs [ index ] = new RenderTargetIdentifier ( IDs [ index ] ) ;
formats [ index ] = inFormat ;
sRGBWrites [ index ] = inSRGBWrite ;
public class GBufferManager
public void InitGBuffers ( int width , int height , CommandBuffer cmd )
public const int MaxGbuffer = 8 ;
public void SetBufferDescription ( int index , string stringId , RenderTextureFormat inFormat , RenderTextureReadWrite inSRGBWrite )
for ( int index = 0 ; index < gbufferCount ; index + + )
IDs [ index ] = Shader . PropertyToID ( stringId ) ;
RTIDs [ index ] = new RenderTargetIdentifier ( IDs [ index ] ) ;
formats [ index ] = inFormat ;
sRGBWrites [ index ] = inSRGBWrite ;
}
public void InitGBuffers ( int width , int height , CommandBuffer cmd )
{
for ( int index = 0 ; index < gbufferCount ; index + + )
{
}
}
public RenderTargetIdentifier [ ] GetGBuffers ( )
public RenderTargetIdentifier [ ] GetGBuffers ( )
{
var colorMRTs = new RenderTargetIdentifier [ gbufferCount ] ;
for ( int index = 0 ; index < gbufferCount ; index + + )
var colorMRTs = new RenderTargetIdentifier [ gbufferCount ] ;
for ( int index = 0 ; index < gbufferCount ; index + + )
{
colorMRTs [ index ] = RTIDs [ index ] ;
}
return colorMRTs ;
colorMRTs [ index ] = RTIDs [ index ] ;
/ *
public void BindBuffers ( Material mat )
return colorMRTs ;
}
/ *
public void BindBuffers ( Material mat )
{
for ( int index = 0 ; index < gbufferCount ; index + + )
for ( int index = 0 ; index < gbufferCount ; index + + )
{
mat . SetTexture ( IDs [ index ] , RTs [ index ] ) ;
}
mat . SetTexture ( IDs [ index ] , RTs [ index ] ) ;
* /
public int gbufferCount { get ; set ; }
int [ ] IDs = new int [ MaxGbuffer ] ;
RenderTargetIdentifier [ ] RTIDs = new RenderTargetIdentifier [ MaxGbuffer ] ;
RenderTextureFormat [ ] formats = new RenderTextureFormat [ MaxGbuffer ] ;
RenderTextureReadWrite [ ] sRGBWrites = new RenderTextureReadWrite [ MaxGbuffer ] ;
* /
public int gbufferCount { get ; set ; }
int [ ] IDs = new int [ MaxGbuffer ] ;
RenderTargetIdentifier [ ] RTIDs = new RenderTargetIdentifier [ MaxGbuffer ] ;
RenderTextureFormat [ ] formats = new RenderTextureFormat [ MaxGbuffer ] ;
RenderTextureReadWrite [ ] sRGBWrites = new RenderTextureReadWrite [ MaxGbuffer ] ;
}
{
{
private readonly HDRenderPipeline m_Owner ;
// TODO: Find a way to automatically create/iterate through deferred material
readonly SkyManager m_SkyManager = new SkyManager ( ) ;
private readonly BaseLightLoop m_LightLoop ;
private DebugParameters debugParameters
{
get { return m_Owner . debugParameters ; }
}
private GlobalDebugParameters globalDebugParameters
{
get { return m_Owner . globalDebugParameters ; }
cmd . Dispose ( ) ;
}
if ( d ebugParameters. debugViewMaterial ! = 0 )
if ( globalDebugParameters . materialD ebugParameters. debugViewMaterial ! = 0 )
{
RenderDebugViewMaterial ( cullResults , hdCamera , renderContext ) ;
}
{
// 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 ( ! debu gParameters. useDepthPrepass )
if ( ! m_Owner . renderin gParameters. useDepthPrepass )
return ;
using ( new Utilities . ProfilingSample ( "Depth Prepass" , renderContext ) )
void RenderGBuffer ( CullResults cull , Camera camera , ScriptableRenderContext renderContext )
{
if ( debu gParameters. ShouldUseForwardRenderingOnly ( ) )
if ( m_Owner . renderin gParameters. ShouldUseForwardRenderingOnly ( ) )
{
return ;
}
{
// If we are forward only we don't need to render ForwardOnlyOpaqueDepthOnly object
// But in case we request a prepass we render it
if ( debu gParameters. ShouldUseForwardRenderingOnly ( ) & & ! debu gParameters. useDepthPrepass )
if ( m_Owner . renderin gParameters. ShouldUseForwardRenderingOnly ( ) & & ! m_Owner . renderin gParameters. 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 ) d ebugParameters. debugViewMaterial ) ;
Shader . SetGlobalInt ( "_DebugViewMaterial" , ( int ) globalDebugParameters . materialD ebugParameters. debugViewMaterial ) ;
if ( ! debu gParameters. ShouldUseForwardRenderingOnly ( ) )
if ( ! m_Owner . renderin gParameters. ShouldUseForwardRenderingOnly ( ) )
m_DebugViewMaterialGBuffer . SetFloat ( "_DebugViewMaterial" , ( float ) d ebugParameters. debugViewMaterial ) ;
m_DebugViewMaterialGBuffer . SetFloat ( "_DebugViewMaterial" , ( float ) globalDebugParameters . materialD ebugParameters. debugViewMaterial ) ;
// m_gbufferManager.BindBuffers(m_DebugViewMaterialGBuffer);
// TODO: Bind depth textures
void RenderDeferredLighting ( HDCamera hdCamera , ScriptableRenderContext renderContext )
{
if ( debu gParameters. ShouldUseForwardRenderingOnly ( ) | | m_LightLoop = = null )
if ( m_Owner . renderin gParameters. ShouldUseForwardRenderingOnly ( ) | | m_LightLoop = = null )
{
return ;
}
void CombineSubsurfaceScattering ( HDCamera hdCamera , ScriptableRenderContext context , SubsurfaceScatteringParameters sssParameters )
{
// Currently, forward-rendered objects do not output split lighting required for the SSS pass.
if ( debu gParameters. ShouldUseForwardRenderingOnly ( ) ) return ;
if ( m_Owner . renderin gParameters. 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 ) ;
{
// TODO: Currently we can't render opaque object forward when deferred is enabled
// miss option
if ( ! debu gParameters. ShouldUseForwardRenderingOnly ( ) & & renderOpaque )
if ( ! m_Owner . renderin gParameters. ShouldUseForwardRenderingOnly ( ) & & renderOpaque )
return ;
using ( new Utilities . ProfilingSample ( "Forward Pass" , renderContext ) )
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 ) | | debu gParameters. ShouldUseForwardRenderingOnly ( ) )
if ( ( ShaderConfig . s_VelocityInGbuffer = = 1 ) | | m_Owner . renderin gParameters. ShouldUseForwardRenderingOnly ( ) )
return ;
int w = camera . pixelWidth ;
LightingDebugParameters shadowDebug = globalDebugParameters . lightingDebugParameters ;
if ( shadowDebug . visualization Mode ! = ShadowDebugMode . None )
if ( shadowDebug . shadowDebug Mode ! = ShadowDebugMode . None )
if ( shadowDebug . visualization Mode = = ShadowDebugMode . VisualizeShadowMap )
if ( shadowDebug . shadowDebug Mode = = ShadowDebugMode . VisualizeShadowMap )
uint visualizeShadowIndex = Math . Min ( shadowDebug . vi sualizeS hadowMapIndex, ( uint ) ( GetCurrentShadowCount ( ) - 1 ) ) ;
uint visualizeShadowIndex = Math . Min ( shadowDebug . shadowMapIndex , ( uint ) ( GetCurrentShadowCount ( ) - 1 ) ) ;
ShadowLight shadowLight = m_ShadowsResult . shadowLights [ visualizeShadowIndex ] ;
for ( int slice = 0 ; slice < shadowLight . shadowSliceCount ; + + slice )
{
NextOverlayCoord ( ref x , ref y , overlaySize , camera . pixelWidth ) ;
}
}
else if ( shadowDebug . visualization Mode = = ShadowDebugMode . VisualizeAtlas )
else if ( shadowDebug . shadowDebug Mode = = ShadowDebugMode . VisualizeAtlas )
{
propertyBlock . SetVector ( "_TextureScaleBias" , new Vector4 ( 1.0f , 1.0f , 0.0f , 0.0f ) ) ;
cmd . GetTemporaryRT ( m_CameraDepthStencilBuffer , w , h , 2 4 , FilterMode . Point , RenderTextureFormat . Depth ) ;
cmd . GetTemporaryRT ( m_CameraStencilBuffer , w , h , 2 4 , FilterMode . Point , RenderTextureFormat . Depth ) ;
if ( ! m_Owner . debu gParameters. ShouldUseForwardRenderingOnly ( ) )
if ( ! m_Owner . renderin gParameters. ShouldUseForwardRenderingOnly ( ) )
{
m_gbufferManager . InitGBuffers ( w , h , cmd ) ;
}
}
// Clear GBuffers
if ( ! debu gParameters. ShouldUseForwardRenderingOnly ( ) )
if ( ! m_Owner . renderin gParameters. ShouldUseForwardRenderingOnly ( ) )
{
using ( new Utilities . ProfilingSample ( "Clear GBuffer" , renderContext ) )
{