@@ -38,15 +38,6 @@ private Rect CalculateUVRect(UniversalCameraData cameraData, float width, float
3838 return new Rect ( 1 - normalizedSizeX , 1 - normalizedSizeY , normalizedSizeX , normalizedSizeY ) ;
3939 }
4040
41- private Rect CalculateUVRect ( UniversalCameraData cameraData , int textureHeightPercent )
42- {
43- var relativeSize = Mathf . Clamp01 ( textureHeightPercent / 100f ) ;
44- var width = relativeSize * cameraData . pixelWidth ;
45- var height = relativeSize * cameraData . pixelHeight ;
46-
47- return CalculateUVRect ( cameraData , width , height ) ;
48- }
49-
5041 private void CorrectForTextureAspectRatio ( ref float width , ref float height , float sourceWidth , float sourceHeight )
5142 {
5243 if ( sourceWidth != 0 && sourceHeight != 0 )
@@ -72,9 +63,20 @@ private void SetupRenderGraphFinalPassDebug(RenderGraph renderGraph, ContextCont
7263 if ( ( DebugHandler != null ) && DebugHandler . IsActiveForCamera ( cameraData . isPreviewCamera ) )
7364 {
7465 if ( DebugHandler . TryGetFullscreenDebugMode ( out DebugFullScreenMode fullScreenDebugMode , out int textureHeightPercent ) &&
75- ( fullScreenDebugMode != DebugFullScreenMode . ReflectionProbeAtlas || usesClusterLightLoop ) &&
76- ( fullScreenDebugMode != DebugFullScreenMode . STP ) )
66+ ( fullScreenDebugMode != DebugFullScreenMode . ReflectionProbeAtlas || usesClusterLightLoop ) )
7767 {
68+ // if we want to visualize RG internal resources, we need to create an RTHandle external to RG and copy to it the textures to visualize
69+ // this is required because the lifetime of these resources is limited to the RenderGraph execution, and we cannot access the actual resources here
70+
71+ // we also copy external resources into the debug texture below to make them "read only". CreateDebugTexture() can lead to (external) texture reallocation.
72+
73+ var debugDescriptor = cameraData . cameraTargetDescriptor ;
74+ // Ensure target can hold all source values. Source can be signed for example.
75+ if ( SystemInfo . IsFormatSupported ( GraphicsFormat . R16G16B16A16_SFloat , GraphicsFormatUsage . Linear | GraphicsFormatUsage . Render ) )
76+ debugDescriptor . graphicsFormat = GraphicsFormat . R16G16B16A16_SFloat ;
77+
78+ CreateDebugTexture ( debugDescriptor ) ;
79+
7880 float screenWidth = cameraData . pixelWidth ;
7981 float screenHeight = cameraData . pixelHeight ;
8082
@@ -85,107 +87,98 @@ private void SetupRenderGraphFinalPassDebug(RenderGraph renderGraph, ContextCont
8587 bool supportsStereo = false ;
8688 Vector4 dataRangeRemap = Vector4 . zero ; // zero = off, .x = old min, .y = old max, .z = new min, .w = new max
8789
88- // visualize RG internal resources
90+ // The debug texture for STP is filled later during post-process rendering so we cannot assign the resource now or it will be invalid
91+ if ( fullScreenDebugMode != DebugFullScreenMode . STP )
8992 {
90- // if we want to visualize RG internal resources, we need to create an RTHandle external to RG and copy to it the textures to visualize
91- // this is required because the lifetime of these resources is limited to the RenderGraph execution, and we cannot access the actual resources here
92-
93- // we also copy external resources to make them "read only". CreateDebugTexture() can lead to (external) texture reallocation.
94-
95- var debugDescriptor = cameraData . cameraTargetDescriptor ;
96- // Ensure target can hold all source values. Source can be signed for example.
97- if ( SystemInfo . IsFormatSupported ( GraphicsFormat . R16G16B16A16_SFloat , GraphicsFormatUsage . Linear | GraphicsFormatUsage . Render ) )
98- debugDescriptor . graphicsFormat = GraphicsFormat . R16G16B16A16_SFloat ;
99-
100- CreateDebugTexture ( debugDescriptor ) ;
101-
102- ImportResourceParams importParams = new ImportResourceParams ( ) ;
103- importParams . clearOnFirstUse = false ;
104- importParams . discardOnLastUse = false ;
105- TextureHandle debugTexture = renderGraph . ImportTexture ( s_RenderGraphDebugTextureHandle , importParams ) ;
93+ // Render into the debug texture
94+ {
95+ ImportResourceParams importParams = new ImportResourceParams ( ) ;
96+ importParams . clearOnFirstUse = false ;
97+ importParams . discardOnLastUse = false ;
98+ TextureHandle debugTexture = renderGraph . ImportTexture ( s_RenderGraphDebugTextureHandle , importParams ) ;
10699
107100
108- switch ( fullScreenDebugMode )
109- {
110- case DebugFullScreenMode . Depth :
111- {
112- BlitToDebugTexture ( renderGraph , resourceData . cameraDepthTexture , debugTexture ) ;
113- supportsStereo = true ;
114- break ;
115- }
116- case DebugFullScreenMode . MotionVector :
117- {
118- BlitToDebugTexture ( renderGraph , resourceData . motionVectorColor , debugTexture , isSourceTextureColor : true ) ;
119- supportsStereo = true ;
120- // Motion vectors are in signed UV space, zoom in and normalize for visualization. (note: maybe add an option to use (angle, mag) visualization)
121- const float zoom = 0.01f ;
122- dataRangeRemap . x = - zoom ;
123- dataRangeRemap . y = zoom ;
124- dataRangeRemap . z = 0 ;
125- dataRangeRemap . w = 1.0f ;
126- break ;
127- }
128- case DebugFullScreenMode . AdditionalLightsShadowMap :
129- {
130- BlitToDebugTexture ( renderGraph , resourceData . additionalShadowsTexture , debugTexture ) ;
131- break ;
132- }
133- case DebugFullScreenMode . MainLightShadowMap :
134- {
135- BlitToDebugTexture ( renderGraph , resourceData . mainShadowsTexture , debugTexture ) ;
136- break ;
137- }
138- case DebugFullScreenMode . AdditionalLightsCookieAtlas :
101+ switch ( fullScreenDebugMode )
139102 {
140- // Copy atlas texture to make it "readonly". Direct reference (debug=atlas) can lead to handle->texture reallocation.
141- var textureHandle =
142- m_LightCookieManager is { AdditionalLightsCookieAtlasTexture : not null }
143- ? renderGraph . ImportTexture ( m_LightCookieManager
144- . AdditionalLightsCookieAtlasTexture )
145- : TextureHandle . nullHandle ;
146-
147- BlitToDebugTexture ( renderGraph , textureHandle , debugTexture ) ;
148- break ;
103+ case DebugFullScreenMode . Depth :
104+ {
105+ BlitToDebugTexture ( renderGraph , resourceData . cameraDepthTexture , debugTexture ) ;
106+ supportsStereo = true ;
107+ break ;
108+ }
109+ case DebugFullScreenMode . MotionVector :
110+ {
111+ BlitToDebugTexture ( renderGraph , resourceData . motionVectorColor , debugTexture , isSourceTextureColor : true ) ;
112+ supportsStereo = true ;
113+ // Motion vectors are in signed UV space, zoom in and normalize for visualization. (note: maybe add an option to use (angle, mag) visualization)
114+ const float zoom = 0.01f ;
115+ dataRangeRemap . x = - zoom ;
116+ dataRangeRemap . y = zoom ;
117+ dataRangeRemap . z = 0 ;
118+ dataRangeRemap . w = 1.0f ;
119+ break ;
120+ }
121+ case DebugFullScreenMode . AdditionalLightsShadowMap :
122+ {
123+ BlitToDebugTexture ( renderGraph , resourceData . additionalShadowsTexture , debugTexture ) ;
124+ break ;
125+ }
126+ case DebugFullScreenMode . MainLightShadowMap :
127+ {
128+ BlitToDebugTexture ( renderGraph , resourceData . mainShadowsTexture , debugTexture ) ;
129+ break ;
130+ }
131+ case DebugFullScreenMode . AdditionalLightsCookieAtlas :
132+ {
133+ // Copy atlas texture to make it "readonly". Direct reference (debug=atlas) can lead to handle->texture reallocation.
134+ var textureHandle =
135+ m_LightCookieManager is { AdditionalLightsCookieAtlasTexture : not null }
136+ ? renderGraph . ImportTexture ( m_LightCookieManager
137+ . AdditionalLightsCookieAtlasTexture )
138+ : TextureHandle . nullHandle ;
139+
140+ BlitToDebugTexture ( renderGraph , textureHandle , debugTexture ) ;
141+ break ;
142+ }
143+
144+ case DebugFullScreenMode . ReflectionProbeAtlas :
145+ {
146+ // Copy atlas texture to make it "readonly". Direct reference (debug=atlas) can lead to handle->texture reallocation.
147+ var textureHandle =
148+ m_ForwardLights . reflectionProbeManager . atlasRT != null
149+ ? renderGraph . ImportTexture ( RTHandles . Alloc (
150+ m_ForwardLights . reflectionProbeManager . atlasRT , transferOwnership : true ) )
151+ : TextureHandle . nullHandle ;
152+
153+ BlitToDebugTexture ( renderGraph , textureHandle , debugTexture ) ;
154+ break ;
155+ }
156+ default :
157+ {
158+ break ;
159+ }
149160 }
161+ }
150162
151- case DebugFullScreenMode . ReflectionProbeAtlas :
152- {
153- // Copy atlas texture to make it "readonly". Direct reference (debug=atlas) can lead to handle->texture reallocation.
154- var textureHandle =
155- m_ForwardLights . reflectionProbeManager . atlasRT != null
156- ? renderGraph . ImportTexture ( RTHandles . Alloc (
157- m_ForwardLights . reflectionProbeManager . atlasRT , transferOwnership : true ) )
158- : TextureHandle . nullHandle ;
159-
160- BlitToDebugTexture ( renderGraph , textureHandle , debugTexture ) ;
161- break ;
162- }
163- default :
163+ // Textures that are not in screen aspect ratio need to be corrected
164+ {
165+ RenderTexture source = null ;
166+ switch ( fullScreenDebugMode )
164167 {
165- break ;
168+ case DebugFullScreenMode . AdditionalLightsShadowMap : source = m_AdditionalLightsShadowCasterPass ? . m_AdditionalLightsShadowmapHandle ? . rt ; break ;
169+ case DebugFullScreenMode . MainLightShadowMap : source = m_MainLightShadowCasterPass ? . m_MainLightShadowmapTexture ? . rt ; break ;
170+ case DebugFullScreenMode . AdditionalLightsCookieAtlas : source = m_LightCookieManager ? . AdditionalLightsCookieAtlasTexture ? . rt ; break ;
171+ case DebugFullScreenMode . ReflectionProbeAtlas : source = m_ForwardLights ? . reflectionProbeManager . atlasRT ; break ;
172+ default :
173+ break ;
166174 }
167- }
168- }
169175
170- // Textures that are not in screen aspect ratio need to be corrected
171- {
172- RenderTexture source = null ;
173- switch ( fullScreenDebugMode )
174- {
175- case DebugFullScreenMode . AdditionalLightsShadowMap : source = m_AdditionalLightsShadowCasterPass ? . m_AdditionalLightsShadowmapHandle ? . rt ; break ;
176- case DebugFullScreenMode . MainLightShadowMap : source = m_MainLightShadowCasterPass ? . m_MainLightShadowmapTexture ? . rt ; break ;
177- case DebugFullScreenMode . AdditionalLightsCookieAtlas : source = m_LightCookieManager ? . AdditionalLightsCookieAtlasTexture ? . rt ; break ;
178- case DebugFullScreenMode . ReflectionProbeAtlas : source = m_ForwardLights ? . reflectionProbeManager . atlasRT ; break ;
179- default :
180- break ;
176+ // Ensure that atlas is not stretched, but doesn't take up more than the percentage in any dimension.
177+ if ( source != null )
178+ CorrectForTextureAspectRatio ( ref width , ref height , source . width , source . height ) ;
181179 }
182-
183- // Ensure that atlas is not stretched, but doesn't take up more than the percentage in any dimension.
184- if ( source != null )
185- CorrectForTextureAspectRatio ( ref width , ref height , source . width , source . height ) ;
186180 }
187181
188-
189182 Rect uvRect = CalculateUVRect ( cameraData , width , height ) ;
190183 DebugHandler . SetDebugRenderTarget ( s_RenderGraphDebugTextureHandle , uvRect , supportsStereo , dataRangeRemap ) ;
191184 }
@@ -221,17 +214,11 @@ private void SetupAfterPostRenderGraphFinalPassDebug(RenderGraph renderGraph, Co
221214 if ( DebugHandler . TryGetFullscreenDebugMode ( out var debugFullscreenMode , out int textureHeightPercent ) &&
222215 ( debugFullscreenMode == DebugFullScreenMode . STP ) )
223216 {
224- CreateDebugTexture ( cameraData . cameraTargetDescriptor ) ;
225-
226217 ImportResourceParams importParams = new ImportResourceParams ( ) ;
227218 importParams . clearOnFirstUse = false ;
228219 importParams . discardOnLastUse = false ;
229220 TextureHandle debugTexture = renderGraph . ImportTexture ( s_RenderGraphDebugTextureHandle , importParams ) ;
230221 BlitToDebugTexture ( renderGraph , resourceData . stpDebugView , debugTexture ) ;
231-
232- Rect uvRect = CalculateUVRect ( cameraData , textureHeightPercent ) ;
233- Vector4 rangeRemap = Vector4 . zero ; // Off
234- DebugHandler . SetDebugRenderTarget ( s_RenderGraphDebugTextureHandle , uvRect , true , rangeRemap ) ;
235222 }
236223 }
237224 }
0 commit comments