@@ -374,7 +374,10 @@ public enum StencilBitMask
374374
375375 // Debugging
376376 MaterialPropertyBlock m_SharedPropertyBlock = new MaterialPropertyBlock ( ) ;
377- public DebugDisplaySettings m_DebugDisplaySettings = new DebugDisplaySettings ( ) ;
377+ DebugDisplaySettings m_DebugDisplaySettings = new DebugDisplaySettings ( ) ;
378+ static DebugDisplaySettings s_NeutraDebugDisplaySettings = new DebugDisplaySettings ( ) ;
379+ DebugDisplaySettings m_CurrentDebugDisplaySettings = null ;
380+
378381 private int m_DebugFullScreenTempRT ;
379382 private bool m_FullScreenDebugPushed = false ;
380383
@@ -676,7 +679,7 @@ public void PushGlobalParams(HDCamera hdCamera, CommandBuffer cmd, SubsurfaceSca
676679 }
677680
678681 // Broadcast SSS parameters to all shaders.
679- Shader . SetGlobalInt ( HDShaderIDs . _EnableSSSAndTransmission , m_DebugDisplaySettings . renderingDebugSettings . enableSSSAndTransmission ? 1 : 0 ) ;
682+ Shader . SetGlobalInt ( HDShaderIDs . _EnableSSSAndTransmission , m_CurrentDebugDisplaySettings . renderingDebugSettings . enableSSSAndTransmission ? 1 : 0 ) ;
680683 Shader . SetGlobalInt ( HDShaderIDs . _TexturingModeFlags , ( int ) sssParameters . texturingModeFlags ) ;
681684 Shader . SetGlobalInt ( HDShaderIDs . _TransmissionFlags , ( int ) sssParameters . transmissionFlags ) ;
682685 Shader . SetGlobalInt ( HDShaderIDs . _UseDisneySSS , sssParameters . useDisneySSS ? 1 : 0 ) ;
@@ -699,14 +702,14 @@ bool NeedStencilBufferCopy()
699702 {
700703 // Currently, Unity does not offer a way to bind the stencil buffer as a texture in a compute shader.
701704 // Therefore, it's manually copied using a pixel shader.
702- return m_DebugDisplaySettings . renderingDebugSettings . enableSSSAndTransmission || LightLoop . GetFeatureVariantsEnabled ( m_Asset . tileSettings ) ;
705+ return m_CurrentDebugDisplaySettings . renderingDebugSettings . enableSSSAndTransmission || LightLoop . GetFeatureVariantsEnabled ( m_Asset . tileSettings ) ;
703706 }
704707
705708 bool NeedHTileCopy ( )
706709 {
707710 // Currently, Unity does not offer a way to access the GCN HTile even on PS4 and Xbox One.
708711 // Therefore, it's computed in a pixel shader, and optimized to only contain the SSS bit.
709- return m_DebugDisplaySettings . renderingDebugSettings . enableSSSAndTransmission ;
712+ return m_CurrentDebugDisplaySettings . renderingDebugSettings . enableSSSAndTransmission ;
710713 }
711714
712715 RenderTargetIdentifier GetDepthTexture ( )
@@ -794,9 +797,6 @@ public override void Render(ScriptableRenderContext renderContext, Camera[] came
794797 // Do anything we need to do upon a new frame.
795798 m_LightLoop . NewFrame ( ) ;
796799
797- ApplyDebugDisplaySettings ( ) ;
798- UpdateCommonSettings ( ) ;
799-
800800 // we only want to render one camera for now
801801 // select the most main camera!
802802
@@ -820,6 +820,21 @@ public override void Render(ScriptableRenderContext renderContext, Camera[] came
820820 return ;
821821 }
822822
823+ // If we render a reflection view or a preview we should not display any debug information
824+ // This need to be call before ApplyDebugDisplaySettings()
825+ if ( camera . cameraType == CameraType . Reflection || camera . cameraType == CameraType . Preview )
826+ {
827+ // Neutral allow to disable all debug settings
828+ m_CurrentDebugDisplaySettings = s_NeutraDebugDisplaySettings ;
829+ }
830+ else
831+ {
832+ m_CurrentDebugDisplaySettings = m_DebugDisplaySettings ;
833+ }
834+
835+ ApplyDebugDisplaySettings ( ) ;
836+ UpdateCommonSettings ( ) ;
837+
823838 ScriptableCullingParameters cullingParams ;
824839 if ( ! CullResults . GetCullingParameters ( camera , out cullingParams ) )
825840 {
@@ -828,7 +843,7 @@ public override void Render(ScriptableRenderContext renderContext, Camera[] came
828843 }
829844
830845 m_LightLoop . UpdateCullingParameters ( ref cullingParams ) ;
831-
846+
832847#if UNITY_EDITOR
833848 // emit scene view UI
834849 if ( camera . cameraType == CameraType . SceneView )
@@ -887,7 +902,7 @@ public override void Render(ScriptableRenderContext renderContext, Camera[] came
887902 // Required for the SSS and the shader feature classification pass.
888903 PrepareAndBindStencilTexture ( cmd ) ;
889904
890- if ( m_DebugDisplaySettings . IsDebugMaterialDisplayEnabled ( ) )
905+ if ( m_CurrentDebugDisplaySettings . IsDebugMaterialDisplayEnabled ( ) )
891906 {
892907 RenderDebugViewMaterial ( m_CullResults , hdCamera , renderContext , cmd ) ;
893908 }
@@ -909,10 +924,15 @@ public override void Render(ScriptableRenderContext renderContext, Camera[] came
909924 m_LightLoop . BuildGPULightLists ( camera , cmd , m_CameraDepthStencilBufferRT , GetStencilTexture ( ) ) ;
910925 }
911926
912- // Caution: We require sun light here as some sky use the sun light to render, mean UpdateSkyEnvironment
913- // must be call after BuildGPULightLists.
914- // 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).
915- UpdateSkyEnvironment ( hdCamera , cmd ) ;
927+
928+ // Don't update the sky environment if we are rendering a cubemap (it should be update already)
929+ if ( camera . cameraType == CameraType . Reflection )
930+ {
931+ // Caution: We require sun light here as some sky use the sun light to render, mean UpdateSkyEnvironment
932+ // must be call after BuildGPULightLists.
933+ // 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).
934+ UpdateSkyEnvironment ( hdCamera , cmd ) ;
935+ }
916936
917937 RenderDeferredLighting ( hdCamera , cmd ) ;
918938
@@ -926,7 +946,7 @@ public override void Render(ScriptableRenderContext renderContext, Camera[] came
926946 RenderForwardError ( m_CullResults , camera , renderContext , cmd , true ) ;
927947#endif
928948
929- RenderLightingDebug ( hdCamera , cmd , m_CameraColorBufferRT , m_DebugDisplaySettings ) ;
949+ RenderLightingDebug ( hdCamera , cmd , m_CameraColorBufferRT , m_CurrentDebugDisplaySettings ) ;
930950
931951 // If full forward rendering, we did just rendered everything, so we can copy the depth buffer
932952 // If Deferred nothing needs copying anymore.
@@ -993,7 +1013,7 @@ void RenderOpaqueRenderList(CullResults cull, Camera camera, ScriptableRenderCon
9931013
9941014 void RenderOpaqueRenderList ( CullResults cull , Camera camera , ScriptableRenderContext renderContext , CommandBuffer cmd , ShaderPassName [ ] passNames , RendererConfiguration rendererConfiguration = 0 , Material overrideMaterial = null )
9951015 {
996- if ( ! m_DebugDisplaySettings . renderingDebugSettings . displayOpaqueObjects )
1016+ if ( ! m_CurrentDebugDisplaySettings . renderingDebugSettings . displayOpaqueObjects )
9971017 return ;
9981018
9991019 // This is done here because DrawRenderers API lives outside command buffers so we need to make call this before doing any DrawRenders
@@ -1026,7 +1046,7 @@ void RenderTransparentRenderList(CullResults cull, Camera camera, ScriptableRend
10261046
10271047 void RenderTransparentRenderList ( CullResults cull , Camera camera , ScriptableRenderContext renderContext , CommandBuffer cmd , ShaderPassName [ ] passNames , RendererConfiguration rendererConfiguration = 0 , Material overrideMaterial = null )
10281048 {
1029- if ( ! m_DebugDisplaySettings . renderingDebugSettings . displayTransparentObjects )
1049+ if ( ! m_CurrentDebugDisplaySettings . renderingDebugSettings . displayTransparentObjects )
10301050 return ;
10311051
10321052 // This is done here because DrawRenderers API lives outside command buffers so we need to make call this before doing any DrawRenders
@@ -1084,20 +1104,20 @@ void RenderGBuffer(CullResults cull, Camera camera, ScriptableRenderContext rend
10841104 if ( m_Asset . renderingSettings . ShouldUseForwardRenderingOnly ( ) )
10851105 return ;
10861106
1087- using ( new Utilities . ProfilingSample ( m_DebugDisplaySettings . IsDebugDisplayEnabled ( ) ? "GBufferDebugDisplay" : "GBuffer" , cmd ) )
1107+ using ( new Utilities . ProfilingSample ( m_CurrentDebugDisplaySettings . IsDebugDisplayEnabled ( ) ? "GBufferDebugDisplay" : "GBuffer" , cmd ) )
10881108 {
10891109 // setup GBuffer for rendering
10901110 Utilities . SetRenderTarget ( cmd , m_gbufferManager . GetGBuffers ( ) , m_CameraDepthStencilBufferRT ) ;
10911111 // render opaque objects into GBuffer
1092- RenderOpaqueRenderList ( cull , camera , renderContext , cmd , m_DebugDisplaySettings . IsDebugDisplayEnabled ( ) ? HDShaderPassNames . m_GBufferDebugDisplayName : HDShaderPassNames . m_GBufferName , Utilities . kRendererConfigurationBakedLighting ) ;
1112+ RenderOpaqueRenderList ( cull , camera , renderContext , cmd , m_CurrentDebugDisplaySettings . IsDebugDisplayEnabled ( ) ? HDShaderPassNames . m_GBufferDebugDisplayName : HDShaderPassNames . m_GBufferName , Utilities . kRendererConfigurationBakedLighting ) ;
10931113 }
10941114 }
10951115
10961116 void RenderDebugViewMaterial ( CullResults cull , HDCamera hdCamera , ScriptableRenderContext renderContext , CommandBuffer cmd )
10971117 {
10981118 using ( new Utilities . ProfilingSample ( "DisplayDebug ViewMaterial" , cmd ) )
10991119 {
1100- if ( m_DebugDisplaySettings . materialDebugSettings . IsDebugGBufferEnabled ( ) && ! m_Asset . renderingSettings . ShouldUseForwardRenderingOnly ( ) )
1120+ if ( m_CurrentDebugDisplaySettings . materialDebugSettings . IsDebugGBufferEnabled ( ) && ! m_Asset . renderingSettings . ShouldUseForwardRenderingOnly ( ) )
11011121 {
11021122 using ( new Utilities . ProfilingSample ( "DebugViewMaterialGBuffer" , cmd ) )
11031123 {
@@ -1137,25 +1157,25 @@ void RenderDeferredLighting(HDCamera hdCamera, CommandBuffer cmd)
11371157 LightLoop . LightingPassOptions options = new LightLoop . LightingPassOptions ( ) ;
11381158 options . volumetricLightingEnabled = m_VolumetricLightingEnabled ;
11391159
1140- if ( m_DebugDisplaySettings . renderingDebugSettings . enableSSSAndTransmission )
1160+ if ( m_CurrentDebugDisplaySettings . renderingDebugSettings . enableSSSAndTransmission )
11411161 {
11421162 // Output split lighting for materials asking for it (masked in the stencil buffer)
11431163 options . outputSplitLighting = true ;
11441164
1145- m_LightLoop . RenderDeferredLighting ( hdCamera , cmd , m_DebugDisplaySettings , colorRTs , m_CameraDepthStencilBufferRT , depthTexture , m_DeferredShadowBuffer , options ) ;
1165+ m_LightLoop . RenderDeferredLighting ( hdCamera , cmd , m_CurrentDebugDisplaySettings , colorRTs , m_CameraDepthStencilBufferRT , depthTexture , m_DeferredShadowBuffer , options ) ;
11461166 }
11471167
11481168 // Output combined lighting for all the other materials.
11491169 options . outputSplitLighting = false ;
11501170
1151- m_LightLoop . RenderDeferredLighting ( hdCamera , cmd , m_DebugDisplaySettings , colorRTs , m_CameraDepthStencilBufferRT , depthTexture , m_DeferredShadowBuffer , options ) ;
1171+ m_LightLoop . RenderDeferredLighting ( hdCamera , cmd , m_CurrentDebugDisplaySettings , colorRTs , m_CameraDepthStencilBufferRT , depthTexture , m_DeferredShadowBuffer , options ) ;
11521172 }
11531173
11541174 // Combines specular lighting and diffuse lighting with subsurface scattering.
11551175 void SubsurfaceScatteringPass ( HDCamera hdCamera , CommandBuffer cmd , SubsurfaceScatteringSettings sssParameters )
11561176 {
11571177 // Currently, forward-rendered objects do not output split lighting required for the SSS pass.
1158- if ( ! m_DebugDisplaySettings . renderingDebugSettings . enableSSSAndTransmission || m_Asset . renderingSettings . ShouldUseForwardRenderingOnly ( ) )
1178+ if ( ! m_CurrentDebugDisplaySettings . renderingDebugSettings . enableSSSAndTransmission || m_Asset . renderingSettings . ShouldUseForwardRenderingOnly ( ) )
11591179 return ;
11601180
11611181 using ( new Utilities . ProfilingSample ( "Subsurface Scattering" , cmd ) )
@@ -1242,7 +1262,7 @@ void RenderForward(CullResults cullResults, Camera camera, ScriptableRenderConte
12421262
12431263 ShaderPassName passName ;
12441264 string profileName ;
1245- if ( m_DebugDisplaySettings . IsDebugDisplayEnabled ( ) )
1265+ if ( m_CurrentDebugDisplaySettings . IsDebugDisplayEnabled ( ) )
12461266 {
12471267 passName = addForwardPass ? HDShaderPassNames . m_ForwardDisplayDebugName : HDShaderPassNames . m_ForwardOnlyOpaqueDisplayDebugName ;
12481268 profileName = addForwardPass ? ( renderOpaque ? "Forward Opaque Display Debug" : "Forward Transparent Display Debug" ) : "ForwardOnlyOpaqueDisplayDebug" ;
@@ -1329,7 +1349,7 @@ void RenderVelocity(CullResults cullResults, HDCamera hdcam, ScriptableRenderCon
13291349
13301350 void RenderDistortion ( CullResults cullResults , Camera camera , ScriptableRenderContext renderContext , CommandBuffer cmd )
13311351 {
1332- if ( ! m_DebugDisplaySettings . renderingDebugSettings . enableDistortion )
1352+ if ( ! m_CurrentDebugDisplaySettings . renderingDebugSettings . enableDistortion )
13331353 return ;
13341354
13351355 using ( new Utilities . ProfilingSample ( "Distortion" , cmd ) )
@@ -1375,21 +1395,21 @@ void RenderPostProcesses(Camera camera, CommandBuffer cmd, PostProcessLayer laye
13751395
13761396 public void ApplyDebugDisplaySettings ( )
13771397 {
1378- m_ShadowSettings . enabled = m_DebugDisplaySettings . lightingDebugSettings . enableShadows ;
1398+ m_ShadowSettings . enabled = m_CurrentDebugDisplaySettings . lightingDebugSettings . enableShadows ;
13791399
1380- LightingDebugSettings lightingDebugSettings = m_DebugDisplaySettings . lightingDebugSettings ;
1400+ LightingDebugSettings lightingDebugSettings = m_CurrentDebugDisplaySettings . lightingDebugSettings ;
13811401 Vector4 debugAlbedo = new Vector4 ( lightingDebugSettings . debugLightingAlbedo . r , lightingDebugSettings . debugLightingAlbedo . g , lightingDebugSettings . debugLightingAlbedo . b , 0.0f ) ;
13821402 Vector4 debugSmoothness = new Vector4 ( lightingDebugSettings . overrideSmoothness ? 1.0f : 0.0f , lightingDebugSettings . overrideSmoothnessValue , 0.0f , 0.0f ) ;
13831403
1384- Shader . SetGlobalInt ( HDShaderIDs . _DebugViewMaterial , ( int ) m_DebugDisplaySettings . GetDebugMaterialIndex ( ) ) ;
1385- Shader . SetGlobalInt ( HDShaderIDs . _DebugLightingMode , ( int ) m_DebugDisplaySettings . GetDebugLightingMode ( ) ) ;
1404+ Shader . SetGlobalInt ( HDShaderIDs . _DebugViewMaterial , ( int ) m_CurrentDebugDisplaySettings . GetDebugMaterialIndex ( ) ) ;
1405+ Shader . SetGlobalInt ( HDShaderIDs . _DebugLightingMode , ( int ) m_CurrentDebugDisplaySettings . GetDebugLightingMode ( ) ) ;
13861406 Shader . SetGlobalVector ( HDShaderIDs . _DebugLightingAlbedo , debugAlbedo ) ;
13871407 Shader . SetGlobalVector ( HDShaderIDs . _DebugLightingSmoothness , debugSmoothness ) ;
13881408 }
13891409
13901410 public void PushFullScreenDebugTexture ( CommandBuffer cb , RenderTargetIdentifier textureID , Camera camera , ScriptableRenderContext renderContext , FullScreenDebugMode debugMode )
13911411 {
1392- if ( debugMode == m_DebugDisplaySettings . fullScreenDebugMode )
1412+ if ( debugMode == m_CurrentDebugDisplaySettings . fullScreenDebugMode )
13931413 {
13941414 m_FullScreenDebugPushed = true ; // We need this flag because otherwise if no fullscreen debug is pushed, when we render the result in RenderDebug the temporary RT will not exist.
13951415 cb . GetTemporaryRT ( m_DebugFullScreenTempRT , camera . pixelWidth , camera . pixelHeight , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear ) ;
@@ -1414,21 +1434,21 @@ void RenderDebug(HDCamera camera, CommandBuffer cmd)
14141434 Utilities . SetRenderTarget ( cmd , BuiltinRenderTextureType . CameraTarget , m_CameraDepthStencilBufferRT ) ;
14151435
14161436 // First render full screen debug texture
1417- if ( m_DebugDisplaySettings . fullScreenDebugMode != FullScreenDebugMode . None && m_FullScreenDebugPushed )
1437+ if ( m_CurrentDebugDisplaySettings . fullScreenDebugMode != FullScreenDebugMode . None && m_FullScreenDebugPushed )
14181438 {
14191439 m_FullScreenDebugPushed = false ;
14201440 cmd . SetGlobalTexture ( HDShaderIDs . _DebugFullScreenTexture , m_DebugFullScreenTempRT ) ;
1421- m_DebugFullScreen . SetFloat ( HDShaderIDs . _FullScreenDebugMode , ( float ) m_DebugDisplaySettings . fullScreenDebugMode ) ;
1441+ m_DebugFullScreen . SetFloat ( HDShaderIDs . _FullScreenDebugMode , ( float ) m_CurrentDebugDisplaySettings . fullScreenDebugMode ) ;
14221442 Utilities . DrawFullScreen ( cmd , m_DebugFullScreen , ( RenderTargetIdentifier ) BuiltinRenderTextureType . CameraTarget ) ;
14231443 }
14241444
14251445 // Then overlays
14261446 float x = 0 ;
1427- float overlayRatio = m_DebugDisplaySettings . debugOverlayRatio ;
1447+ float overlayRatio = m_CurrentDebugDisplaySettings . debugOverlayRatio ;
14281448 float overlaySize = Math . Min ( camera . camera . pixelHeight , camera . camera . pixelWidth ) * overlayRatio ;
14291449 float y = camera . camera . pixelHeight - overlaySize ;
14301450
1431- LightingDebugSettings lightingDebug = m_DebugDisplaySettings . lightingDebugSettings ;
1451+ LightingDebugSettings lightingDebug = m_CurrentDebugDisplaySettings . lightingDebugSettings ;
14321452
14331453 if ( lightingDebug . displaySkyReflection )
14341454 {
@@ -1440,7 +1460,7 @@ void RenderDebug(HDCamera camera, CommandBuffer cmd)
14401460 Utilities . NextOverlayCoord ( ref x , ref y , overlaySize , overlaySize , camera . camera . pixelWidth ) ;
14411461 }
14421462
1443- m_LightLoop . RenderDebugOverlay ( camera . camera , cmd , m_DebugDisplaySettings , ref x , ref y , overlaySize , camera . camera . pixelWidth ) ;
1463+ m_LightLoop . RenderDebugOverlay ( camera . camera , cmd , m_CurrentDebugDisplaySettings , ref x , ref y , overlaySize , camera . camera . pixelWidth ) ;
14441464 }
14451465 }
14461466
0 commit comments