add fsr3
This commit is contained in:
parent
1535347d45
commit
b4d543c222
@ -114,5 +114,5 @@ MonoBehaviour:
|
|||||||
m_PrefilterNativeRenderPass: 1
|
m_PrefilterNativeRenderPass: 1
|
||||||
m_ShaderVariantLogLevel: 0
|
m_ShaderVariantLogLevel: 0
|
||||||
m_ShadowCascades: 0
|
m_ShadowCascades: 0
|
||||||
superResolution: 0
|
superResolution: 3
|
||||||
vrsRate: 0
|
vrsRate: 0
|
||||||
|
|||||||
@ -44,7 +44,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 386e439eeef2849448d91896c74ff1d5, type: 3}
|
m_Script: {fileID: 11500000, guid: 386e439eeef2849448d91896c74ff1d5, type: 3}
|
||||||
m_Name: FSR
|
m_Name: FSR
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
m_Active: 0
|
m_Active: 1
|
||||||
Quality: 0
|
Quality: 0
|
||||||
v1setting:
|
v1setting:
|
||||||
EasuCompute: {fileID: 7200000, guid: 787b0c165dad9074e9489817de945916, type: 3}
|
EasuCompute: {fileID: 7200000, guid: 787b0c165dad9074e9489817de945916, type: 3}
|
||||||
@ -91,6 +91,24 @@ MonoBehaviour:
|
|||||||
autoGenReactivePass: {fileID: 7200000, guid: 3b0d05a92dc6af24fb6f30d6606b37cf, type: 3}
|
autoGenReactivePass: {fileID: 7200000, guid: 3b0d05a92dc6af24fb6f30d6606b37cf, type: 3}
|
||||||
tcrAutoGenPass: {fileID: 7200000, guid: 78865acef22baa24f9ce68fb50877fe8, type: 3}
|
tcrAutoGenPass: {fileID: 7200000, guid: 78865acef22baa24f9ce68fb50877fe8, type: 3}
|
||||||
debugViewPass: {fileID: 7200000, guid: cb24a71d54164c54eb5e86839acd48c5, type: 3}
|
debugViewPass: {fileID: 7200000, guid: cb24a71d54164c54eb5e86839acd48c5, type: 3}
|
||||||
|
AutoExposureSource: 0
|
||||||
|
TransparencyAndCompositionMask: {fileID: 0}
|
||||||
|
PreExposure: 1
|
||||||
|
PerformSharpenPass: 0
|
||||||
|
Sharpness: 0
|
||||||
|
VelocityFactor: 1
|
||||||
|
AutoGenerateTransparencyAndComposition: 0
|
||||||
|
GenerateTransparencyAndCompositionParameters:
|
||||||
|
autoTcThreshold: 0.05
|
||||||
|
autoTcScale: 1
|
||||||
|
autoReactiveScale: 5
|
||||||
|
autoReactiveMax: 0.9
|
||||||
|
AutoGenerateReactiveMask: 0
|
||||||
|
GenerateReactiveParameters:
|
||||||
|
scale: 0.5
|
||||||
|
cutoffThreshold: 0.2
|
||||||
|
binaryValue: 0.9
|
||||||
|
flags: 13
|
||||||
--- !u!114 &-4454652084718109581
|
--- !u!114 &-4454652084718109581
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@ -95,6 +95,21 @@ namespace X.Rendering.Feature
|
|||||||
public class V3Setting
|
public class V3Setting
|
||||||
{
|
{
|
||||||
public Fsr3UpscalerShaders Shaders;
|
public Fsr3UpscalerShaders Shaders;
|
||||||
|
|
||||||
|
public bool AutoExposureSource;
|
||||||
|
public RenderTexture TransparencyAndCompositionMask ;
|
||||||
|
|
||||||
|
public float PreExposure ;
|
||||||
|
public bool PerformSharpenPass ;
|
||||||
|
public float Sharpness;
|
||||||
|
|
||||||
|
public float VelocityFactor = 1;
|
||||||
|
public bool AutoGenerateTransparencyAndComposition;
|
||||||
|
public GenerateTcrParameters GenerateTransparencyAndCompositionParameters = new GenerateTcrParameters();
|
||||||
|
|
||||||
|
public bool AutoGenerateReactiveMask;
|
||||||
|
public GenerateReactiveParameters GenerateReactiveParameters = new GenerateReactiveParameters();
|
||||||
|
|
||||||
}
|
}
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
V3Setting v3setting;
|
V3Setting v3setting;
|
||||||
@ -340,6 +355,7 @@ namespace X.Rendering.Feature
|
|||||||
private readonly Fsr2.GenerateReactiveDescription genReactiveDescription = new();
|
private readonly Fsr2.GenerateReactiveDescription genReactiveDescription = new();
|
||||||
private bool resetHistory = false;
|
private bool resetHistory = false;
|
||||||
private float mipBias;
|
private float mipBias;
|
||||||
|
private Vector2Int prevUpscaleSize;
|
||||||
|
|
||||||
public FSRV2(FSR.V2Setting setting)
|
public FSRV2(FSR.V2Setting setting)
|
||||||
{
|
{
|
||||||
@ -355,8 +371,14 @@ namespace X.Rendering.Feature
|
|||||||
var scaledRenderSize = new Vector2Int(source.rt.width, source.rt.height);
|
var scaledRenderSize = new Vector2Int(source.rt.width, source.rt.height);
|
||||||
var upscaleSize = new Vector2Int(camera.pixelWidth, camera.pixelHeight);
|
var upscaleSize = new Vector2Int(camera.pixelWidth, camera.pixelHeight);
|
||||||
|
|
||||||
if (fsrContext == null)
|
if (fsrContext == null || upscaleSize.x != prevUpscaleSize.x || upscaleSize.y != prevUpscaleSize.y)
|
||||||
{
|
{
|
||||||
|
if (fsrContext != null)
|
||||||
|
{
|
||||||
|
fsrContext.Destroy();
|
||||||
|
fsrContext = null;
|
||||||
|
}
|
||||||
|
|
||||||
Fsr2.InitializationFlags flags = 0;
|
Fsr2.InitializationFlags flags = 0;
|
||||||
if (camera.allowHDR)
|
if (camera.allowHDR)
|
||||||
{
|
{
|
||||||
@ -368,6 +390,8 @@ namespace X.Rendering.Feature
|
|||||||
flags |= Fsr2.InitializationFlags.EnableAutoExposure;
|
flags |= Fsr2.InitializationFlags.EnableAutoExposure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prevUpscaleSize = upscaleSize;
|
||||||
|
resetHistory = true;
|
||||||
fsrContext = Fsr2.CreateContext(upscaleSize, scaledRenderSize, setting.Shaders, flags);
|
fsrContext = Fsr2.CreateContext(upscaleSize, scaledRenderSize, setting.Shaders, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -461,7 +485,13 @@ namespace X.Rendering.Feature
|
|||||||
private readonly FSR.V3Setting setting;
|
private readonly FSR.V3Setting setting;
|
||||||
private readonly ProfilingSampler profiler;
|
private readonly ProfilingSampler profiler;
|
||||||
|
|
||||||
|
private Fsr3UpscalerContext fsrContext;
|
||||||
|
private readonly Fsr3Upscaler.DispatchDescription dispatchDescription = new();
|
||||||
|
private readonly Fsr3Upscaler.GenerateReactiveDescription genReactiveDescription = new();
|
||||||
|
|
||||||
private bool resetHistory = false;
|
private bool resetHistory = false;
|
||||||
|
private float mipBias;
|
||||||
|
private Vector2Int prevUpscaleSize;
|
||||||
|
|
||||||
public FSRV3(FSR.V3Setting setting)
|
public FSRV3(FSR.V3Setting setting)
|
||||||
{
|
{
|
||||||
@ -474,10 +504,118 @@ namespace X.Rendering.Feature
|
|||||||
using var scp = new ProfilingScope(cmd, profiler);
|
using var scp = new ProfilingScope(cmd, profiler);
|
||||||
var cameraData = renderingData.cameraData;
|
var cameraData = renderingData.cameraData;
|
||||||
var camera = cameraData.camera;
|
var camera = cameraData.camera;
|
||||||
|
var scaledRenderSize = new Vector2Int(source.rt.width, source.rt.height);
|
||||||
|
var upscaleSize = new Vector2Int(camera.pixelWidth, camera.pixelHeight);
|
||||||
|
|
||||||
|
if (fsrContext == null || upscaleSize.x != prevUpscaleSize.x || upscaleSize.y != prevUpscaleSize.y)
|
||||||
|
{
|
||||||
|
if (fsrContext != null)
|
||||||
|
{
|
||||||
|
fsrContext.Destroy();
|
||||||
|
fsrContext = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Fsr3Upscaler.InitializationFlags flags = 0;
|
||||||
|
if (camera.allowHDR)
|
||||||
|
{
|
||||||
|
flags |= Fsr3Upscaler.InitializationFlags.EnableHighDynamicRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setting.AutoExposureSource)
|
||||||
|
{
|
||||||
|
flags |= Fsr3Upscaler.InitializationFlags.EnableAutoExposure;
|
||||||
|
}
|
||||||
|
|
||||||
|
resetHistory = true;
|
||||||
|
prevUpscaleSize = upscaleSize;
|
||||||
|
fsrContext = Fsr3Upscaler.CreateContext(upscaleSize, scaledRenderSize, setting.Shaders, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
var depth = renderingData.cameraData.renderer.cameraDepthTargetHandle;
|
||||||
|
|
||||||
|
dispatchDescription.Color = new ResourceView(source.rt);
|
||||||
|
dispatchDescription.Depth = new ResourceView(depth.rt, RenderTextureSubElement.Depth);
|
||||||
|
dispatchDescription.MotionVectors = new ResourceView(motionVector.rt);
|
||||||
|
dispatchDescription.Exposure = ResourceView.Unassigned;
|
||||||
|
dispatchDescription.Reactive = ResourceView.Unassigned;
|
||||||
|
dispatchDescription.TransparencyAndComposition = ResourceView.Unassigned;
|
||||||
|
|
||||||
|
|
||||||
|
if (setting.TransparencyAndCompositionMask != null)
|
||||||
|
{
|
||||||
|
dispatchDescription.TransparencyAndComposition = new ResourceView(setting.TransparencyAndCompositionMask);
|
||||||
|
}
|
||||||
|
|
||||||
|
mipBias = Fsr3Upscaler.GetMipmapBiasOffset(scaledRenderSize.x, upscaleSize.x);
|
||||||
|
|
||||||
|
SuperResolutionParamSets.Instance.Set<bool>("NeedJitter", true);
|
||||||
|
SuperResolutionParamSets.Instance.Set<float>("MipmapBias", mipBias);
|
||||||
|
var jitter = TemporalAA.CurrentJitter;
|
||||||
|
|
||||||
|
dispatchDescription.Output = new ResourceView(destination.rt);
|
||||||
|
dispatchDescription.PreExposure = setting.PreExposure;
|
||||||
|
dispatchDescription.EnableSharpening = setting.PerformSharpenPass;
|
||||||
|
dispatchDescription.Sharpness = setting.Sharpness;
|
||||||
|
dispatchDescription.JitterOffset = jitter;
|
||||||
|
dispatchDescription.MotionVectorScale.x = -scaledRenderSize.x;
|
||||||
|
dispatchDescription.MotionVectorScale.y = -scaledRenderSize.y;
|
||||||
|
dispatchDescription.RenderSize = scaledRenderSize;
|
||||||
|
dispatchDescription.UpscaleSize = upscaleSize;
|
||||||
|
dispatchDescription.FrameTimeDelta = Time.unscaledDeltaTime;
|
||||||
|
dispatchDescription.CameraNear = camera.nearClipPlane;
|
||||||
|
dispatchDescription.CameraFar = camera.farClipPlane;
|
||||||
|
dispatchDescription.CameraFovAngleVertical = camera.fieldOfView * Mathf.Deg2Rad;
|
||||||
|
dispatchDescription.ViewSpaceToMetersFactor = 1.0f; // 1 unit is 1 meter in Unity
|
||||||
|
dispatchDescription.VelocityFactor = setting.VelocityFactor;
|
||||||
|
dispatchDescription.Reset = resetHistory;
|
||||||
|
resetHistory = false;
|
||||||
|
|
||||||
|
// Set up the parameters for the optional experimental auto-TCR feature
|
||||||
|
dispatchDescription.EnableAutoReactive = setting.AutoGenerateTransparencyAndComposition;
|
||||||
|
if (setting.AutoGenerateTransparencyAndComposition)
|
||||||
|
{
|
||||||
|
dispatchDescription.ColorOpaqueOnly = new ResourceView(Shader.GetGlobalTexture("_CameraOpaqueTexture"));
|
||||||
|
dispatchDescription.AutoTcThreshold = setting.GenerateTransparencyAndCompositionParameters.autoTcThreshold;
|
||||||
|
dispatchDescription.AutoTcScale = setting.GenerateTransparencyAndCompositionParameters.autoTcScale;
|
||||||
|
dispatchDescription.AutoReactiveScale = setting.GenerateTransparencyAndCompositionParameters.autoReactiveScale;
|
||||||
|
dispatchDescription.AutoReactiveMax = setting.GenerateTransparencyAndCompositionParameters.autoReactiveMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SystemInfo.usesReversedZBuffer)
|
||||||
|
{
|
||||||
|
// Swap the near and far clip plane distances as FSR3 Upscaler expects this when using inverted depth
|
||||||
|
(dispatchDescription.CameraNear, dispatchDescription.CameraFar) = (dispatchDescription.CameraFar, dispatchDescription.CameraNear);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setting.AutoGenerateReactiveMask)
|
||||||
|
{
|
||||||
|
genReactiveDescription.ColorOpaqueOnly = new ResourceView(Shader.GetGlobalTexture("_CameraOpaqueTexture"));
|
||||||
|
genReactiveDescription.ColorPreUpscale = new ResourceView(source.rt);
|
||||||
|
genReactiveDescription.OutReactive = new ResourceView(Fsr3ShaderIDs.UavAutoReactive);
|
||||||
|
genReactiveDescription.RenderSize = scaledRenderSize;
|
||||||
|
|
||||||
|
genReactiveDescription.Scale = setting.GenerateReactiveParameters.scale;
|
||||||
|
genReactiveDescription.CutoffThreshold = setting.GenerateReactiveParameters.cutoffThreshold;
|
||||||
|
genReactiveDescription.BinaryValue = setting.GenerateReactiveParameters.binaryValue;
|
||||||
|
genReactiveDescription.Flags = (Fsr3Upscaler.GenerateReactiveFlags)setting.GenerateReactiveParameters.flags;
|
||||||
|
|
||||||
|
|
||||||
|
cmd.GetTemporaryRT(Fsr3ShaderIDs.UavAutoReactive, scaledRenderSize.x, scaledRenderSize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true);
|
||||||
|
fsrContext.GenerateReactiveMask(genReactiveDescription, cmd);
|
||||||
|
dispatchDescription.Reactive = new ResourceView(Fsr3ShaderIDs.UavAutoReactive);
|
||||||
|
}
|
||||||
|
|
||||||
|
fsrContext.Dispatch(dispatchDescription, cmd);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
if (fsrContext != null)
|
||||||
|
{
|
||||||
|
fsrContext.Destroy();
|
||||||
|
fsrContext = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user