using UnityEngine.Rendering ;
using System ;
using System.Diagnostics ;
using System.Linq ;
using UnityEngine.Rendering.PostProcessing ;
using UnityEngine.Experimental.Rendering.HDPipeline.TilePass ;
[Serializable]
public class RenderingSettings
{
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 useDepthPrepassWithDeferredRendering = false ;
public bool renderAlphaTestOnlyInDeferredPrepass = false ;
public bool useForwardRenderingOnly ; // TODO: Currently there is no way to strip the extra forward shaders generated by the shaders compiler, so we can switch dynamically.
public bool useDepthPrepassWithDeferredRendering ;
public bool renderAlphaTestOnlyInDeferredPrepass ;
// We have to fall back to forward-only rendering when scene view is using wireframe rendering mode --
// as rendering everything in wireframe + deferred do not play well together
public class GBufferManager
{
public const int MaxGbuffer = 8 ;
public const int k_MaxGbuffer = 8 ;
public int gbufferCount { get ; set ; }
int [ ] m_IDs = new int [ k_MaxGbuffer ] ;
RenderTargetIdentifier [ ] m_ColorMRTs ;
RenderTargetIdentifier [ ] m_RTIDs = new RenderTargetIdentifier [ k_MaxGbuffer ] ;
RenderTextureFormat [ ] m_Formats = new RenderTextureFormat [ k_MaxGbuffer ] ;
RenderTextureReadWrite [ ] m_sRGBWrites = new RenderTextureReadWrite [ k_MaxGbuffer ] ;
IDs [ index ] = Shader . PropertyToID ( stringId ) ;
RTIDs [ index ] = new RenderTargetIdentifier ( IDs [ index ] ) ;
formats [ index ] = inFormat ;
sRGBWrites [ index ] = inSRGBWrite ;
m_IDs [ index ] = Shader . PropertyToID ( stringId ) ;
m_RTIDs [ index ] = new RenderTargetIdentifier ( m_IDs [ index ] ) ;
m_Formats [ index ] = inFormat ;
m_sRGBWrites [ index ] = inSRGBWrite ;
}
public void InitGBuffers ( int width , int height , CommandBuffer cmd )
cmd . GetTemporaryRT ( IDs [ index ] , width , height , 0 , FilterMode . Point , formats [ index ] , sRGBWrites [ index ] ) ;
cmd . GetTemporaryRT ( m_IDs [ index ] , width , height , 0 , FilterMode . Point , m_Formats [ index ] , m_sRGBWrites [ index ] ) ;
private RenderTargetIdentifier [ ] m_ColorMRTs ;
public RenderTargetIdentifier [ ] GetGBuffers ( )
{
if ( m_ColorMRTs = = null | | m_ColorMRTs . Length ! = gbufferCount )
{
m_ColorMRTs [ index ] = RTIDs [ index ] ;
m_ColorMRTs [ index ] = m_RTIDs [ 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 partial class HDRenderPipeline : RenderPipeline
readonly RenderPipelineMaterial m_DeferredMaterial ;
readonly List < RenderPipelineMaterial > m_MaterialList = new List < RenderPipelineMaterial > ( ) ;
readonly GBufferManager m_g bufferManager = new GBufferManager ( ) ;
readonly GBufferManager m_G bufferManager = new GBufferManager ( ) ;
Material m_CopyStencilForSplitLighting ;
Material m_CopyStencilForRegularLighting ;
readonly RenderTargetIdentifier m_DeferredShadowBufferRT ;
private RenderTexture m_CameraDepthStencilBuffer = null ;
private RenderTexture m_CameraDepthBufferCopy = null ;
private RenderTexture m_CameraStencilBufferCopy = null ;
private RenderTexture m_HTile = null ; // If the hardware does not expose it, we compute our own, optimized to only contain the SSS bit
RenderTexture m_CameraDepthStencilBuffer ;
RenderTexture m_CameraDepthBufferCopy ;
RenderTexture m_CameraStencilBufferCopy ;
RenderTexture m_HTile ; // If the hardware does not expose it, we compute our own, optimized to only contain the SSS bit
private RenderTargetIdentifier m_CameraDepthStencilBufferRT ;
private RenderTargetIdentifier m_CameraDepthBufferCopyRT ;
private RenderTargetIdentifier m_CameraStencilBufferCopyRT ;
private RenderTargetIdentifier m_HTileRT ;
RenderTargetIdentifier m_CameraDepthStencilBufferRT ;
RenderTargetIdentifier m_CameraDepthBufferCopyRT ;
RenderTargetIdentifier m_CameraStencilBufferCopyRT ;
RenderTargetIdentifier m_HTileRT ;
// The pass "SRPDefaultUnlit" is a fallback to legacy unlit rendering and is required to support unity 2d + unity UI that render in the scene.
ShaderPassName [ ] m_ForwardPassNames = { new ShaderPassName ( ) , HDShaderPassNames . s_SRPDefaultUnlitName } ;
ShaderPassName [ ] m_ForwardErrorPassNames = { HDShaderPassNames . s_AlwaysName , HDShaderPassNames . s_ForwardBaseName , HDShaderPassNames . s_DeferredName , HDShaderPassNames . s_PrepassBaseName , HDShaderPassNames . s_VertexName , HDShaderPassNames . s_VertexLMRGBMName , HDShaderPassNames . s_VertexLMName } ;
ShaderPassName [ ] m_SinglePassName = new ShaderPassName [ 1 ] ;
RenderTargetIdentifier [ ] m_MRTCache2 = new RenderTargetIdentifier [ 2 ] ;
// Post-processing context and screen-space effects (recycled on every frame to avoid GC alloc)
readonly PostProcessRenderContext m_PostProcessContext ;
MaterialPropertyBlock m_SharedPropertyBlock = new MaterialPropertyBlock ( ) ;
DebugDisplaySettings m_DebugDisplaySettings = new DebugDisplaySettings ( ) ;
static DebugDisplaySettings s_NeutralDebugDisplaySettings = new DebugDisplaySettings ( ) ;
DebugDisplaySettings m_CurrentDebugDisplaySettings = null ;
DebugDisplaySettings m_CurrentDebugDisplaySettings ;
private int m_DebugFullScreenTempRT ;
private bool m_FullScreenDebugPushed = false ;
int m_DebugFullScreenTempRT ;
bool m_FullScreenDebugPushed ;
public SubsurfaceScatteringSettings sssSettings
{
private CommonSettings . Settings m_CommonSettings = CommonSettings . Settings . s_Defaultsettings ;
private SkySettings m_SkySettings = null ;
private ScreenSpaceAmbientOcclusionSettings . Settings m_SsaoSettings = ScreenSpaceAmbientOcclusionSettings . Settings . s_Defaultsettings ;
CommonSettings . Settings m_CommonSettings = CommonSettings . Settings . s_Defaultsettings ;
SkySettings m_SkySettings = null ;
ScreenSpaceAmbientOcclusionSettings . Settings m_SsaoSettings = ScreenSpaceAmbientOcclusionSettings . Settings . s_Defaultsettings ;
public CommonSettings . Settings commonSettingsToUse
{
m_GPUCopy = new GPUCopy ( asset . renderPipelineResources . copyChannelCS ) ;
// Scan material list and assign it
m_MaterialList = CoreUtils . GetRenderPipelineMaterialList ( ) ;
m_MaterialList = HDUtils . GetRenderPipelineMaterialList ( ) ;
foreach ( RenderPipelineMaterial material in m_MaterialList )
foreach ( var material in m_MaterialList )
{
}
}
// TODO: Handle the case of no Gbuffer material
InitializeDebugMaterials ( ) ;
// Init Gbuffer description
m_g bufferManager . gbufferCount = m_DeferredMaterial . GetMaterialGBufferCount ( ) ;
RenderTextureFormat [ ] RT Format;
RenderTextureReadWrite [ ] RT ReadWrite;
m_DeferredMaterial . GetMaterialGBufferDescription ( out RTFormat , out RT ReadWrite) ;
m_G bufferManager . gbufferCount = m_DeferredMaterial . GetMaterialGBufferCount ( ) ;
RenderTextureFormat [ ] rt Format;
RenderTextureReadWrite [ ] rt ReadWrite;
m_DeferredMaterial . GetMaterialGBufferDescription ( out rtFormat , out rt ReadWrite) ;
for ( int gbufferIndex = 0 ; gbufferIndex < m_g bufferManager . gbufferCount ; + + gbufferIndex )
for ( int gbufferIndex = 0 ; gbufferIndex < m_G bufferManager . gbufferCount ; + + gbufferIndex )
m_g bufferManager . SetBufferDescription ( gbufferIndex , "_GBufferTexture" + gbufferIndex , RT Format[ gbufferIndex ] , RT ReadWrite[ gbufferIndex ] ) ;
m_G bufferManager . SetBufferDescription ( gbufferIndex , "_GBufferTexture" + gbufferIndex , rt Format[ gbufferIndex ] , rt ReadWrite[ gbufferIndex ] ) ;
}
m_VelocityBuffer = HDShaderIDs . _VelocityTexture ;
m_gbufferManager . SetBufferDescription ( m_gbufferManager . gbufferCount , "_VelocityTexture" , Builtin . GetVelocityBufferFormat ( ) , Builtin . GetVelocityBufferReadWrite ( ) ) ;
m_gbufferManager . gbufferCount + + ;
m_GbufferManager . SetBufferDescription ( m_GbufferManager . gbufferCount , "_VelocityTexture" , Builtin . GetVelocityBufferFormat ( ) , Builtin . GetVelocityBufferReadWrite ( ) ) ;
m_GbufferManager . gbufferCount + + ;
}
m_VelocityBufferRT = new RenderTargetIdentifier ( m_VelocityBuffer ) ;
void RegisterDebug ( )
{
// These need to be Runtime Only because those values are hold by the HDRenderPipeline asset so if user change them through the editor debug menu they might change the value in the asset without noticing it.
DebugMenuManager . instance . AddDebugItem < bool > ( "HDRP" , "Forward Only" , ( ) = > ( bool ) m_Asset . renderingSettings . useForwardRenderingOnly , ( value ) = > m_Asset . renderingSettings . useForwardRenderingOnly = ( bool ) value , DebugItemFlag . RuntimeOnly ) ;
DebugMenuManager . instance . AddDebugItem < bool > ( "HDRP" , "Deferred Depth Prepass" , ( ) = > ( bool ) m_Asset . renderingSettings . useDepthPrepassWithDeferredRendering , ( value ) = > m_Asset . renderingSettings . useDepthPrepassWithDeferredRendering = ( bool ) value , DebugItemFlag . RuntimeOnly ) ;
DebugMenuManager . instance . AddDebugItem < bool > ( "HDRP" , "Deferred Depth Prepass ATest Only" , ( ) = > ( bool ) m_Asset . renderingSettings . renderAlphaTestOnlyInDeferredPrepass , ( value ) = > m_Asset . renderingSettings . renderAlphaTestOnlyInDeferredPrepass = ( bool ) value , DebugItemFlag . RuntimeOnly ) ;
DebugMenuManager . instance . AddDebugItem < bool > ( "HDRP" , "Forward Only" , ( ) = > m_Asset . renderingSettings . useForwardRenderingOnly , ( value ) = > m_Asset . renderingSettings . useForwardRenderingOnly = ( bool ) value , DebugItemFlag . RuntimeOnly ) ;
DebugMenuManager . instance . AddDebugItem < bool > ( "HDRP" , "Deferred Depth Prepass" , ( ) = > m_Asset . renderingSettings . useDepthPrepassWithDeferredRendering , ( value ) = > m_Asset . renderingSettings . useDepthPrepassWithDeferredRendering = ( bool ) value , DebugItemFlag . RuntimeOnly ) ;
DebugMenuManager . instance . AddDebugItem < bool > ( "HDRP" , "Deferred Depth Prepass ATest Only" , ( ) = > m_Asset . renderingSettings . renderAlphaTestOnlyInDeferredPrepass , ( value ) = > m_Asset . renderingSettings . renderAlphaTestOnlyInDeferredPrepass = ( bool ) value , DebugItemFlag . RuntimeOnly ) ;
DebugMenuManager . instance . AddDebugItem < bool > ( "HDRP" , "Enable Tile/Cluster" , ( ) = > ( bool ) m_Asset . tileSettings . enableTileAndCluster , ( value ) = > m_Asset . tileSettings . enableTileAndCluster = ( bool ) value , DebugItemFlag . RuntimeOnly ) ;
DebugMenuManager . instance . AddDebugItem < bool > ( "HDRP" , "Enable Big Tile" , ( ) = > ( bool ) m_Asset . tileSettings . enableBigTilePrepass , ( value ) = > m_Asset . tileSettings . enableBigTilePrepass = ( bool ) value , DebugItemFlag . RuntimeOnly ) ;
DebugMenuManager . instance . AddDebugItem < bool > ( "HDRP" , "Enable Cluster" , ( ) = > ( bool ) m_Asset . tileSettings . enableClustered , ( value ) = > m_Asset . tileSettings . enableClustered = ( bool ) value , DebugItemFlag . RuntimeOnly ) ;
DebugMenuManager . instance . AddDebugItem < bool > ( "HDRP" , "Enable Compute Lighting" , ( ) = > ( bool ) m_Asset . tileSettings . enableComputeLightEvaluation , ( value ) = > m_Asset . tileSettings . enableComputeLightEvaluation = ( bool ) value , DebugItemFlag . RuntimeOnly ) ;
DebugMenuManager . instance . AddDebugItem < bool > ( "HDRP" , "Enable Light Classification" , ( ) = > ( bool ) m_Asset . tileSettings . enableComputeLightVariants , ( value ) = > m_Asset . tileSettings . enableComputeLightVariants = ( bool ) value , DebugItemFlag . RuntimeOnly ) ;
DebugMenuManager . instance . AddDebugItem < bool > ( "HDRP" , "Enable Material Classification" , ( ) = > ( bool ) m_Asset . tileSettings . enableComputeMaterialVariants , ( value ) = > m_Asset . tileSettings . enableComputeMaterialVariants = ( bool ) value , DebugItemFlag . RuntimeOnly ) ;
DebugMenuManager . instance . AddDebugItem < bool > ( "HDRP" , "Enable Tile/Cluster" , ( ) = > m_Asset . tileSettings . enableTileAndCluster , ( value ) = > m_Asset . tileSettings . enableTileAndCluster = ( bool ) value , DebugItemFlag . RuntimeOnly ) ;
DebugMenuManager . instance . AddDebugItem < bool > ( "HDRP" , "Enable Big Tile" , ( ) = > m_Asset . tileSettings . enableBigTilePrepass , ( value ) = > m_Asset . tileSettings . enableBigTilePrepass = ( bool ) value , DebugItemFlag . RuntimeOnly ) ;
DebugMenuManager . instance . AddDebugItem < bool > ( "HDRP" , "Enable Cluster" , ( ) = > m_Asset . tileSettings . enableClustered , ( value ) = > m_Asset . tileSettings . enableClustered = ( bool ) value , DebugItemFlag . RuntimeOnly ) ;
DebugMenuManager . instance . AddDebugItem < bool > ( "HDRP" , "Enable Compute Lighting" , ( ) = > m_Asset . tileSettings . enableComputeLightEvaluation , ( value ) = > m_Asset . tileSettings . enableComputeLightEvaluation = ( bool ) value , DebugItemFlag . RuntimeOnly ) ;
DebugMenuManager . instance . AddDebugItem < bool > ( "HDRP" , "Enable Light Classification" , ( ) = > m_Asset . tileSettings . enableComputeLightVariants , ( value ) = > m_Asset . tileSettings . enableComputeLightVariants = ( bool ) value , DebugItemFlag . RuntimeOnly ) ;
DebugMenuManager . instance . AddDebugItem < bool > ( "HDRP" , "Enable Material Classification" , ( ) = > m_Asset . tileSettings . enableComputeMaterialVariants , ( value ) = > m_Asset . tileSettings . enableComputeMaterialVariants = ( bool ) value , DebugItemFlag . RuntimeOnly ) ;
}
void InitializeDebugMaterials ( )
void InitializeRenderStateBlocks ( )
{
m_DepthStateOpaque . depthState = new DepthState ( true , CompareFunction . LessEqual ) ;
m_DepthStateOpaque . mask = RenderStateMask . Depth ;
m_DepthStateOpaque = new RenderStateBlock
{
depthState = new DepthState ( true , CompareFunction . LessEqual ) ,
mask = RenderStateMask . Depth
} ;
m_DepthStateOpaqueWithPrepass . depthState = new DepthState ( false , CompareFunction . Equal ) ;
m_DepthStateOpaqueWithPrepass . mask = RenderStateMask . Depth ;
m_DepthStateOpaqueWithPrepass = new RenderStateBlock
{
depthState = new DepthState ( false , CompareFunction . Equal ) ,
mask = RenderStateMask . Depth
} ;
}
public void OnSceneLoad ( )
}
#if UNITY_EDITOR
private static readonly SupportedRenderingFeatures s_NeededFeatures = new SupportedRenderingFeatures ( )
static readonly SupportedRenderingFeatures s_NeededFeatures = new SupportedRenderingFeatures ( )
{
reflectionProbe = SupportedRenderingFeatures . ReflectionProbe . Rotation
} ;
{
if ( m_CameraDepthStencilBuffer ! = null )
{
}
m_CameraDepthStencilBuffer = new RenderTexture ( camera . pixelWidth , camera . pixelHeight , 2 4 , RenderTextureFormat . Depth ) ;
m_CameraDepthStencilBuffer . filterMode = FilterMode . Point ;
if ( NeedDepthBufferCopy ( ) )
{
if ( m_CameraDepthBufferCopy ! = null )
{
}
m_CameraDepthBufferCopy = new RenderTexture ( camera . pixelWidth , camera . pixelHeight , 2 4 , RenderTextureFormat . Depth ) ;
m_CameraDepthBufferCopy . filterMode = FilterMode . Point ;
m_CameraDepthBufferCopy . Create ( ) ;
if ( NeedStencilBufferCopy ( ) )
{
if ( m_CameraStencilBufferCopy ! = null )
{
}
m_CameraStencilBufferCopy = new RenderTexture ( camera . pixelWidth , camera . pixelHeight , 0 , RenderTextureFormat . R8 , RenderTextureReadWrite . Linear ) ; // DXGI_FORMAT_R8_UINT is not supported by Unity
m_CameraStencilBufferCopy . filterMode = FilterMode . Point ;
m_CameraStencilBufferCopy . Create ( ) ;
if ( NeedHTileCopy ( ) )
{
if ( m_HTile ! = null )
{
}
// We use 8x8 tiles in order to match the native GCN HTile as closely as possible.
m_HTile = new RenderTexture ( ( camera . pixelWidth + 7 ) / 8 , ( camera . pixelHeight + 7 ) / 8 , 0 , RenderTextureFormat . R8 , RenderTextureReadWrite . Linear ) ; // DXGI_FORMAT_R8_UINT is not supported by Unity
m_HTile . filterMode = FilterMode . Point ;
bool resolutionChanged = camera . pixelWidth ! = m_CurrentWidth | | camera . pixelHeight ! = m_CurrentHeight ;
if ( resolutionChanged | | m_CameraDepthStencilBuffer = = null )
{
}
{
}
{
}
// update recorded window resolution
m_CurrentWidth = camera . pixelWidth ;
// Broadcast SSS parameters to all shaders.
Shader . SetGlobalInt ( HDShaderIDs . _EnableSSSAndTransmission , m_CurrentDebugDisplaySettings . renderingDebugSettings . enableSSSAndTransmission ? 1 : 0 ) ;
Shader . SetGlobalInt ( HDShaderIDs . _TexturingModeFlags , ( int ) sssParameters . texturingModeFlags ) ;
Shader . SetGlobalInt ( HDShaderIDs . _TransmissionFlags , ( int ) sssParameters . transmissionFlags ) ;
Shader . SetGlobalInt ( HDShaderIDs . _TexturingModeFlags , sssParameters . texturingModeFlags ) ;
Shader . SetGlobalInt ( HDShaderIDs . _TransmissionFlags , sssParameters . transmissionFlags ) ;
Shader . SetGlobalInt ( HDShaderIDs . _UseDisneySSS , sssParameters . useDisneySSS ? 1 : 0 ) ;
cmd . SetGlobalVectorArray ( HDShaderIDs . _ThicknessRemaps , sssParameters . thicknessRemaps ) ;
cmd . SetGlobalVectorArray ( HDShaderIDs . _ShapeParams , sssParameters . shapeParams ) ;
return m_HTileRT ;
}
private void CopyDepthBufferIfNeeded ( CommandBuffer cmd )
void CopyDepthBufferIfNeeded ( CommandBuffer cmd )
{
using ( new ProfilingSample ( cmd , NeedDepthBufferCopy ( ) ? "Copy DepthBuffer" : "Set DepthBuffer" ) )
{
}
}
private void PrepareAndBindStencilTexture ( CommandBuffer cmd )
void PrepareAndBindStencilTexture ( CommandBuffer cmd )
{
if ( NeedStencilBufferCopy ( ) )
{
}
// This is the main command buffer used for the frame.
CommandBuffer cmd = CommandBufferPool . Get ( "" ) ;
var cmd = CommandBufferPool . Get ( "" ) ;
m_MaterialList . ForEach ( material = > material . RenderInit ( cmd ) ) ;
foreach ( var material in m_MaterialList )
material . RenderInit ( cmd ) ;
// Do anything we need to do upon a new frame.
m_LightLoop . NewFrame ( ) ;
Camera camera = null ;
foreach ( var cam in cameras )
{
break ;
}
}
renderContext . SetupCameraProperties ( camera ) ;
var postProcessLayer = camera . GetComponent < PostProcessLayer > ( ) ;
HDCamera hdCamera = HDCamera . Get ( camera , postProcessLayer ) ;
var hdCamera = HDCamera . Get ( camera , postProcessLayer ) ;
PushGlobalParams ( hdCamera , cmd , m_Asset . sssSettings ) ;
// TODO: Find a correct place to bind these material textures
using ( new ProfilingSample ( cmd , "Forward" ) )
{
CoreUtils . SetRenderTarget ( cmd , m_CameraColorBufferRT , m_CameraDepthStencilBufferRT , ClearFlag . Color | ClearFlag . Depth ) ;
ShaderPassName [ ] arrayShaderPassName = { HDShaderPassNames . s_ForwardName } ;
RenderOpaqueRenderList ( m_CullResults , camera , renderContext , cmd , arrayShaderPassName ) ;
RenderTransparentRenderList ( m_CullResults , camera , renderContext , cmd , arrayShaderPassName ) ;
RenderOpaqueRenderList ( m_CullResults , camera , renderContext , cmd , HDShaderPassNames . s_ForwardName ) ;
RenderTransparentRenderList ( m_CullResults , camera , renderContext , cmd , HDShaderPassNames . s_ForwardName ) ;
}
renderContext . ExecuteCommandBuffer ( cmd ) ;
renderContext . SetupCameraProperties ( camera ) ; // Need to recall SetupCameraProperties after m_ShadowPass.Render
m_LightLoop . BuildGPULightLists ( camera , cmd , m_CameraDepthStencilBufferRT , GetStencilTexture ( ) ) ;
}
// Don't update the sky environment if we are rendering a cubemap (it should be update already)
if ( camera . cameraType ! = CameraType . Reflection )
// Simple blit
cmd . Blit ( m_CameraColorBufferRT , BuiltinRenderTextureType . CameraTarget ) ;
}
}
else
{
#if UNITY_EDITOR
// bind depth surface for editor grid/gizmo/selection rendering
if ( camera . cameraType = = CameraType . SceneView )
{
}
#endif
renderContext . ExecuteCommandBuffer ( cmd ) ;
CommandBuffer cmd ,
ShaderPassName passName ,
RendererConfiguration rendererConfiguration = 0 ,
RenderQueueRange ? inRenderQueueRange = null ,
RenderQueueRange ? inRenderQueueRange = null ,
RenderOpaqueRenderList ( cull , camera , renderContext , cmd , new ShaderPassName [ ] { passName } , rendererConfiguration , inRenderQueueRange , stateBlock , overrideMaterial ) ;
m_SinglePassName [ 0 ] = passName ;
RenderOpaqueRenderList ( cull , camera , renderContext , cmd , m_SinglePassName , rendererConfiguration , inRenderQueueRange , stateBlock , overrideMaterial ) ;
}
void RenderOpaqueRenderList ( CullResults cull ,
}
if ( overrideMaterial ! = null )
{
}
var filterSettings = new FilterRenderersSettings ( true )
{
renderQueueRange = inRenderQueueRange = = null
? RenderQueueRange . opaque
: inRenderQueueRange . Value
} ;
var filterSettings = new FilterRenderersSettings ( true ) { renderQueueRange = inRenderQueueRange = = null ? RenderQueueRange . opaque : inRenderQueueRange . Value } ;
if ( stateBlock = = null )
renderContext . DrawRenderers ( cull . visibleRenderers , ref drawSettings , filterSettings ) ;
else
void RenderTransparentRenderList ( CullResults cull ,
Camera camera ,
ScriptableRenderContext renderContext ,
CommandBuffer cmd ,
ShaderPassName passName ,
RendererConfiguration rendererConfiguration = 0 ,
RenderStateBlock ? stateBlock = null ,
Material overrideMaterial = null )
void RenderTransparentRenderList ( CullResults cull ,
Camera camera ,
ScriptableRenderContext renderContext ,
CommandBuffer cmd ,
ShaderPassName passName ,
RendererConfiguration rendererConfiguration = 0 ,
RenderStateBlock ? stateBlock = null ,
Material overrideMaterial = null )
RenderTransparentRenderList ( cull , camera , renderContext , cmd , new ShaderPassName [ ] { passName } , rendererConfiguration , stateBlock , overrideMaterial ) ;
m_SinglePassName [ 0 ] = passName ;
RenderTransparentRenderList ( cull , camera , renderContext , cmd , m_SinglePassName , rendererConfiguration , stateBlock , overrideMaterial ) ;
void RenderTransparentRenderList ( CullResults cull ,
Camera camera ,
ScriptableRenderContext renderContext ,
CommandBuffer cmd ,
ShaderPassName [ ] passNames ,
RendererConfiguration rendererConfiguration = 0 ,
RenderStateBlock ? stateBlock = null ,
Material overrideMaterial = null )
void RenderTransparentRenderList ( CullResults cull ,
Camera camera ,
ScriptableRenderContext renderContext ,
CommandBuffer cmd ,
ShaderPassName [ ] passNames ,
RendererConfiguration rendererConfiguration = 0 ,
RenderStateBlock ? stateBlock = null ,
Material overrideMaterial = null )
{
if ( ! m_CurrentDebugDisplaySettings . renderingDebugSettings . displayTransparentObjects )
return ;
}
if ( overrideMaterial ! = null )
{
}
if ( stateBlock = = null )
renderContext . DrawRenderers ( cull . visibleRenderers , ref drawSettings , filterSettings ) ;
else
using ( new ProfilingSample ( cmd , addDepthPrepass ? "Depth Prepass" : "Depth Prepass forward opaque" ) )
{
// Default depth prepass (forward and deferred) will render all opaque geometry.
RenderQueueRange renderQueueRange = RenderQueueRange . opaque ;
var renderQueueRange = RenderQueueRange . opaque ;
// If we want only alpha tested geometry in prepass for deferred we change the RenderQueueRange
if ( ! m_Asset . renderingSettings . ShouldUseForwardRenderingOnly ( ) & & m_Asset . renderingSettings . useDepthPrepassWithDeferredRendering & & m_Asset . renderingSettings . renderAlphaTestOnlyInDeferredPrepass )
renderQueueRange = new RenderQueueRange { min = ( int ) RenderQueue . AlphaTest , max = ( int ) RenderQueue . GeometryLast - 1 } ;
using ( new ProfilingSample ( cmd , m_CurrentDebugDisplaySettings . IsDebugDisplayEnabled ( ) ? "GBufferDebugDisplay" : "GBuffer" ) )
{
// setup GBuffer for rendering
CoreUtils . SetRenderTarget ( cmd , m_g bufferManager . GetGBuffers ( ) , m_CameraDepthStencilBufferRT ) ;
CoreUtils . SetRenderTarget ( cmd , m_G bufferManager . GetGBuffers ( ) , m_CameraDepthStencilBufferRT ) ;
// Render opaque objects into GBuffer
if ( m_CurrentDebugDisplaySettings . IsDebugDisplayEnabled ( ) )
{
if ( m_Asset . renderingSettings . useDepthPrepassWithDeferredRendering )
{
RenderQueueRange rangeOpaqueNoAlphaTest = new RenderQueueRange { min = ( int ) RenderQueue . Geometry , max = ( int ) RenderQueue . AlphaTest - 1 } ;
RenderQueueRange rangeOpaqueAlphaTest = new RenderQueueRange { min = ( int ) RenderQueue . AlphaTest , max = ( int ) RenderQueue . GeometryLast - 1 } ;
var rangeOpaqueNoAlphaTest = new RenderQueueRange { min = ( int ) RenderQueue . Geometry , max = ( int ) RenderQueue . AlphaTest - 1 } ;
var rangeOpaqueAlphaTest = new RenderQueueRange { min = ( int ) RenderQueue . AlphaTest , max = ( int ) RenderQueue . GeometryLast - 1 } ;
// When using depth prepass for opaque alpha test only we need to use regular depth test for normal opaque objects.
RenderOpaqueRenderList ( cull , camera , renderContext , cmd , HDShaderPassNames . s_GBufferName , HDUtils . k_RendererConfigurationBakedLighting , rangeOpaqueNoAlphaTest , m_Asset . renderingSettings . renderAlphaTestOnlyInDeferredPrepass ? m_DepthStateOpaque : m_DepthStateOpaqueWithPrepass ) ;
void RenderDeferredLighting ( HDCamera hdCamera , CommandBuffer cmd )
{
if ( m_Asset . renderingSettings . ShouldUseForwardRenderingOnly ( ) )
{
}
RenderTargetIdentifier [ ] colorRTs = { m_CameraColorBufferRT , m_CameraSssDiffuseLightingBufferRT } ;
RenderTargetIdentifier depthTexture = GetDepthTexture ( ) ;
m_MRTCache2 [ 0 ] = m_CameraColorBufferRT ;
m_MRTCache2 [ 1 ] = m_CameraSssDiffuseLightingBufferRT ;
var depthTexture = GetDepthTexture ( ) ;
LightLoop . LightingPassOptions options = new LightLoop . LightingPassOptions ( ) ;
var options = new LightLoop . LightingPassOptions ( ) ;
options . volumetricLightingEnabled = m_VolumetricLightingEnabled ;
if ( m_CurrentDebugDisplaySettings . renderingDebugSettings . enableSSSAndTransmission )
m_LightLoop . RenderDeferredLighting ( hdCamera , cmd , m_CurrentDebugDisplaySettings , colorRTs , m_CameraDepthStencilBufferRT , depthTexture , m_DeferredShadowBuffer , options ) ;
m_LightLoop . RenderDeferredLighting ( hdCamera , cmd , m_CurrentDebugDisplaySettings , m_MRTCache2 , m_CameraDepthStencilBufferRT , depthTexture , m_DeferredShadowBuffer , options ) ;
m_LightLoop . RenderDeferredLighting ( hdCamera , cmd , m_CurrentDebugDisplaySettings , colorRTs , m_CameraDepthStencilBufferRT , depthTexture , m_DeferredShadowBuffer , options ) ;
m_LightLoop . RenderDeferredLighting ( hdCamera , cmd , m_CurrentDebugDisplaySettings , m_MRTCache2 , m_CameraDepthStencilBufferRT , depthTexture , m_DeferredShadowBuffer , options ) ;
}
// Combines specular lighting and diffuse lighting with subsurface scattering.
cmd . SetComputeVectorArrayParam ( m_SubsurfaceScatteringCS , HDShaderIDs . _FilterKernels , sssParameters . filterKernels ) ;
cmd . SetComputeVectorArrayParam ( m_SubsurfaceScatteringCS , HDShaderIDs . _ShapeParams , sssParameters . shapeParams ) ;
cmd . SetComputeTextureParam ( m_SubsurfaceScatteringCS , m_SubsurfaceScatteringKernel , HDShaderIDs . _GBufferTexture0 , m_g bufferManager . GetGBuffers ( ) [ 0 ] ) ;
cmd . SetComputeTextureParam ( m_SubsurfaceScatteringCS , m_SubsurfaceScatteringKernel , HDShaderIDs . _GBufferTexture1 , m_g bufferManager . GetGBuffers ( ) [ 1 ] ) ;
cmd . SetComputeTextureParam ( m_SubsurfaceScatteringCS , m_SubsurfaceScatteringKernel , HDShaderIDs . _GBufferTexture2 , m_g bufferManager . GetGBuffers ( ) [ 2 ] ) ;
cmd . SetComputeTextureParam ( m_SubsurfaceScatteringCS , m_SubsurfaceScatteringKernel , HDShaderIDs . _GBufferTexture3 , m_g bufferManager . GetGBuffers ( ) [ 3 ] ) ;
cmd . SetComputeTextureParam ( m_SubsurfaceScatteringCS , m_SubsurfaceScatteringKernel , HDShaderIDs . _GBufferTexture0 , m_G bufferManager . GetGBuffers ( ) [ 0 ] ) ;
cmd . SetComputeTextureParam ( m_SubsurfaceScatteringCS , m_SubsurfaceScatteringKernel , HDShaderIDs . _GBufferTexture1 , m_G bufferManager . GetGBuffers ( ) [ 1 ] ) ;
cmd . SetComputeTextureParam ( m_SubsurfaceScatteringCS , m_SubsurfaceScatteringKernel , HDShaderIDs . _GBufferTexture2 , m_G bufferManager . GetGBuffers ( ) [ 2 ] ) ;
cmd . SetComputeTextureParam ( m_SubsurfaceScatteringCS , m_SubsurfaceScatteringKernel , HDShaderIDs . _GBufferTexture3 , m_G bufferManager . GetGBuffers ( ) [ 3 ] ) ;
cmd . SetComputeTextureParam ( m_SubsurfaceScatteringCS , m_SubsurfaceScatteringKernel , HDShaderIDs . _DepthTexture , GetDepthTexture ( ) ) ;
cmd . SetComputeTextureParam ( m_SubsurfaceScatteringCS , m_SubsurfaceScatteringKernel , HDShaderIDs . _StencilTexture , GetStencilTexture ( ) ) ;
cmd . SetComputeTextureParam ( m_SubsurfaceScatteringCS , m_SubsurfaceScatteringKernel , HDShaderIDs . _HTile , GetHTile ( ) ) ;
m_LightLoop . RenderForward ( camera , cmd , renderOpaque ) ;
// The pass "SRPDefaultUnlit" is a fallback to legacy unlit rendering and is required to support unity 2d + unity UI that render in the scene.
ShaderPassName [ ] arrayNames = { passName , HDShaderPassNames . s_SRPDefaultUnlitName } ;
m_ForwardPassNames [ 0 ] = passName ;
RenderOpaqueRenderList ( cullResults , camera , renderContext , cmd , arrayNames , HDUtils . k_RendererConfigurationBakedLighting , null , m_DepthStateOpaqueWithPrepass ) ;
RenderOpaqueRenderList ( cullResults , camera , renderContext , cmd , m_ForwardPassNames , HDUtils . k_RendererConfigurationBakedLighting , null , m_DepthStateOpaqueWithPrepass ) ;
RenderTransparentRenderList ( cullResults , camera , renderContext , cmd , arrayNames , HDUtils . k_RendererConfigurationBakedLighting ) ;
RenderTransparentRenderList ( cullResults , camera , renderContext , cmd , m_ForwardPassNames , HDUtils . k_RendererConfigurationBakedLighting ) ;
}
}
}
{
CoreUtils . SetRenderTarget ( cmd , m_CameraColorBufferRT , m_CameraDepthStencilBufferRT ) ;
ShaderPassName [ ] arrayNames = { HDShaderPassNames . s_AlwaysName , HDShaderPassNames . s_ForwardBaseName , HDShaderPassNames . s_DeferredName , HDShaderPassNames . s_PrepassBaseName , HDShaderPassNames . s_VertexName , HDShaderPassNames . s_VertexLMRGBMName , HDShaderPassNames . s_VertexLMName } ;
RenderOpaqueRenderList ( cullResults , camera , renderContext , cmd , arrayNames , 0 , null , null , m_ErrorMaterial ) ;
RenderOpaqueRenderList ( cullResults , camera , renderContext , cmd , m_ForwardErrorPassNames , 0 , null , null , m_ErrorMaterial ) ;
RenderTransparentRenderList ( cullResults , camera , renderContext , cmd , arrayNames , 0 , null , m_ErrorMaterial ) ;
RenderTransparentRenderList ( cullResults , camera , renderContext , cmd , m_ForwardErrorPassNames , 0 , null , m_ErrorMaterial ) ;
}
}
}
{
m_ShadowSettings . enabled = m_CurrentDebugDisplaySettings . lightingDebugSettings . enableShadows ;
LightingDebugSettings lightingDebugSettings = m_CurrentDebugDisplaySettings . 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 ) ;
var lightingDebugSettings = m_CurrentDebugDisplaySettings . lightingDebugSettings ;
var debugAlbedo = new Vector4 ( lightingDebugSettings . debugLightingAlbedo . r , lightingDebugSettings . debugLightingAlbedo . g , lightingDebugSettings . debugLightingAlbedo . b , 0.0f ) ;
var debugSmoothness = new Vector4 ( lightingDebugSettings . overrideSmoothness ? 1.0f : 0.0f , lightingDebugSettings . overrideSmoothnessValue , 0.0f , 0.0f ) ;
Shader . SetGlobalInt ( HDShaderIDs . _DebugViewMaterial , ( int ) m_CurrentDebugDisplaySettings . GetDebugMaterialIndex ( ) ) ;
Shader . SetGlobalInt ( HDShaderIDs . _DebugLightingMode , ( int ) m_CurrentDebugDisplaySettings . GetDebugLightingMode ( ) ) ;
float overlaySize = Math . Min ( camera . camera . pixelHeight , camera . camera . pixelWidth ) * overlayRatio ;
float y = camera . camera . pixelHeight - overlaySize ;
LightingDebugSettings lightingDebug = m_CurrentDebugDisplaySettings . lightingDebugSettings ;
var lightingDebug = m_CurrentDebugDisplaySettings . lightingDebugSettings ;
Texture skyReflection = m_SkyManager . skyReflection ;
var skyReflection = m_SkyManager . skyReflection ;
m_SharedPropertyBlock . SetTexture ( HDShaderIDs . _InputCubemap , skyReflection ) ;
m_SharedPropertyBlock . SetFloat ( HDShaderIDs . _Mipmap , lightingDebug . skyReflectionMipmap ) ;
cmd . SetViewport ( new Rect ( x , y , overlaySize , overlaySize ) ) ;
// End
if ( ! m_Asset . renderingSettings . ShouldUseForwardRenderingOnly ( ) )
{
m_gbufferManager . InitGBuffers ( w , h , cmd ) ;
}
m_GbufferManager . InitGBuffers ( w , h , cmd ) ;
CoreUtils . SetRenderTarget ( cmd , m_CameraColorBufferRT , m_CameraDepthStencilBufferRT , ClearFlag . Depth ) ;
}
}
if ( m_VolumetricLightingEnabled )
{
}
// 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.
{
using ( new ProfilingSample ( cmd , "Clear GBuffer" ) )
{
CoreUtils . SetRenderTarget ( cmd , m_g bufferManager . GetGBuffers ( ) , m_CameraDepthStencilBufferRT , ClearFlag . Color , Color . black ) ;
CoreUtils . SetRenderTarget ( cmd , m_G bufferManager . GetGBuffers ( ) , m_CameraDepthStencilBufferRT , ClearFlag . Color , Color . black ) ;
}
}
// END TEMP