public Material GetBlitMaterial ( ) { return m_Blit ; }
FrameSettings m_FrameSettings ; // Init every frame
ComputeBuffer m_DebugScreenSpaceTracingData = null ;
ScreenSpaceTracingDebug [ ] m_DebugScreenSpaceTracingDataArray = new ScreenSpaceTracingDebug [ 1 ] ;
}
m_Asset = asset ;
// Initial state of the RTHandle system.
// Tells the system that we will require MSAA or not so that we can avoid wasteful render texture allocation.
// TODO: Might want to initialize to at least the window resolution to avoid un-necessary re-alloc in the player
RTHandles . Initialize ( 1 , 1 , m_Asset . renderPipelineSettings . supportMSAA , m_Asset . renderPipelineSettings . msaaSampleCount ) ;
var bufferPyramidProcessor = new BufferPyramidProcessor (
asset . renderPipelineResources . colorPyramidCS ,
asset . renderPipelineResources . depthPyramidCS ,
void InitializeRenderTextures ( )
{
// Initial state of the RTHandle system.
// Tells the system that we will require MSAA or not so that we can avoid wasteful render texture allocation.
// TODO: Might want to initialize to at least the window resolution to avoid un-necessary re-alloc in the player
RTHandles . Initialize ( 1 , 1 , m_Asset . renderPipelineSettings . supportMSAA , m_Asset . renderPipelineSettings . msaaSampleCount ) ;
if ( ! m_Asset . renderPipelineSettings . supportForwardOnly )
m_GbufferManager . CreateBuffers ( ) ;
RTHandles . Release ( m_DebugFullScreenTempBuffer ) ;
m_DebugScreenSpaceTracingData . Release ( ) ;
HDCamera . CleanUnused ( ) ;
}
m_VolumetricLightingSystem . Cleanup ( ) ;
m_IBLFilterGGX . Cleanup ( ) ;
HDCamera . ClearAll ( ) ;
DestroyRenderTextures ( ) ;
#if UNITY_EDITOR
if ( m_CurrentWidth > 0 & & m_CurrentHeight > 0 )
m_LightLoop . ReleaseResolutionDependentBuffers ( ) ;
m_LightLoop . AllocResolutionDependentBuffers ( ( int ) hdCamera . screenSize . x , ( int ) hdCamera . screenSize . y , m_FrameSettings . enableStereo ) ;
m_LightLoop . AllocResolutionDependentBuffers ( ( int ) hdCamera . screenSize . x , ( int ) hdCamera . screenSize . y , hdCamera . frameSettings . enableStereo ) ;
// Warning: (resolutionChanged == false) if you open a new Editor tab of the same size!
m_VolumetricLightingSystem . ResizeVBufferAndUpdateProperties ( hdCamera , m_FrameCount ) ;
// update recorded window resolution
m_CurrentWidth = hdCamera . actualWidth ;
using ( new ProfilingSample ( cmd , "Push Global Parameters" , CustomSamplerId . PushGlobalParameters . GetSampler ( ) ) )
{
// Set up UnityPerFrame CBuffer.
m_SSSBufferManager . PushGlobalParams ( cmd , sssParameters , m_FrameSetting s ) ;
m_SSSBufferManager . PushGlobalParams ( hdCamera , cmd , sssParameters ) ;
m_DbufferManager . PushGlobalParams ( cmd , m_FrameSettings ) ;
m_DbufferManager . PushGlobalParams ( hdCamera , cmd ) ;
m_VolumetricLightingSystem . PushGlobalParams ( hdCamera , cmd , m_FrameCount ) ;
// Set up UnityPerView CBuffer.
hdCamera . SetupGlobalParams ( cmd , m_Time , m_LastTime ) ;
if ( m_FrameSettings . enableStereo ) hdCamera . SetupGlobalStereoParams ( cmd ) ;
if ( hdCamera . frameSettings . enableStereo )
hdCamera . SetupGlobalStereoParams ( cmd ) ;
var previousDepthPyramidRT = hdCamera . GetPreviousFrameRT ( ( int ) HDCameraFrameHistoryType . DepthPyramid ) ;
if ( previousDepthPyramidRT ! = null )
}
}
public void UpdateShadowSettings ( )
public void UpdateShadowSettings ( HDCamera hdCamera )
{
var shadowSettings = VolumeManager . instance . stack . GetComponent < HDShadowSettings > ( ) ;
m_ShadowSettings . enabled = m_FrameSettings . enableShadow ;
m_ShadowSettings . enabled = hdCamera . frameSettings . enableShadow ;
}
public void ConfigureForShadowMask ( bool enableBakeShadowMask , CommandBuffer cmd )
{
srcFrameSettings = m_Asset . GetFrameSettings ( ) ;
}
FrameSettings currentFrameSettings = new FrameSettings ( ) ;
FrameSettings . InitializeFrameSettings ( camera , m_Asset . GetRenderPipelineSettings ( ) , srcFrameSettings , ref m_FrameSettings ) ;
FrameSettings . InitializeFrameSettings ( camera , m_Asset . GetRenderPipelineSettings ( ) , srcFrameSettings , ref currentFrameSettings ) ;
// This is the main command buffer used for the frame.
var cmd = CommandBufferPool . Get ( "" ) ;
using ( new ProfilingSample ( cmd , "HDRenderPipeline::Render" , CustomSamplerId . HDRenderPipelineRender . GetSampler ( ) ) )
{
// Do anything we need to do upon a new frame.
m_LightLoop . NewFrame ( m_ FrameSettings) ;
m_LightLoop . NewFrame ( current FrameSettings) ;
// If we render a reflection view or a preview we should not display any debug information
// This need to be call before ApplyDebugDisplaySettings()
// Disable post process if we enable debug mode or if the post process layer is disabled
if ( m_CurrentDebugDisplaySettings . IsDebugDisplayRemovePostprocess ( ) | | ! CoreUtils . IsPostProcessingActive ( postProcessLayer ) )
{
m_FrameSettings . enablePostprocess = false ;
currentFrameSettings . enablePostprocess = false ;
var hdCamera = HDCamera . Get ( camera , postProcessLayer , m_FrameSettings ) ;
var hdCamera = HDCamera . Get ( camera ) ;
if ( hdCamera = = null )
{
hdCamera = HDCamera . Create ( camera , m_VolumetricLightingSystem ) ;
}
// From this point, we should only use frame settings from the camera
hdCamera . Update ( currentFrameSettings , postProcessLayer , m_VolumetricLightingSystem ) ;
UpdateShadowSettings ( ) ;
UpdateShadowSettings ( hdCamera ) ;
if ( ! CullResults . GetCullingParameters ( camera , m_FrameSettings . enableStereo , out cullingParams ) )
if ( ! CullResults . GetCullingParameters ( camera , hdCamera . frameSettings . enableStereo , out cullingParams ) )
{
renderContext . Submit ( ) ;
continue ;
hdCamera . UpdateStereoDependentState ( m_FrameSettings , ref cullingParams ) ;
hdCamera . UpdateStereoDependentState ( ref cullingParams ) ;
#if UNITY_EDITOR
// emit scene view UI
}
#endif
if ( m_F rameSettings. enableDBuffer )
if ( hdCamera . f rameSettings. enableDBuffer )
{
// decal system needs to be updated with current camera, it needs it to set up culling and light list generation parameters
DecalSystem . instance . CurrentCamera = camera ;
m_DbufferManager . vsibleDecalCount = 0 ;
using ( new ProfilingSample ( cmd , "DBufferPrepareDrawData" , CustomSamplerId . DBufferPrepareDrawData . GetSampler ( ) ) )
{
if ( m_F rameSettings. enableDBuffer )
if ( hdCamera . f rameSettings. enableDBuffer )
{
DecalSystem . instance . EndCull ( ) ;
m_DbufferManager . vsibleDecalCount = DecalSystem . m_DecalsVisibleThisFrame ;
}
}
renderContext . SetupCameraProperties ( camera , m_F rameSettings. enableStereo ) ;
renderContext . SetupCameraProperties ( camera , hdCamera . f rameSettings. enableStereo ) ;
PushGlobalParams ( hdCamera , cmd , diffusionProfileSettings ) ;
bool enableBakeShadowMask ;
using ( new ProfilingSample ( cmd , "TP_PrepareLightsForGPU" , CustomSamplerId . TPPrepareLightsForGPU . GetSampler ( ) ) )
{
enableBakeShadowMask = m_LightLoop . PrepareLightsForGPU ( cmd , camera , m_ShadowSettings , m_CullResults , m_ReflectionProbeCullResults , densityVolumes ) & & m_F rameSettings. enableShadowMask ;
enableBakeShadowMask = m_LightLoop . PrepareLightsForGPU ( cmd , camera , m_ShadowSettings , m_CullResults , m_ReflectionProbeCullResults , densityVolumes ) & & hdCamera . f rameSettings. enableShadowMask ;
StartStereoRendering ( renderContext , hdCamera . camera ) ;
StartStereoRendering ( renderContext , hdCamera ) ;
ClearBuffers ( hdCamera , cmd ) ;
RenderObjectsVelocity ( m_CullResults , hdCamera , renderContext , cmd ) ;
// This will bind the depth buffer if needed for DBuffer)
RenderDBuffer ( hdCamera , cmd ) ;
RenderGBuffer ( m_CullResults , hdCamera , enableBakeShadowMask , renderContext , cmd ) ;
RenderCameraVelocity ( m_CullResults , hdCamera , renderContext , cmd ) ;
// Depth texture is now ready, bind it.
cmd . SetGlobalTexture ( HDShaderIDs . _Main DepthTexture , GetDepthTexture ( ) ) ;
// Depth texture is now ready, bind it (Depth buffer could have been bind before if DBuffer is enable)
cmd . SetGlobalTexture ( HDShaderIDs . _Camera DepthTexture , GetDepthTexture ( ) ) ;
// Caution: We require sun light here as some skies use the sun light to render, it means that UpdateSkyEnvironment must be called after PrepareLightsForGPU.
// TODO: Try to arrange code so we can trigger this call earlier and use async compute here to run sky convolution during other passes (once we move convolution shader to compute).
StopStereoRendering ( renderContext , hdCamera . camera ) ;
StopStereoRendering ( renderContext , hdCamera ) ;
if ( m_CurrentDebugDisplaySettings . IsDebugMaterialDisplayEnabled ( ) )
{
}
else
{
StartStereoRendering ( renderContext , hdCamera . camera ) ;
StartStereoRendering ( renderContext , hdCamera ) ;
using ( new ProfilingSample ( cmd , "Render SSAO" , CustomSamplerId . RenderSSAO . GetSampler ( ) ) )
{
}
}
StopStereoRendering ( renderContext , hdCamera . camera ) ;
StopStereoRendering ( renderContext , hdCamera ) ;
if ( m_F rameSettings. enableAsyncCompute )
if ( hdCamera . f rameSettings. enableAsyncCompute )
{
GPUFence startFence = cmd . CreateGPUFence ( ) ;
renderContext . ExecuteCommandBuffer ( cmd ) ;
m_LightLoop . RenderShadows ( renderContext , cmd , m_CullResults ) ;
// Overwrite camera properties set during the shadow pass with the original camera properties.
renderContext . SetupCameraProperties ( camera , m_FrameSettings . enableStereo ) ;
renderContext . SetupCameraProperties ( camera , hdCamera . frameSettings . enableStereo ) ;
if ( m_FrameSettings . enableStereo ) hdCamera . SetupGlobalStereoParams ( cmd ) ;
if ( hdCamera . frameSettings . enableStereo )
hdCamera . SetupGlobalStereoParams ( cmd ) ;
}
using ( new ProfilingSample ( cmd , "Deferred directional shadows" , CustomSamplerId . RenderDeferredDirectionalShadow . GetSampler ( ) ) )
}
m_LightLoop . RenderDeferredDirectionalShadow ( hdCamera , m_DeferredShadowBuffer , GetDepthTexture ( ) , cmd ) ;
PushFullScreenDebugTexture ( cmd , m_DeferredShadowBuffer , hdCamera , FullScreenDebugMode . DeferredShadows ) ;
PushFullScreenDebugTexture ( hdCamera , cmd , m_DeferredShadowBuffer , FullScreenDebugMode . DeferredShadows ) ;
if ( m_F rameSettings. enableAsyncCompute )
if ( hdCamera . f rameSettings. enableAsyncCompute )
{
m_LightLoop . BuildGPULightListAsyncEnd ( hdCamera , cmd , buildGPULightListsCompleteFence ) ;
}
{
// Set fog parameters for volumetric lighting.
var visualEnv = VolumeManager . instance . stack . GetComponent < VisualEnvironment > ( ) ;
visualEnv . PushFogShaderParameters ( cmd , m_FrameSettings ) ;
visualEnv . PushFogShaderParameters ( hdCamera , cmd ) ;
m_VolumetricLightingSystem . VolumeVoxelizationPass ( densityVolumes , hdCamera , cmd , m_FrameSettings , m_FrameCount ) ;
m_VolumetricLightingSystem . VolumeVoxelizationPass ( hdCamera , cmd , m_FrameCount , densityVolumes ) ;
m_VolumetricLightingSystem . VolumetricLightingPass ( hdCamera , cmd , m_FrameSettings , m_Frame Count ) ;
m_VolumetricLightingSystem . VolumetricLightingPass ( hdCamera , cmd , m_FrameCount ) ;
StartStereoRendering ( renderContext , hdCamera . camera ) ;
StartStereoRendering ( renderContext , hdCamera ) ;
m_SSSBufferManager . SubsurfaceScatteringPass ( hdCamera , cmd , diffusionProfileSettings , m_FrameSettings ,
m_SSSBufferManager . SubsurfaceScatteringPass ( hdCamera , cmd , diffusionProfileSettings ,
m_CameraColorBuffer , m_CameraSssDiffuseLightingBuffer , m_CameraDepthStencilBuffer , GetDepthTexture ( ) ) ;
RenderSky ( hdCamera , cmd ) ;
RenderColorPyramid ( hdCamera , cmd , renderContext , false ) ;
AccumulateDistortion ( m_CullResults , hdCamera , renderContext , cmd ) ;
RenderDistortion ( cmd , m_Asset . renderPipelineResources , hdCamera ) ;
RenderDistortion ( hdCamera , cmd , m_Asset . renderPipelineResources ) ;
StopStereoRendering ( renderContext , hdCamera . camera ) ;
StopStereoRendering ( renderContext , hdCamera ) ;
PushFullScreenDebugTexture ( cmd , m_CameraColorBuffer , hdCamera , FullScreenDebugMode . NanTracker ) ;
PushColorPickerDebugTexture ( cmd , m_CameraColorBuffer , hdCamera ) ;
PushFullScreenDebugTexture ( hdCamera , cmd , m_CameraColorBuffer , FullScreenDebugMode . NanTracker ) ;
PushColorPickerDebugTexture ( hdCamera , cmd , m_CameraColorBuffer ) ;
StartStereoRendering ( renderContext , hdCamera . camera ) ;
StartStereoRendering ( renderContext , hdCamera ) ;
if ( m_F rameSettings. enablePostprocess )
if ( hdCamera . f rameSettings. enablePostprocess )
{
RenderPostProcess ( hdCamera , cmd , postProcessLayer ) ;
}
}
}
StopStereoRendering ( renderContext , hdCamera . camera ) ;
StopStereoRendering ( renderContext , hdCamera ) ;
if ( m_F rameSettings. enableStereo )
if ( hdCamera . f rameSettings. enableStereo )
renderContext . StereoEndRender ( hdCamera . camera ) ;
}
}
}
#endif
PushFullScreenDebugTexture ( cmd , m_CameraColorBuffer , hdCamera , FullScreenDebugMode . ScreenSpaceTracing ) ;
PushFullScreenDebugTexture ( hdCamera , cmd , m_CameraColorBuffer , FullScreenDebugMode . ScreenSpaceTracing ) ;
// Caution: RenderDebug need to take into account that we have flip the screen (so anything capture before the flip will be flipped)
RenderDebug ( hdCamera , cmd ) ;
}
void RenderOpaqueRenderList ( CullResults cull ,
Camera c amera,
HDCamera hdC amera,
ScriptableRenderContext renderContext ,
CommandBuffer cmd ,
ShaderPassName passName ,
Material overrideMaterial = null )
{
m_SinglePassName [ 0 ] = passName ;
RenderOpaqueRenderList ( cull , c amera, renderContext , cmd , m_SinglePassName , rendererConfiguration , inRenderQueueRange , stateBlock , overrideMaterial ) ;
RenderOpaqueRenderList ( cull , hdC amera, renderContext , cmd , m_SinglePassName , rendererConfiguration , inRenderQueueRange , stateBlock , overrideMaterial ) ;
Camera c amera,
HDCamera hdC amera,
ScriptableRenderContext renderContext ,
CommandBuffer cmd ,
ShaderPassName [ ] passNames ,
Material overrideMaterial = null )
{
if ( ! m_F rameSettings. enableOpaqueObjects )
if ( ! hdCamera . f rameSettings. enableOpaqueObjects )
return ;
// This is done here because DrawRenderers API lives outside command buffers so we need to make call this before doing any DrawRenders
var drawSettings = new DrawRendererSettings ( camera , HDShaderPassNames . s_EmptyName )
var drawSettings = new DrawRendererSettings ( hdCamera . camera , HDShaderPassNames . s_EmptyName )
{
rendererConfiguration = rendererConfiguration ,
sorting = { flags = SortFlags . CommonOpaque }
}
void RenderTransparentRenderList ( CullResults cull ,
Camera c amera,
HDCamera hdC amera,
ScriptableRenderContext renderContext ,
CommandBuffer cmd ,
ShaderPassName passName ,
Material overrideMaterial = null )
{
m_SinglePassName [ 0 ] = passName ;
RenderTransparentRenderList ( cull , c amera, renderContext , cmd , m_SinglePassName ,
RenderTransparentRenderList ( cull , hdC amera, renderContext , cmd , m_SinglePassName ,
Camera c amera,
HDCamera hdC amera,
ScriptableRenderContext renderContext ,
CommandBuffer cmd ,
ShaderPassName [ ] passNames ,
Material overrideMaterial = null
)
{
if ( ! m_F rameSettings. enableTransparentObjects )
if ( ! hdCamera . f rameSettings. enableTransparentObjects )
return ;
// This is done here because DrawRenderers API lives outside command buffers so we need to make call this before doing any DrawRenders
var drawSettings = new DrawRendererSettings ( camera , HDShaderPassNames . s_EmptyName )
var drawSettings = new DrawRendererSettings ( hdCamera . camera , HDShaderPassNames . s_EmptyName )
{
rendererConfiguration = rendererConfiguration ,
sorting = { flags = SortFlags . CommonTransparent }
void AccumulateDistortion ( CullResults cullResults , HDCamera hdCamera , ScriptableRenderContext renderContext , CommandBuffer cmd )
{
if ( ! m_F rameSettings. enableDistortion )
if ( ! hdCamera . f rameSettings. enableDistortion )
return ;
using ( new ProfilingSample ( cmd , "Distortion" , CustomSamplerId . Distortion . GetSampler ( ) ) )
// Only transparent object can render distortion vectors
RenderTransparentRenderList ( cullResults , hdCamera . camera , renderContext , cmd , HDShaderPassNames . s_DistortionVectorsName ) ;
RenderTransparentRenderList ( cullResults , hdCamera , renderContext , cmd , HDShaderPassNames . s_DistortionVectorsName ) ;
void RenderDistortion ( CommandBuffer cmd , RenderPipelineResources resources , HDCamera hdCamera )
void RenderDistortion ( HDCamera hdCamera , CommandBuffer cmd , RenderPipelineResources resources )
if ( ! m_F rameSettings. enableDistortion )
if ( ! hdCamera . f rameSettings. enableDistortion )
return ;
using ( new ProfilingSample ( cmd , "ApplyDistortion" , CustomSamplerId . ApplyDistortion . GetSampler ( ) ) )
// by using the pass "ForwardOnly". In this case the .shader should not have "Forward" but only a "ForwardOnly" pass.
// It must also have a "DepthForwardOnly" and no "DepthOnly" pass as forward material (either deferred or forward only rendering) have always a depth pass.
// If a forward material have no depth prepass, then lighting can be incorrect (deferred sahdowing, SSAO), this may be acceptable depends on usage
bool addFullDepthPrepass = forcePrepass | | m_FrameSettings . enableForwardRenderingOnly | | m_FrameSettings . enableDepthPrepassWithDeferredRendering ;
var camera = hdCamera . camera ;
bool addFullDepthPrepass = forcePrepass | | hdCamera . frameSettings . enableForwardRenderingOnly | | hdCamera . frameSettings . enableDepthPrepassWithDeferredRendering ;
using ( new ProfilingSample ( cmd , ! addFullDepthPrepass ? "Depth Prepass alpha test" : "Depth Prepass" , CustomSamplerId . DepthPrepass . GetSampler ( ) ) )
{
// We render first the opaque object as opaque alpha tested are more costly to render and could be reject by early-z (but not Hi-z as it is disable with clip instruction)
// This is handled automatically with the RenderQueue value (OpaqueAlphaTested have a different value and thus are sorted after Opaque)
RenderOpaqueRenderList ( cull , c amera, renderContext , cmd , m_DepthOnlyAndDepthForwardOnlyPassNames , 0 , HDRenderQueue . k_RenderQueue_AllOpaque ) ;
RenderOpaqueRenderList ( cull , hdC amera, renderContext , cmd , m_DepthOnlyAndDepthForwardOnlyPassNames , 0 , HDRenderQueue . k_RenderQueue_AllOpaque ) ;
RenderOpaqueRenderList ( cull , c amera, renderContext , cmd , m_DepthForwardOnlyPassNames , 0 , HDRenderQueue . k_RenderQueue_AllOpaque ) ;
RenderOpaqueRenderList ( cull , hdC amera, renderContext , cmd , m_DepthForwardOnlyPassNames , 0 , HDRenderQueue . k_RenderQueue_AllOpaque ) ;
RenderOpaqueRenderList ( cull , c amera, renderContext , cmd , m_DepthOnlyPassNames , 0 , renderQueueRange ) ;
RenderOpaqueRenderList ( cull , hdC amera, renderContext , cmd , m_DepthOnlyPassNames , 0 , renderQueueRange ) ;
if ( m_F rameSettings. enableTransparentPrepass )
if ( hdCamera . f rameSettings. enableTransparentPrepass )
RenderTransparentRenderList ( cull , c amera, renderContext , cmd , m_TransparentDepthPrepassNames ) ;
RenderTransparentRenderList ( cull , hdC amera, renderContext , cmd , m_TransparentDepthPrepassNames ) ;
}
}
}
void RenderGBuffer ( CullResults cull , HDCamera hdCamera , bool enableShadowMask , ScriptableRenderContext renderContext , CommandBuffer cmd )
{
if ( m_FrameSettings . enableForwardRenderingOnly )
if ( hdCamera . frameSettings . enableForwardRenderingOnly )
var camera = hdCamera . camera ;
RenderOpaqueRenderList ( cull , camera , renderContext , cmd , HDShaderPassNames . s_GBufferName , m_currentRendererConfigurationBakedLighting , HDRenderQueue . k_RenderQueue_AllOpaque ) ;
RenderOpaqueRenderList ( cull , hdCamera , renderContext , cmd , HDShaderPassNames . s_GBufferName , m_currentRendererConfigurationBakedLighting , HDRenderQueue . k_RenderQueue_AllOpaque ) ;
void RenderDBuffer ( HDCamera camera , CommandBuffer cmd )
void RenderDBuffer ( HDCamera hdCamera , CommandBuffer cmd )
if ( ! m_FrameSettings . enableDBuffer )
if ( ! hdCamera . frameSettings . enableDBuffer )
return ;
using ( new ProfilingSample ( cmd , "DBufferRender" , CustomSamplerId . DBufferRender . GetSampler ( ) ) )
// Depth texture is now ready, bind it.
cmd . SetGlobalTexture ( HDShaderIDs . _Main DepthTexture , GetDepthTexture ( ) ) ;
m_DbufferManager . ClearTargets ( cmd , c amera) ;
HDUtils . SetRenderTarget ( cmd , c amera, m_DbufferManager . GetBuffersRTI ( ) , m_CameraDepthStencilBuffer ) ; // do not clear anymore
cmd . SetGlobalTexture ( HDShaderIDs . _Camera DepthTexture , GetDepthTexture ( ) ) ;
m_DbufferManager . ClearTargets ( cmd , hdC amera) ;
HDUtils . SetRenderTarget ( cmd , hdC amera, m_DbufferManager . GetBuffersRTI ( ) , m_CameraDepthStencilBuffer ) ; // do not clear anymore
m_DbufferManager . SetHTile ( m_DbufferManager . bufferCount , cmd ) ;
DecalSystem . instance . RenderIntoDBuffer ( cmd ) ;
m_DbufferManager . UnSetHTile ( cmd ) ;
{
using ( new ProfilingSample ( cmd , "DisplayDebug ViewMaterial" , CustomSamplerId . DisplayDebugViewMaterial . GetSampler ( ) ) )
{
if ( m_CurrentDebugDisplaySettings . materialDebugSettings . IsDebugGBufferEnabled ( ) & & ! m_F rameSettings. enableForwardRenderingOnly )
if ( m_CurrentDebugDisplaySettings . materialDebugSettings . IsDebugGBufferEnabled ( ) & & ! hdCamera . f rameSettings. enableForwardRenderingOnly )
{
using ( new ProfilingSample ( cmd , "DebugViewMaterialGBuffer" , CustomSamplerId . DebugViewMaterialGBuffer . GetSampler ( ) ) )
{
HDUtils . SetRenderTarget ( cmd , hdCamera , m_CameraColorBuffer , m_CameraDepthStencilBuffer , ClearFlag . All , CoreUtils . clearColorAllBlack ) ;
// Render Opaque forward
RenderOpaqueRenderList ( cull , hdCamera . camera , renderContext , cmd , m_AllForwardOpaquePassNames , m_currentRendererConfigurationBakedLighting , stateBlock : m_DepthStateOpaque ) ;
RenderOpaqueRenderList ( cull , hdCamera , renderContext , cmd , m_AllForwardOpaquePassNames , m_currentRendererConfigurationBakedLighting , stateBlock : m_DepthStateOpaque ) ;
RenderTransparentRenderList ( cull , hdCamera . camera , renderContext , cmd , m_AllTransparentPassNames , m_currentRendererConfigurationBakedLighting , stateBlock : m_DepthStateOpaque ) ;
RenderTransparentRenderList ( cull , hdCamera , renderContext , cmd , m_AllTransparentPassNames , m_currentRendererConfigurationBakedLighting , stateBlock : m_DepthStateOpaque ) ;
}
}
var camera = hdCamera . camera ;
// Apply SSAO from PostProcessLayer
if ( m_F rameSettings. enableSSAO & & postProcessLayer ! = null & & postProcessLayer . enabled )
if ( hdCamera . f rameSettings. enableSSAO & & postProcessLayer ! = null & & postProcessLayer . enabled )
{
var settings = postProcessLayer . GetSettings < AmbientOcclusion > ( ) ;
cmd . SetGlobalTexture ( HDShaderIDs . _AmbientOcclusionTexture , m_AmbientOcclusionBuffer ) ;
cmd . SetGlobalVector ( HDShaderIDs . _AmbientOcclusionParam , new Vector4 ( settings . color . value . r , settings . color . value . g , settings . color . value . b , settings . directLightingStrength . value ) ) ;
PushFullScreenDebugTexture ( cmd , m_AmbientOcclusionBuffer , hdCamera , FullScreenDebugMode . SSAO ) ;
PushFullScreenDebugTexture ( hdCamera , cmd , m_AmbientOcclusionBuffer , FullScreenDebugMode . SSAO ) ;
return ;
}
}
void RenderDeferredLighting ( HDCamera hdCamera , CommandBuffer cmd )
{
if ( m_F rameSettings. enableForwardRenderingOnly )
if ( hdCamera . f rameSettings. enableForwardRenderingOnly )
return ;
m_MRTCache2 [ 0 ] = m_CameraColorBuffer ;
var options = new LightLoop . LightingPassOptions ( ) ;
if ( m_F rameSettings. enableSubsurfaceScattering )
if ( hdCamera . f rameSettings. enableSubsurfaceScattering )
{
// Output split lighting for materials asking for it (masked in the stencil buffer)
options . outputSplitLighting = true ;
if ( pass = = ForwardPass . Opaque )
{
// In case of forward SSS we will bind all the required target. It is up to the shader to write into it or not.
if ( m_F rameSettings. enableSubsurfaceScattering )
if ( hdCamera . f rameSettings. enableSubsurfaceScattering )
{
RenderTargetIdentifier [ ] m_MRTWithSSS =
new RenderTargetIdentifier [ 2 + m_SSSBufferManager . sssBufferCount ] ;
HDShaderPassNames . s_ForwardOnlyName ;
m_ForwardAndForwardOnlyPassNames [ 1 ] = HDShaderPassNames . s_ForwardName ;
var passNames = m_F rameSettings. enableForwardRenderingOnly
var passNames = hdCamera . f rameSettings. enableForwardRenderingOnly
? m_ForwardAndForwardOnlyPassNames
: m_ForwardOnlyPassNames ;
var debugSSTThisPass = debugScreenSpaceTracing & & ( m_CurrentDebugDisplaySettings . lightingDebugSettings . debugLightingMode = = DebugLightingMode . ScreenSpaceTracingReflection ) ;
cmd . SetRandomWriteTarget ( 7 , m_DebugScreenSpaceTracingData ) ;
}
RenderOpaqueRenderList ( cullResults , c amera, renderContext , cmd , passNames , m_currentRendererConfigurationBakedLighting ) ;
RenderOpaqueRenderList ( cullResults , hdC amera, renderContext , cmd , passNames , m_currentRendererConfigurationBakedLighting ) ;
if ( debugSSTThisPass )
cmd . ClearRandomWriteTargets ( ) ;
}
if ( ( m_FrameSettings . enableDBuffer ) & & ( DecalSystem . m_DecalsVisibleThisFrame > 0 ) ) // enable d-buffer flag value is being interpreted more like enable decals in general now that we have clustered
if ( ( hdCamera . frameSettings . enableDBuffer ) & & ( DecalSystem . m_DecalsVisibleThisFrame > 0 ) ) // enable d-buffer flag value is being interpreted more like enable decals in general now that we have clustered
{
DecalSystem . instance . SetAtlas ( cmd ) ; // for clustered decals
}
cmd . SetGlobalBuffer ( HDShaderIDs . _DebugScreenSpaceTracingData , m_DebugScreenSpaceTracingData ) ;
cmd . SetRandomWriteTarget ( 7 , m_DebugScreenSpaceTracingData ) ;
}
RenderTransparentRenderList ( cullResults , c amera, renderContext , cmd , m_AllTransparentPassNames , m_currentRendererConfigurationBakedLighting , pass = = ForwardPass . PreRefraction ? HDRenderQueue . k_RenderQueue_PreRefraction : HDRenderQueue . k_RenderQueue_Transparent ) ;
RenderTransparentRenderList ( cullResults , hdC amera, renderContext , cmd , m_AllTransparentPassNames , m_currentRendererConfigurationBakedLighting , pass = = ForwardPass . PreRefraction ? HDRenderQueue . k_RenderQueue_PreRefraction : HDRenderQueue . k_RenderQueue_Transparent ) ;
if ( debugSSTThisPass )
cmd . ClearRandomWriteTargets ( ) ;
}
if ( pass = = ForwardPass . Opaque )
{
RenderOpaqueRenderList ( cullResults , hdCamera . camera , renderContext , cmd , m_ForwardErrorPassNames , 0 , null , null , m_ErrorMaterial ) ;
RenderOpaqueRenderList ( cullResults , hdCamera , renderContext , cmd , m_ForwardErrorPassNames , 0 , null , null , m_ErrorMaterial ) ;
RenderTransparentRenderList ( cullResults , hdCamera . camera , renderContext , cmd , m_ForwardErrorPassNames , 0 , pass = = ForwardPass . PreRefraction ? HDRenderQueue . k_RenderQueue_PreRefraction : HDRenderQueue . k_RenderQueue_Transparent , null , m_ErrorMaterial ) ;
RenderTransparentRenderList ( cullResults , hdCamera , renderContext , cmd , m_ForwardErrorPassNames , 0 , pass = = ForwardPass . PreRefraction ? HDRenderQueue . k_RenderQueue_PreRefraction : HDRenderQueue . k_RenderQueue_Transparent , null , m_ErrorMaterial ) ;
}
}
}
if ( ! m_FrameSettings . enableTransparentPostpass )
if ( ! hdCamera . frameSettings . enableTransparentPostpass )
RenderTransparentRenderList ( cullResults , hdCamera . camera , renderContext , cmd , m_TransparentDepthPostpassNames ) ;
RenderTransparentRenderList ( cullResults , hdCamera , renderContext , cmd , m_TransparentDepthPostpassNames ) ;
void RenderObjectsVelocity ( CullResults cullResults , HDCamera hdcamera , ScriptableRenderContext renderContext , CommandBuffer cmd )
void RenderObjectsVelocity ( CullResults cullResults , HDCamera hdCamera , ScriptableRenderContext renderContext , CommandBuffer cmd )
if ( ! m_FrameSettings . enableMotionVectors | | ! m_FrameSettings . enableObjectMotionVectors )
if ( ! hdCamera . frameSettings . enableMotionVectors | | ! hdCamera . frameSettings . enableObjectMotionVectors )
return ;
using ( new ProfilingSample ( cmd , "Objects Velocity" , CustomSamplerId . ObjectsVelocity . GetSampler ( ) ) )
hdcamera . camera . depthTextureMode | = DepthTextureMode . MotionVectors | DepthTextureMode . Depth ;
hdCamera . camera . depthTextureMode | = DepthTextureMode . MotionVectors | DepthTextureMode . Depth ;
HDUtils . SetRenderTarget ( cmd , hdcamera , m_VelocityBuffer , m_CameraDepthStencilBuffer ) ;
RenderOpaqueRenderList ( cullResults , hdcamera . camera , renderContext , cmd , HDShaderPassNames . s_MotionVectorsName , RendererConfiguration . PerObjectMotionVectors ) ;
HDUtils . SetRenderTarget ( cmd , hdCamera , m_VelocityBuffer , m_CameraDepthStencilBuffer ) ;
RenderOpaqueRenderList ( cullResults , hdCamera , renderContext , cmd , HDShaderPassNames . s_MotionVectorsName , RendererConfiguration . PerObjectMotionVectors ) ;
void RenderCameraVelocity ( CullResults cullResults , HDCamera hdcamera , ScriptableRenderContext renderContext , CommandBuffer cmd )
void RenderCameraVelocity ( CullResults cullResults , HDCamera hdCamera , ScriptableRenderContext renderContext , CommandBuffer cmd )
if ( ! m_FrameSettings . enableMotionVectors )
if ( ! hdCamera . frameSettings . enableMotionVectors )
return ;
using ( new ProfilingSample ( cmd , "Camera Velocity" , CustomSamplerId . CameraVelocity . GetSampler ( ) ) )
hdcamera . camera . depthTextureMode | = DepthTextureMode . MotionVectors | DepthTextureMode . Depth ;
hdCamera . camera . depthTextureMode | = DepthTextureMode . MotionVectors | DepthTextureMode . Depth ;
HDUtils . DrawFullScreen ( cmd , hdcamera , m_CameraMotionVectorsMaterial , m_VelocityBuffer , m_CameraDepthStencilBuffer , null , 0 ) ;
PushFullScreenDebugTexture ( cmd , m_VelocityBuffer , hdcamera , FullScreenDebugMode . MotionVectors ) ;
HDUtils . DrawFullScreen ( cmd , hdCamera , m_CameraMotionVectorsMaterial , m_VelocityBuffer , m_CameraDepthStencilBuffer , null , 0 ) ;
PushFullScreenDebugTexture ( hdCamera , cmd , m_VelocityBuffer , FullScreenDebugMode . MotionVectors ) ;
}
}
{
if ( ! m_F rameSettings. enableRoughRefraction )
if ( ! hdCamera . f rameSettings. enableRoughRefraction )
if ( ! m_F rameSettings. enableDistortion & & ! m_F rameSettings. enablePostprocess & & ! m_F rameSettings. enableSSR )
if ( ! hdCamera . f rameSettings. enableDistortion & & ! hdCamera . f rameSettings. enablePostprocess & & ! hdCamera . f rameSettings. enableSSR )
return ;
}
m_BufferPyramid . RenderColorPyramid ( hdCamera , cmd , renderContext , m_CameraColorBuffer , cameraRT ) ;
Vector2 pyramidScale = m_BufferPyramid . GetPyramidToScreenScale ( hdCamera , cameraRT ) ;
PushFullScreenDebugTextureMip ( cmd , cameraRT , m_BufferPyramid . GetPyramidLodCount ( new Vector2Int ( hdCamera . actualWidth , hdCamera . actualHeight ) ) , new Vector4 ( pyramidScale . x , pyramidScale . y , 0.0f , 0.0f ) , hdCamera , isPreRefraction ? FullScreenDebugMode . PreRefractionColorPyramid : FullScreenDebugMode . FinalColorPyramid ) ;
PushFullScreenDebugTextureMip ( hdCamera , cmd , cameraRT , m_BufferPyramid . GetPyramidLodCount ( new Vector2Int ( hdCamera . actualWidth , hdCamera . actualHeight ) ) , new Vector4 ( pyramidScale . x , pyramidScale . y , 0.0f , 0.0f ) , isPreRefraction ? FullScreenDebugMode . PreRefractionColorPyramid : FullScreenDebugMode . FinalColorPyramid ) ;
if ( ! m_F rameSettings. enableRoughRefraction )
if ( ! hdCamera . f rameSettings. enableRoughRefraction )
return ;
var cameraRT = hdCamera . GetCurrentFrameRT ( ( int ) HDCameraFrameHistoryType . DepthPyramid )
m_BufferPyramid . RenderDepthPyramid ( hdCamera , cmd , renderContext , GetDepthTexture ( ) , cameraRT ) ;
Vector2 pyramidScale = m_BufferPyramid . GetPyramidToScreenScale ( hdCamera , cameraRT ) ;
PushFullScreenDebugTextureMip ( cmd , cameraRT , m_BufferPyramid . GetPyramidLodCount ( new Vector2Int ( hdCamera . actualWidth , hdCamera . actualHeight ) ) , new Vector4 ( pyramidScale . x , pyramidScale . y , 0.0f , 0.0f ) , hdCamera , debugMode ) ;
PushFullScreenDebugTextureMip ( hdCamera , cmd , cameraRT , m_BufferPyramid . GetPyramidLodCount ( new Vector2Int ( hdCamera . actualWidth , hdCamera . actualHeight ) ) , new Vector4 ( pyramidScale . x , pyramidScale . y , 0.0f , 0.0f ) , debugMode ) ;
}
void RenderPostProcess ( HDCamera hdcamera , CommandBuffer cmd , PostProcessLayer layer )
}
// TODO TEMP: Not sure I want to keep this special case. Gotta see how to get rid of it (not sure it will work correctly for non-full viewports.
public void PushColorPickerDebugTexture ( CommandBuffer cmd , RenderTargetIdentifier textureID , HDCamera hdCamera )
public void PushColorPickerDebugTexture ( HDCamera hdCamera , CommandBuffer cmd , RenderTargetIdentifier textureID )
{
if ( m_CurrentDebugDisplaySettings . colorPickerDebugSettings . colorPickerMode ! = ColorPickerDebugMode . None )
{
}
}
public void PushFullScreenDebugTexture ( CommandBuffer cmd , RTHandleSystem . RTHandle textureID , HDCamera hdCamera , FullScreenDebugMode debugMode )
public void PushFullScreenDebugTexture ( HDCamera hdCamera , CommandBuffer cmd , RTHandleSystem . RTHandle textureID , FullScreenDebugMode debugMode )
{
if ( debugMode = = m_CurrentDebugDisplaySettings . fullScreenDebugMode )
{
}
void PushFullScreenDebugTextureMip ( CommandBuffer cmd , RTHandleSystem . RTHandle texture , int lodCount , Vector4 scaleBias , HDCamera hdCamera , FullScreenDebugMode debugMode )
void PushFullScreenDebugTextureMip ( HDCamera hdCamera , CommandBuffer cmd , RTHandleSystem . RTHandle texture , int lodCount , Vector4 scaleBias , FullScreenDebugMode debugMode )
{
if ( debugMode = = m_CurrentDebugDisplaySettings . fullScreenDebugMode )
{
m_DebugFullScreen . SetTexture ( HDShaderIDs . _DepthPyramidTexture , hdCamera . GetPreviousFrameRT ( ( int ) HDCameraFrameHistoryType . DepthPyramid ) ) ;
HDUtils . DrawFullScreen ( cmd , hdCamera , m_DebugFullScreen , ( RenderTargetIdentifier ) BuiltinRenderTextureType . CameraTarget ) ;
PushColorPickerDebugTexture ( cmd , ( RenderTargetIdentifier ) BuiltinRenderTextureType . CameraTarget , hdCamera ) ;
PushColorPickerDebugTexture ( hdCamera , cmd , ( RenderTargetIdentifier ) BuiltinRenderTextureType . CameraTarget ) ;
}
// Then overlays
// TODO: 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.
// Clear GBuffers
if ( ! m_F rameSettings. enableForwardRenderingOnly )
if ( ! hdCamera . f rameSettings. enableForwardRenderingOnly )
{
using ( new ProfilingSample ( cmd , "Clear GBuffer" , CustomSamplerId . ClearGBuffer . GetSampler ( ) ) )
{
}
}
void StartStereoRendering ( ScriptableRenderContext renderContext , Camera cam )
void StartStereoRendering ( ScriptableRenderContext renderContext , HDCamera hdCamera )
if ( m_F rameSettings. enableStereo )
renderContext . StartMultiEye ( cam ) ;
if ( hdCamera . f rameSettings. enableStereo )
renderContext . StartMultiEye ( hdCamera . camera ) ;
void StopStereoRendering ( ScriptableRenderContext renderContext , Camera cam )
void StopStereoRendering ( ScriptableRenderContext renderContext , HDCamera hdCamera )
if ( m_F rameSettings. enableStereo )
renderContext . StopMultiEye ( cam ) ;
if ( hdCamera . f rameSettings. enableStereo )
renderContext . StopMultiEye ( hdCamera . camera ) ;
}
}
}