Browse Source

Added support for auto-reactive mask generation, using a temp RT for storing the opaque-only image.

stable
Nico de Poel 3 years ago
parent
commit
ff34164ef3
  1. 27
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs
  2. 20
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessLayer.cs

27
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs

@ -22,8 +22,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.Experimental.Rendering;
using FidelityFX; using FidelityFX;
namespace UnityEngine.Rendering.PostProcessing namespace UnityEngine.Rendering.PostProcessing
@ -64,9 +63,13 @@ namespace UnityEngine.Rendering.PostProcessing
[Serializable] [Serializable]
public class GenerateReactiveParameters public class GenerateReactiveParameters
{ {
[Tooltip("A value to scale the output")]
[Range(0, 2)] public float scale = 0.5f; [Range(0, 2)] public float scale = 0.5f;
[Tooltip("A threshold value to generate a binary reactive mask")]
[Range(0, 1)] public float cutoffThreshold = 0.2f; [Range(0, 1)] public float cutoffThreshold = 0.2f;
[Tooltip("A value to set for the binary reactive mask")]
[Range(0, 1)] public float binaryValue = 0.9f; [Range(0, 1)] public float binaryValue = 0.9f;
[Tooltip("Flags to determine how to generate the reactive mask")]
public Fsr2.GenerateReactiveFlags flags = Fsr2.GenerateReactiveFlags.ApplyTonemap | Fsr2.GenerateReactiveFlags.ApplyThreshold | Fsr2.GenerateReactiveFlags.UseComponentsMax; public Fsr2.GenerateReactiveFlags flags = Fsr2.GenerateReactiveFlags.ApplyTonemap | Fsr2.GenerateReactiveFlags.ApplyThreshold | Fsr2.GenerateReactiveFlags.UseComponentsMax;
} }
@ -133,7 +136,7 @@ namespace UnityEngine.Rendering.PostProcessing
context.camera.rect = _originalRect; context.camera.rect = _originalRect;
} }
public void Render(PostProcessRenderContext context)
public void Render(PostProcessRenderContext context, RenderTargetIdentifier opaqueOnly)
{ {
var cmd = context.command; var cmd = context.command;
cmd.BeginSample("FSR2"); cmd.BeginSample("FSR2");
@ -156,7 +159,11 @@ namespace UnityEngine.Rendering.PostProcessing
if (autoGenerateReactiveMask) if (autoGenerateReactiveMask)
{ {
// TODO: auto-generate reactive mask
SetupAutoReactiveDescription(context, opaqueOnly);
cmd.GetTemporaryRT(Fsr2ShaderIDs.UavAutoReactive, _renderSize.x, _renderSize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true);
_fsrContext.GenerateReactiveMask(_genReactiveDescription, cmd);
_dispatchDescription.Reactive = Fsr2ShaderIDs.UavAutoReactive;
} }
cmd.GetTemporaryRT(Fsr2ShaderIDs.UavUpscaledOutput, _displaySize.x, _displaySize.y, 0, default, context.sourceFormat, default, 1, true); cmd.GetTemporaryRT(Fsr2ShaderIDs.UavUpscaledOutput, _displaySize.x, _displaySize.y, 0, default, context.sourceFormat, default, 1, true);
@ -264,6 +271,18 @@ namespace UnityEngine.Rendering.PostProcessing
} }
} }
private void SetupAutoReactiveDescription(PostProcessRenderContext context, RenderTargetIdentifier opaqueOnly)
{
_genReactiveDescription.ColorOpaqueOnly = opaqueOnly;
_genReactiveDescription.ColorPreUpscale = null;
_genReactiveDescription.OutReactive = null;
_genReactiveDescription.RenderSize = _renderSize;
_genReactiveDescription.Scale = generateReactiveParameters.scale;
_genReactiveDescription.CutoffThreshold = generateReactiveParameters.cutoffThreshold;
_genReactiveDescription.BinaryValue = generateReactiveParameters.binaryValue;
_genReactiveDescription.Flags = generateReactiveParameters.flags;
}
private class Callbacks : Fsr2CallbacksBase private class Callbacks : Fsr2CallbacksBase
{ {
private readonly PostProcessResources _resources; private readonly PostProcessResources _resources;

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

@ -214,6 +214,7 @@ namespace UnityEngine.Rendering.PostProcessing
PostProcessRenderContext m_CurrentContext; PostProcessRenderContext m_CurrentContext;
LogHistogram m_LogHistogram; LogHistogram m_LogHistogram;
RenderTexture m_opaqueOnly;
RenderTexture m_upscaledOutput; RenderTexture m_upscaledOutput;
bool m_SettingsUpdateNeeded = true; bool m_SettingsUpdateNeeded = true;
@ -283,6 +284,12 @@ namespace UnityEngine.Rendering.PostProcessing
[ImageEffectUsesCommandBuffer] [ImageEffectUsesCommandBuffer]
void OnRenderImage(RenderTexture src, RenderTexture dst) void OnRenderImage(RenderTexture src, RenderTexture dst)
{ {
if (m_opaqueOnly != null)
{
m_opaqueOnly.Release();
m_opaqueOnly = null;
}
if (!finalBlitToCameraTarget && m_CurrentContext.IsSuperResolutionActive()) if (!finalBlitToCameraTarget && m_CurrentContext.IsSuperResolutionActive())
{ {
// Blit the upscaled image to the backbuffer // Blit the upscaled image to the backbuffer
@ -634,10 +641,12 @@ namespace UnityEngine.Rendering.PostProcessing
aoRenderer.Get().RenderAfterOpaque(context); aoRenderer.Get().RenderAfterOpaque(context);
} }
bool fsrRequiresOpaque = context.IsSuperResolutionActive() && superResolution.autoGenerateReactiveMask; // TODO or auto-TCR
bool isFogActive = fog.IsEnabledAndSupported(context); bool isFogActive = fog.IsEnabledAndSupported(context);
bool hasCustomOpaqueOnlyEffects = HasOpaqueOnlyEffects(context); bool hasCustomOpaqueOnlyEffects = HasOpaqueOnlyEffects(context);
int opaqueOnlyEffects = 0; int opaqueOnlyEffects = 0;
// TODO: if FSR2 is active & using auto-reactive/TCR, add opaque-only copy step
opaqueOnlyEffects += fsrRequiresOpaque ? 1 : 0;
opaqueOnlyEffects += isScreenSpaceReflectionsActive ? 1 : 0; opaqueOnlyEffects += isScreenSpaceReflectionsActive ? 1 : 0;
opaqueOnlyEffects += isFogActive ? 1 : 0; opaqueOnlyEffects += isFogActive ? 1 : 0;
opaqueOnlyEffects += hasCustomOpaqueOnlyEffects ? 1 : 0; opaqueOnlyEffects += hasCustomOpaqueOnlyEffects ? 1 : 0;
@ -662,7 +671,12 @@ namespace UnityEngine.Rendering.PostProcessing
UpdateSrcDstForOpaqueOnly(ref srcTarget, ref dstTarget, context, cameraTarget, opaqueOnlyEffects); UpdateSrcDstForOpaqueOnly(ref srcTarget, ref dstTarget, context, cameraTarget, opaqueOnlyEffects);
} }
// TODO: create opaque-only texture copy for FSR2 auto-reactive/TCR
if (fsrRequiresOpaque)
{
m_opaqueOnly = context.GetScreenSpaceTemporaryRT();
cmd.BuiltinBlit(context.source, m_opaqueOnly);
opaqueOnlyEffects--;
}
if (isScreenSpaceReflectionsActive) if (isScreenSpaceReflectionsActive)
{ {
@ -1141,7 +1155,7 @@ namespace UnityEngine.Rendering.PostProcessing
var finalDestination = context.destination; var finalDestination = context.destination;
context.GetScreenSpaceTemporaryRT(cmd, fsrTarget, 0, context.sourceFormat); context.GetScreenSpaceTemporaryRT(cmd, fsrTarget, 0, context.sourceFormat);
context.destination = fsrTarget; context.destination = fsrTarget;
superResolution.Render(context);
superResolution.Render(context, m_opaqueOnly);
context.source = fsrTarget; context.source = fsrTarget;
context.destination = finalDestination; context.destination = finalDestination;

Loading…
Cancel
Save