@@ -123,7 +123,7 @@ public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingD
123123 m_FullScreenPass . SetupMembers ( passMaterial , passIndex , fetchColorBuffer , bindDepthStencilAttachment ) ;
124124
125125 m_FullScreenPass . requiresIntermediateTexture = fetchColorBuffer ;
126-
126+
127127 renderer . EnqueuePass ( m_FullScreenPass ) ;
128128 }
129129
@@ -150,14 +150,14 @@ public void SetupMembers(Material material, int passIndex, bool fetchActiveColor
150150 m_BindDepthStencilAttachment = bindDepthStencilAttachment ;
151151 }
152152
153- private static void ExecuteMainPass ( RasterCommandBuffer cmd , RTHandle sourceTexture , Material material , int passIndex )
153+ private static void ExecuteMainPass ( RasterCommandBuffer cmd , RTHandle sourceTexture , Material material , int passIndex , Vector4 blitScaleBias )
154154 {
155155 s_SharedPropertyBlock . Clear ( ) ;
156156 if ( sourceTexture != null )
157157 s_SharedPropertyBlock . SetTexture ( ShaderPropertyId . blitTexture , sourceTexture ) ;
158158
159159 // We need to set the "_BlitScaleBias" uniform for user materials with shaders relying on core Blit.hlsl to work
160- s_SharedPropertyBlock . SetVector ( ShaderPropertyId . blitScaleBias , new Vector4 ( 1 , 1 , 0 , 0 ) ) ;
160+ s_SharedPropertyBlock . SetVector ( ShaderPropertyId . blitScaleBias , blitScaleBias ) ;
161161
162162 cmd . DrawProcedural ( Matrix4x4 . identity , material , passIndex , MeshTopology . Triangles , 3 , 1 , s_SharedPropertyBlock ) ;
163163 }
@@ -169,42 +169,33 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
169169
170170 TextureHandle source , destination ;
171171
172- Debug . Assert ( resourcesData . cameraColor . IsValid ( ) ) ;
173-
174172 if ( m_FetchActiveColor )
175173 {
174+ // The pass requests the intermediate textures so this should always be valid
175+ Debug . Assert ( resourcesData . cameraColor . IsValid ( ) ) ;
176+
176177 var targetDesc = renderGraph . GetTextureDesc ( resourcesData . cameraColor ) ;
177178 targetDesc . name = "_CameraColorFullScreenPass" ;
178179 targetDesc . clearBuffer = false ;
179180
180- source = resourcesData . activeColorTexture ;
181+ source = resourcesData . cameraColor ;
181182 destination = renderGraph . CreateTexture ( targetDesc ) ;
182183
183184 renderGraph . AddBlitPass ( source , destination , Vector2 . one , Vector2 . zero , passName : "Copy Color Full Screen" ) ;
184185
185- //Swap for next pass;
186+ // Swap for next pass;
186187 source = destination ;
187188 }
188189 else
189190 {
190191 source = TextureHandle . nullHandle ;
191192 }
192193
194+ // If resourcesData.isActiveTargetBackBuffer == true, then the backbuffer is alread written to and this could overwrite it.
195+ // However, the user might want to blend into the backbuffer so we allow it here.
193196 destination = resourcesData . activeColorTexture ;
194-
195- // The AddBlitPass utility is not used when m_BindDepthStencilAttachment is active since SetRenderAttachmentDepth is not available with the returned builder of AddBlitPass.
196- bool useCustomPass = input != ScriptableRenderPassInput . None || m_BindDepthStencilAttachment ;
197-
198- if ( useCustomPass )
199- {
200- AddFullscreenRenderPassInputPass ( renderGraph , resourcesData , cameraData , source , destination ) ;
201- }
202- else
203- {
204- var blitMaterialParameters = new BlitMaterialParameters ( source , destination , m_Material , m_PassIndex ) ;
205-
206- renderGraph . AddBlitPass ( blitMaterialParameters , passName : "Blit Color Full Screen" ) ;
207- }
197+
198+ AddFullscreenRenderPassInputPass ( renderGraph , resourcesData , cameraData , source , destination ) ;
208199 }
209200
210201 private void AddFullscreenRenderPassInputPass ( RenderGraph renderGraph , UniversalResourceData resourcesData , UniversalCameraData cameraData , in TextureHandle source , in TextureHandle destination )
@@ -214,10 +205,11 @@ private void AddFullscreenRenderPassInputPass(RenderGraph renderGraph, Universal
214205 passData . material = m_Material ;
215206 passData . passIndex = m_PassIndex ;
216207
217- passData . inputTexture = source ;
208+ passData . source = source ;
209+ passData . destination = destination ;
218210
219- if ( passData . inputTexture . IsValid ( ) )
220- builder . UseTexture ( passData . inputTexture , AccessFlags . Read ) ;
211+ if ( passData . source . IsValid ( ) )
212+ builder . UseTexture ( passData . source , AccessFlags . Read ) ;
221213
222214 bool needsColor = ( input & ScriptableRenderPassInput . Color ) != ScriptableRenderPassInput . None ;
223215 bool needsDepth = ( input & ScriptableRenderPassInput . Depth ) != ScriptableRenderPassInput . None ;
@@ -262,21 +254,17 @@ private void AddFullscreenRenderPassInputPass(RenderGraph renderGraph, Universal
262254
263255 builder . SetRenderFunc ( static ( MainPassData data , RasterGraphContext rgContext ) =>
264256 {
265- ExecuteMainPass ( rgContext . cmd , data . inputTexture , data . material , data . passIndex ) ;
257+ Vector4 scaleBias = RenderingUtils . GetFinalBlitScaleBias ( rgContext , in data . source , in data . destination ) ;
258+ ExecuteMainPass ( rgContext . cmd , data . source , data . material , data . passIndex , scaleBias ) ;
266259 } ) ;
267260 }
268261 }
269-
270- private class CopyPassData
271- {
272- internal TextureHandle inputTexture ;
273- }
274-
275262 private class MainPassData
276263 {
277264 internal Material material ;
278265 internal int passIndex ;
279- internal TextureHandle inputTexture ;
266+ internal TextureHandle source ;
267+ internal TextureHandle destination ;
280268 }
281269 }
282270 }
0 commit comments