Browse Source

Cleaned up the dynamic resolution feature by allowing dynamic scale to be disabled on screen-space RTs and globally disabling dynamic res only once, after upscaling.

fsr2
Nico de Poel 3 years ago
parent
commit
17eb3f7700
  1. 9
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessLayer.cs
  2. 9
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessRenderContext.cs
  3. 4
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Utils/RuntimeUtilities.cs

9
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessLayer.cs

@ -293,7 +293,7 @@ namespace UnityEngine.Rendering.PostProcessing
if (m_CurrentContext.IsSuperResolutionActive()) if (m_CurrentContext.IsSuperResolutionActive())
{ {
RuntimeUtilities.EnableDynamicResolution = true;
RuntimeUtilities.AllowDynamicResolution = true;
} }
if (!finalBlitToCameraTarget && m_CurrentContext.IsSuperResolutionActive()) if (!finalBlitToCameraTarget && m_CurrentContext.IsSuperResolutionActive())
@ -1191,16 +1191,15 @@ namespace UnityEngine.Rendering.PostProcessing
var fsrTarget = m_TargetPool.Get(); var fsrTarget = m_TargetPool.Get();
var finalDestination = context.destination; var finalDestination = context.destination;
RuntimeUtilities.EnableDynamicResolution = false;
context.GetScreenSpaceTemporaryRT(cmd, fsrTarget, 0, context.sourceFormat, enableRandomWrite: true);
context.GetScreenSpaceTemporaryRT(cmd, fsrTarget, 0, context.sourceFormat, isUpscaleOutput: true);
context.destination = fsrTarget; context.destination = fsrTarget;
superResolution.colorOpaqueOnly = m_opaqueOnly; superResolution.colorOpaqueOnly = m_opaqueOnly;
RuntimeUtilities.EnableDynamicResolution = true;
superResolution.Render(context); superResolution.Render(context);
context.source = fsrTarget; context.source = fsrTarget;
context.destination = finalDestination; context.destination = finalDestination;
RuntimeUtilities.EnableDynamicResolution = false;
// Disable dynamic scaling on render targets, so all subsequent effects will be applied on the full resolution upscaled image
RuntimeUtilities.AllowDynamicResolution = false;
if (lastTarget > -1) if (lastTarget > -1)
cmd.ReleaseTemporaryRT(lastTarget); cmd.ReleaseTemporaryRT(lastTarget);

9
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessRenderContext.cs

@ -372,10 +372,10 @@ namespace UnityEngine.Rendering.PostProcessing
/// <param name="filter">The texture filtering mode</param> /// <param name="filter">The texture filtering mode</param>
/// <param name="widthOverride">Override the display width; use <c>0</c> to disable the override</param> /// <param name="widthOverride">Override the display width; use <c>0</c> to disable the override</param>
/// <param name="heightOverride">Override the display height; use <c>0</c> to disable the override</param> /// <param name="heightOverride">Override the display height; use <c>0</c> to disable the override</param>
/// <param name="enableRandomWrite">Enable random access write into this render texture</param>
/// <param name="isUpscaleOutput">Enable random access write into this render texture and disable dynamic scaling</param>
public void GetScreenSpaceTemporaryRT(CommandBuffer cmd, int nameID, public void GetScreenSpaceTemporaryRT(CommandBuffer cmd, int nameID,
int depthBufferBits = 0, RenderTextureFormat colorFormat = RenderTextureFormat.Default, RenderTextureReadWrite readWrite = RenderTextureReadWrite.Default, int depthBufferBits = 0, RenderTextureFormat colorFormat = RenderTextureFormat.Default, RenderTextureReadWrite readWrite = RenderTextureReadWrite.Default,
FilterMode filter = FilterMode.Bilinear, int widthOverride = 0, int heightOverride = 0, bool enableRandomWrite = false)
FilterMode filter = FilterMode.Bilinear, int widthOverride = 0, int heightOverride = 0, bool isUpscaleOutput = false)
{ {
var desc = GetDescriptor(depthBufferBits, colorFormat, readWrite); var desc = GetDescriptor(depthBufferBits, colorFormat, readWrite);
if (widthOverride > 0) if (widthOverride > 0)
@ -387,8 +387,11 @@ namespace UnityEngine.Rendering.PostProcessing
if (stereoActive && desc.dimension == Rendering.TextureDimension.Tex2DArray) if (stereoActive && desc.dimension == Rendering.TextureDimension.Tex2DArray)
desc.dimension = Rendering.TextureDimension.Tex2D; desc.dimension = Rendering.TextureDimension.Tex2D;
if (enableRandomWrite)
if (isUpscaleOutput)
{
desc.enableRandomWrite = true; desc.enableRandomWrite = true;
desc.useDynamicScale = false;
}
#if UNITY_2019_1_OR_NEWER #if UNITY_2019_1_OR_NEWER
cmd.GetTemporaryRT(nameID, desc, filter); cmd.GetTemporaryRT(nameID, desc, filter);

4
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Utils/RuntimeUtilities.cs

@ -1010,7 +1010,7 @@ namespace UnityEngine.Rendering.PostProcessing
&& layer.temporalAntialiasing.IsSupported(); && layer.temporalAntialiasing.IsSupported();
} }
#if UNITY_2017_3_OR_NEWER #if UNITY_2017_3_OR_NEWER
public static bool EnableDynamicResolution = true;
public static bool AllowDynamicResolution = true;
/// <summary> /// <summary>
/// Checks if dynamic resolution is enabled on a given camera. /// Checks if dynamic resolution is enabled on a given camera.
@ -1019,7 +1019,7 @@ namespace UnityEngine.Rendering.PostProcessing
/// <returns><c>true</c> if dynamic resolution is enabled, <c>false</c> otherwise</returns> /// <returns><c>true</c> if dynamic resolution is enabled, <c>false</c> otherwise</returns>
public static bool IsDynamicResolutionEnabled(Camera camera) public static bool IsDynamicResolutionEnabled(Camera camera)
{ {
return EnableDynamicResolution && (camera.allowDynamicResolution || (camera.targetTexture != null && camera.targetTexture.useDynamicScale));
return AllowDynamicResolution && (camera.allowDynamicResolution || (camera.targetTexture != null && camera.targetTexture.useDynamicScale));
} }
#endif #endif
/// <summary> /// <summary>

Loading…
Cancel
Save