@@ -146,12 +146,31 @@ public static PropertySheet copySheet
146
146
}
147
147
}
148
148
149
+ public static void SetRenderTargetWithLoadStoreAction ( this CommandBuffer cmd , RenderTargetIdentifier rt , RenderBufferLoadAction loadAction , RenderBufferStoreAction storeAction )
150
+ {
151
+ #if UNITY_2018_2_OR_NEWER
152
+ cmd . SetRenderTarget ( rt , loadAction , storeAction ) ;
153
+ #else
154
+ cmd . SetRenderTarget ( rt ) ;
155
+ #endif
156
+ }
157
+ public static void SetRenderTargetWithLoadStoreAction ( this CommandBuffer cmd ,
158
+ RenderTargetIdentifier color , RenderBufferLoadAction colorLoadAction , RenderBufferStoreAction colorStoreAction ,
159
+ RenderTargetIdentifier depth , RenderBufferLoadAction depthLoadAction , RenderBufferStoreAction depthStoreAction )
160
+ {
161
+ #if UNITY_2018_2_OR_NEWER
162
+ cmd . SetRenderTarget ( color , colorLoadAction , colorStoreAction , depth , depthLoadAction , depthStoreAction ) ;
163
+ #else
164
+ cmd . SetRenderTarget ( color , depth ) ;
165
+ #endif
166
+ }
167
+
149
168
// Use a custom blit method to draw a fullscreen triangle instead of a fullscreen quad
150
169
// https://michaldrobot.com/2014/04/01/gcn-execution-patterns-in-full-screen-passes/
151
170
public static void BlitFullscreenTriangle ( this CommandBuffer cmd , RenderTargetIdentifier source , RenderTargetIdentifier destination , bool clear = false )
152
171
{
153
172
cmd . SetGlobalTexture ( ShaderIDs . MainTex , source ) ;
154
- cmd . SetRenderTarget ( destination ) ;
173
+ cmd . SetRenderTargetWithLoadStoreAction ( destination , RenderBufferLoadAction . DontCare , RenderBufferStoreAction . Store ) ;
155
174
156
175
if ( clear )
157
176
cmd . ClearRenderTarget ( true , true , Color . clear ) ;
@@ -162,7 +181,7 @@ public static void BlitFullscreenTriangle(this CommandBuffer cmd, RenderTargetId
162
181
public static void BlitFullscreenTriangle ( this CommandBuffer cmd , RenderTargetIdentifier source , RenderTargetIdentifier destination , PropertySheet propertySheet , int pass , bool clear = false )
163
182
{
164
183
cmd . SetGlobalTexture ( ShaderIDs . MainTex , source ) ;
165
- cmd . SetRenderTarget ( destination ) ;
184
+ cmd . SetRenderTargetWithLoadStoreAction ( destination , RenderBufferLoadAction . DontCare , RenderBufferStoreAction . Store ) ;
166
185
167
186
if ( clear )
168
187
cmd . ClearRenderTarget ( true , true , Color . clear ) ;
@@ -173,10 +192,18 @@ public static void BlitFullscreenTriangle(this CommandBuffer cmd, RenderTargetId
173
192
public static void BlitFullscreenTriangle ( this CommandBuffer cmd , RenderTargetIdentifier source , RenderTargetIdentifier destination , RenderTargetIdentifier depth , PropertySheet propertySheet , int pass , bool clear = false )
174
193
{
175
194
cmd . SetGlobalTexture ( ShaderIDs . MainTex , source ) ;
176
- cmd . SetRenderTarget ( destination , depth ) ;
177
-
195
+
178
196
if ( clear )
197
+ {
198
+ cmd . SetRenderTargetWithLoadStoreAction ( destination , RenderBufferLoadAction . DontCare , RenderBufferStoreAction . Store ,
199
+ depth , RenderBufferLoadAction . DontCare , RenderBufferStoreAction . Store ) ;
179
200
cmd . ClearRenderTarget ( true , true , Color . clear ) ;
201
+ }
202
+ else
203
+ {
204
+ cmd . SetRenderTargetWithLoadStoreAction ( destination , RenderBufferLoadAction . DontCare , RenderBufferStoreAction . Store ,
205
+ depth , RenderBufferLoadAction . Load , RenderBufferStoreAction . Store ) ;
206
+ }
180
207
181
208
cmd . DrawMesh ( fullscreenTriangle , Matrix4x4 . identity , propertySheet . material , 0 , pass , propertySheet . properties ) ;
182
209
}
@@ -200,11 +227,32 @@ public static void BlitFullscreenTriangle(Texture source, RenderTexture destinat
200
227
if ( source != null )
201
228
material . SetTexture ( ShaderIDs . MainTex , source ) ;
202
229
230
+ if ( destination != null )
231
+ destination . DiscardContents ( true , false ) ;
232
+
203
233
Graphics . SetRenderTarget ( destination ) ;
204
234
Graphics . DrawMeshNow ( fullscreenTriangle , Matrix4x4 . identity ) ;
205
235
RenderTexture . active = oldRt ;
206
236
}
207
237
238
+ public static void BuiltinBlit ( this CommandBuffer cmd , Rendering . RenderTargetIdentifier source , Rendering . RenderTargetIdentifier dest )
239
+ {
240
+ #if UNITY_2018_2_OR_NEWER
241
+ cmd . SetRenderTarget ( dest , RenderBufferLoadAction . DontCare , RenderBufferStoreAction . Store ) ;
242
+ dest = BuiltinRenderTextureType . CurrentActive ;
243
+ #endif
244
+ cmd . Blit ( source , dest ) ;
245
+ }
246
+
247
+ public static void BuiltinBlit ( this CommandBuffer cmd , Rendering . RenderTargetIdentifier source , Rendering . RenderTargetIdentifier dest , Material mat , int pass = 0 )
248
+ {
249
+ #if UNITY_2018_2_OR_NEWER
250
+ cmd . SetRenderTarget ( dest , RenderBufferLoadAction . DontCare , RenderBufferStoreAction . Store ) ;
251
+ dest = BuiltinRenderTextureType . CurrentActive ;
252
+ #endif
253
+ cmd . Blit ( source , dest , mat , pass ) ;
254
+ }
255
+
208
256
// Fast basic copy texture if available, falls back to blit copy if not
209
257
// Assumes that both textures have the exact same type and format
210
258
public static void CopyTexture ( CommandBuffer cmd , RenderTargetIdentifier source , RenderTargetIdentifier destination )
0 commit comments