@@ -195,12 +195,31 @@ public static PropertySheet copySheet
195
195
}
196
196
}
197
197
198
+ public static void SetRenderTargetWithLoadStoreAction ( this CommandBuffer cmd , RenderTargetIdentifier rt , RenderBufferLoadAction loadAction , RenderBufferStoreAction storeAction )
199
+ {
200
+ #if UNITY_2018_2_OR_NEWER
201
+ cmd . SetRenderTarget ( rt , loadAction , storeAction ) ;
202
+ #else
203
+ cmd . SetRenderTarget ( rt ) ;
204
+ #endif
205
+ }
206
+ public static void SetRenderTargetWithLoadStoreAction ( this CommandBuffer cmd ,
207
+ RenderTargetIdentifier color , RenderBufferLoadAction colorLoadAction , RenderBufferStoreAction colorStoreAction ,
208
+ RenderTargetIdentifier depth , RenderBufferLoadAction depthLoadAction , RenderBufferStoreAction depthStoreAction )
209
+ {
210
+ #if UNITY_2018_2_OR_NEWER
211
+ cmd . SetRenderTarget ( color , colorLoadAction , colorStoreAction , depth , depthLoadAction , depthStoreAction ) ;
212
+ #else
213
+ cmd . SetRenderTarget ( color , depth ) ;
214
+ #endif
215
+ }
216
+
198
217
// Use a custom blit method to draw a fullscreen triangle instead of a fullscreen quad
199
218
// https://michaldrobot.com/2014/04/01/gcn-execution-patterns-in-full-screen-passes/
200
219
public static void BlitFullscreenTriangle ( this CommandBuffer cmd , RenderTargetIdentifier source , RenderTargetIdentifier destination , bool clear = false )
201
220
{
202
221
cmd . SetGlobalTexture ( ShaderIDs . MainTex , source ) ;
203
- cmd . SetRenderTarget ( destination ) ;
222
+ cmd . SetRenderTargetWithLoadStoreAction ( destination , RenderBufferLoadAction . DontCare , RenderBufferStoreAction . Store ) ;
204
223
205
224
if ( clear )
206
225
cmd . ClearRenderTarget ( true , true , Color . clear ) ;
@@ -211,7 +230,7 @@ public static void BlitFullscreenTriangle(this CommandBuffer cmd, RenderTargetId
211
230
public static void BlitFullscreenTriangle ( this CommandBuffer cmd , RenderTargetIdentifier source , RenderTargetIdentifier destination , PropertySheet propertySheet , int pass , bool clear = false )
212
231
{
213
232
cmd . SetGlobalTexture ( ShaderIDs . MainTex , source ) ;
214
- cmd . SetRenderTarget ( destination ) ;
233
+ cmd . SetRenderTargetWithLoadStoreAction ( destination , RenderBufferLoadAction . DontCare , RenderBufferStoreAction . Store ) ;
215
234
216
235
if ( clear )
217
236
cmd . ClearRenderTarget ( true , true , Color . clear ) ;
@@ -222,10 +241,18 @@ public static void BlitFullscreenTriangle(this CommandBuffer cmd, RenderTargetId
222
241
public static void BlitFullscreenTriangle ( this CommandBuffer cmd , RenderTargetIdentifier source , RenderTargetIdentifier destination , RenderTargetIdentifier depth , PropertySheet propertySheet , int pass , bool clear = false )
223
242
{
224
243
cmd . SetGlobalTexture ( ShaderIDs . MainTex , source ) ;
225
- cmd . SetRenderTarget ( destination , depth ) ;
226
-
244
+
227
245
if ( clear )
246
+ {
247
+ cmd . SetRenderTargetWithLoadStoreAction ( destination , RenderBufferLoadAction . DontCare , RenderBufferStoreAction . Store ,
248
+ depth , RenderBufferLoadAction . DontCare , RenderBufferStoreAction . Store ) ;
228
249
cmd . ClearRenderTarget ( true , true , Color . clear ) ;
250
+ }
251
+ else
252
+ {
253
+ cmd . SetRenderTargetWithLoadStoreAction ( destination , RenderBufferLoadAction . DontCare , RenderBufferStoreAction . Store ,
254
+ depth , RenderBufferLoadAction . Load , RenderBufferStoreAction . Store ) ;
255
+ }
229
256
230
257
cmd . DrawMesh ( fullscreenTriangle , Matrix4x4 . identity , propertySheet . material , 0 , pass , propertySheet . properties ) ;
231
258
}
@@ -249,11 +276,32 @@ public static void BlitFullscreenTriangle(Texture source, RenderTexture destinat
249
276
if ( source != null )
250
277
material . SetTexture ( ShaderIDs . MainTex , source ) ;
251
278
279
+ if ( destination != null )
280
+ destination . DiscardContents ( true , false ) ;
281
+
252
282
Graphics . SetRenderTarget ( destination ) ;
253
283
Graphics . DrawMeshNow ( fullscreenTriangle , Matrix4x4 . identity ) ;
254
284
RenderTexture . active = oldRt ;
255
285
}
256
286
287
+ public static void BuiltinBlit ( this CommandBuffer cmd , Rendering . RenderTargetIdentifier source , Rendering . RenderTargetIdentifier dest )
288
+ {
289
+ #if UNITY_2018_2_OR_NEWER
290
+ cmd . SetRenderTarget ( dest , RenderBufferLoadAction . DontCare , RenderBufferStoreAction . Store ) ;
291
+ dest = BuiltinRenderTextureType . CurrentActive ;
292
+ #endif
293
+ cmd . Blit ( source , dest ) ;
294
+ }
295
+
296
+ public static void BuiltinBlit ( this CommandBuffer cmd , Rendering . RenderTargetIdentifier source , Rendering . RenderTargetIdentifier dest , Material mat , int pass = 0 )
297
+ {
298
+ #if UNITY_2018_2_OR_NEWER
299
+ cmd . SetRenderTarget ( dest , RenderBufferLoadAction . DontCare , RenderBufferStoreAction . Store ) ;
300
+ dest = BuiltinRenderTextureType . CurrentActive ;
301
+ #endif
302
+ cmd . Blit ( source , dest , mat , pass ) ;
303
+ }
304
+
257
305
// Fast basic copy texture if available, falls back to blit copy if not
258
306
// Assumes that both textures have the exact same type and format
259
307
public static void CopyTexture ( CommandBuffer cmd , RenderTargetIdentifier source , RenderTargetIdentifier destination )
0 commit comments