Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit f39a092

Browse files
authored
Merge pull request #750 from Unity-Technologies/load-rt-when-viewport-used
Update RuntimeUtilities.cs
2 parents f640579 + d462e55 commit f39a092

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

PostProcessing/Runtime/Utils/RuntimeUtilities.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace UnityEngine.Rendering.PostProcessing
1414
{
1515
using SceneManagement;
1616
using UnityObject = UnityEngine.Object;
17+
using LoadAction = RenderBufferLoadAction;
18+
using StoreAction = RenderBufferStoreAction;
1719

1820
/// <summary>
1921
/// A set of runtime utilities used by the post-processing stack.
@@ -200,7 +202,7 @@ public static Texture2D GetLutStrip(int size)
200202
var format = TextureFormat.RGBAHalf;
201203
if (!format.IsSupported())
202204
format = TextureFormat.ARGB32;
203-
205+
204206
texture = new Texture2D(size * size, size, format, false, true)
205207
{
206208
name = "Strip Lut" + size,
@@ -431,7 +433,7 @@ public static void SetRenderTargetWithLoadStoreAction(this CommandBuffer cmd,
431433
public static void BlitFullscreenTriangle(this CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier destination, bool clear = false, Rect? viewport = null)
432434
{
433435
cmd.SetGlobalTexture(ShaderIDs.MainTex, source);
434-
cmd.SetRenderTargetWithLoadStoreAction(destination, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
436+
cmd.SetRenderTargetWithLoadStoreAction(destination, viewport == null ? LoadAction.DontCare : LoadAction.Load, StoreAction.Store);
435437

436438
if (viewport != null)
437439
cmd.SetViewport(viewport.Value);
@@ -456,11 +458,13 @@ public static void BlitFullscreenTriangle(this CommandBuffer cmd, RenderTargetId
456458
{
457459
cmd.SetGlobalTexture(ShaderIDs.MainTex, source);
458460
#if UNITY_2018_2_OR_NEWER
459-
bool clear = (loadAction == RenderBufferLoadAction.Clear);
461+
bool clear = (loadAction == LoadAction.Clear);
462+
if(clear)
463+
loadAction = LoadAction.DontCare;
460464
#else
461465
bool clear = false;
462466
#endif
463-
cmd.SetRenderTargetWithLoadStoreAction(destination, clear ? RenderBufferLoadAction.DontCare : loadAction, RenderBufferStoreAction.Store);
467+
cmd.SetRenderTargetWithLoadStoreAction(destination, viewport == null ? loadAction : LoadAction.Load, StoreAction.Store);
464468

465469
if (viewport != null)
466470
cmd.SetViewport(viewport.Value);
@@ -484,10 +488,10 @@ public static void BlitFullscreenTriangle(this CommandBuffer cmd, RenderTargetId
484488
public static void BlitFullscreenTriangle(this CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier destination, PropertySheet propertySheet, int pass, bool clear = false, Rect? viewport = null)
485489
{
486490
#if UNITY_2018_2_OR_NEWER
487-
cmd.BlitFullscreenTriangle(source, destination, propertySheet, pass, clear ? RenderBufferLoadAction.Clear : RenderBufferLoadAction.DontCare, viewport);
491+
cmd.BlitFullscreenTriangle(source, destination, propertySheet, pass, clear ? LoadAction.Clear : LoadAction.DontCare, viewport);
488492
#else
489493
cmd.SetGlobalTexture(ShaderIDs.MainTex, source);
490-
cmd.SetRenderTargetWithLoadStoreAction(destination, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
494+
cmd.SetRenderTargetWithLoadStoreAction(destination, viewport == null ? LoadAction.DontCare : LoadAction.Load, StoreAction.Store);
491495

492496
if (viewport != null)
493497
cmd.SetViewport(viewport.Value);
@@ -597,17 +601,16 @@ public static void BlitFullscreenTriangleToTexArray(this CommandBuffer cmd, Rend
597601
public static void BlitFullscreenTriangle(this CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier destination, RenderTargetIdentifier depth, PropertySheet propertySheet, int pass, bool clear = false, Rect? viewport = null)
598602
{
599603
cmd.SetGlobalTexture(ShaderIDs.MainTex, source);
600-
604+
605+
LoadAction loadAction = viewport == null ? LoadAction.DontCare : LoadAction.Load;
601606
if (clear)
602607
{
603-
cmd.SetRenderTargetWithLoadStoreAction(destination, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store,
604-
depth, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
608+
cmd.SetRenderTargetWithLoadStoreAction(destination, loadAction, StoreAction.Store, depth, loadAction, StoreAction.Store);
605609
cmd.ClearRenderTarget(true, true, Color.clear);
606610
}
607611
else
608612
{
609-
cmd.SetRenderTargetWithLoadStoreAction(destination, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store,
610-
depth, RenderBufferLoadAction.Load, RenderBufferStoreAction.Store);
613+
cmd.SetRenderTargetWithLoadStoreAction(destination, loadAction, StoreAction.Store, depth, LoadAction.Load, StoreAction.Store);
611614
}
612615

613616
if (viewport != null)

0 commit comments

Comments
 (0)