Browse Source

Ported changes from FidelityFX 1.1.4

fsr3.1.4
Nico de Poel 9 months ago
parent
commit
834abd0f0e
  1. 8
      Runtime/FSR3/Fsr3Upscaler.cs
  2. 8
      Runtime/FSR3/Fsr3UpscalerContext.cs
  3. 4
      Shaders/shaders/fsr2/ffx_fsr2_accumulate.h
  4. 4
      Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_accumulate.h
  5. 22
      Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_callbacks_hlsl.h
  6. 19
      Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_prepare_reactivity.h

8
Runtime/FSR3/Fsr3Upscaler.cs

@ -201,6 +201,10 @@ namespace FidelityFX.FSR3
public float CameraFovAngleVertical;
public float ViewSpaceToMetersFactor;
public float VelocityFactor = 1.0f;
public float ReactivenessScale = 1.0f;
public float ShadingChangeScale = 1.0f;
public float AccumulationAddedPerFrame = 1.0f / 3.0f;
public float MinDisocclusionAccumulation = -1.0f / 3.0f;
public DispatchFlags Flags;
public bool UseTextureArrays; // Enable texture array bindings, primarily used for HDRP and XR
@ -268,6 +272,10 @@ namespace FidelityFX.FSR3
public float frameIndex;
public float velocityFactor;
public float reactivenessScale;
public float shadingChangeScale;
public float accumulationAddedPerFrame;
public float minDisocclusionAccumulation;
}
[Serializable, StructLayout(LayoutKind.Sequential)]

8
Runtime/FSR3/Fsr3UpscalerContext.cs

@ -97,6 +97,10 @@ namespace FidelityFX.FSR3
UpscalerConsts.maxUpscaleSize = _contextDescription.MaxUpscaleSize;
UpscalerConsts.velocityFactor = 1.0f;
UpscalerConsts.reactivenessScale = 1.0f;
UpscalerConsts.shadingChangeScale = 1.0f;
UpscalerConsts.accumulationAddedPerFrame = 1.0f / 3.0f;
UpscalerConsts.minDisocclusionAccumulation = -1.0f / 3.0f;
_resources.Create(_contextDescription);
CreatePasses();
@ -410,6 +414,10 @@ namespace FidelityFX.FSR3
constants.frameIndex += 1.0f;
constants.velocityFactor = dispatchParams.VelocityFactor;
constants.reactivenessScale = dispatchParams.ReactivenessScale;
constants.shadingChangeScale = dispatchParams.ShadingChangeScale;
constants.accumulationAddedPerFrame = dispatchParams.AccumulationAddedPerFrame;
constants.minDisocclusionAccumulation = dispatchParams.MinDisocclusionAccumulation;
}
private Vector4 SetupDeviceDepthToViewSpaceDepthParams(Fsr3Upscaler.DispatchDescription dispatchParams)

4
Shaders/shaders/fsr2/ffx_fsr2_accumulate.h

@ -66,8 +66,8 @@ void RectifyHistory(
{
FfxFloat32 fScaleFactorInfluence = ffxMin(20.0f, ffxPow(FfxFloat32(1.0f / length(DownscaleFactor().x * DownscaleFactor().y)), 3.0f));
const FfxFloat32 fVecolityFactor = ffxSaturate(params.fHrVelocity / 20.0f);
const FfxFloat32 fBoxScaleT = ffxMax(params.fDepthClipFactor, ffxMax(params.fAccumulationMask, fVecolityFactor));
const FfxFloat32 fHrVelocityFactor = ffxSaturate(params.fHrVelocity / 20.0f);
const FfxFloat32 fBoxScaleT = ffxMax(params.fDepthClipFactor, ffxMax(params.fAccumulationMask, fHrVelocityFactor));
FfxFloat32 fBoxScale = ffxLerp(fScaleFactorInfluence, 1.0f, fBoxScaleT);
FfxFloat32x3 fScaledBoxVec = clippingBox.boxVec * fBoxScale;

4
Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_accumulate.h

@ -46,12 +46,12 @@ void RectifyHistory(
FFX_PARAMETER_INOUT AccumulationPassData data
)
{
const FfxFloat32 fVecolityFactor = ffxSaturate(params.f4KVelocity / 20.0f);
const FfxFloat32 f4kVelocityFactor = ffxSaturate(params.f4KVelocity / 20.0f);
const FfxFloat32 fDistanceFactor = ffxSaturate(0.75f - params.fFarthestDepthInMeters / 20.0f);
const FfxFloat32 fAccumulationFactor = 1.0f - params.fAccumulation;
const FfxFloat32 fReactiveFactor = ffxPow(params.fReactiveMask, 1.0f / 2.0f);
const FfxFloat32 fShadingChangeFactor = params.fShadingChange;
const FfxFloat32 fBoxScaleT = ffxMax(fVecolityFactor, ffxMax(fDistanceFactor, ffxMax(fAccumulationFactor, ffxMax(fReactiveFactor, fShadingChangeFactor))));
const FfxFloat32 fBoxScaleT = ffxMax(f4kVelocityFactor, ffxMax(fDistanceFactor, ffxMax(fAccumulationFactor, ffxMax(fReactiveFactor, fShadingChangeFactor))));
const FfxFloat32 fBoxScale = ffxLerp(3.0f, 1.0f, fBoxScaleT);
const FfxFloat32x3 fScaledBoxVec = data.clippingBox.boxVec * FfxFloat32x3(1.7f, 1.0f, 1.0f) * fBoxScale;

22
Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_callbacks_hlsl.h

@ -77,6 +77,10 @@ cbuffer cbFSR3Upscaler : FFX_FSR3UPSCALER_DECLARE_CB(FSR3UPSCALER_BIND_CB_FSR3UP
FfxFloat32 fFrameIndex;
FfxFloat32 fVelocityFactor;
FfxFloat32 fReactivenessScale;
FfxFloat32 fShadingChangeScale;
FfxFloat32 fAccumulationAddedPerFrame;
FfxFloat32 fMinDisocclusionAccumulation;
};
#define FFX_FSR3UPSCALER_CONSTANT_BUFFER_1_SIZE (sizeof(cbFSR3Upscaler) / 4) // Number of 32-bit values. This must be kept in sync with the cbFSR3Upscaler size.
@ -177,6 +181,16 @@ FfxFloat32 VelocityFactor()
return fVelocityFactor;
}
FfxFloat32 AccumulationAddedPerFrame()
{
return fAccumulationAddedPerFrame;
}
FfxFloat32 MinDisocclusionAccumulation()
{
return fMinDisocclusionAccumulation;
}
#endif // #if defined(FSR3UPSCALER_BIND_CB_FSR3UPSCALER)
#define FFX_FSR3UPSCALER_ROOTSIG_STRINGIFY(p) FFX_FSR3UPSCALER_ROOTSIG_STR(p)
@ -384,7 +398,7 @@ UNITY_FSR_TEX2D(FfxFloat32) r_reactive_mask : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3U
FfxFloat32 LoadReactiveMask(FfxUInt32x2 iPxPos)
{
return r_reactive_mask[UNITY_FSR_POS(iPxPos)];
return r_reactive_mask[UNITY_FSR_POS(iPxPos)] * fReactivenessScale;
}
FfxInt32x2 GetReactiveMaskResourceDimensions()
@ -398,7 +412,7 @@ FfxInt32x2 GetReactiveMaskResourceDimensions()
FfxFloat32 SampleReactiveMask(FfxFloat32x2 fUV)
{
return r_reactive_mask.SampleLevel(s_LinearClamp, UNITY_FSR_UV(fUV), 0).x;
return r_reactive_mask.SampleLevel(s_LinearClamp, UNITY_FSR_UV(fUV), 0).x * fReactivenessScale;
}
#endif
@ -553,12 +567,12 @@ Texture2D<FfxFloat32> r_shading_change : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCAL
FfxFloat32 LoadShadingChange(FfxUInt32x2 iPxPos)
{
return r_shading_change[iPxPos];
return r_shading_change[iPxPos] * fShadingChangeScale;
}
FfxFloat32 SampleShadingChange(FfxFloat32x2 fUV)
{
return r_shading_change.SampleLevel(s_LinearClamp, fUV, 0);
return r_shading_change.SampleLevel(s_LinearClamp, fUV, 0) * fShadingChangeScale;
}
#endif

19
Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_prepare_reactivity.h

@ -210,15 +210,28 @@ FfxFloat32 UpdateAccumulation(FfxInt32x2 iPxPos, FfxFloat32x2 fUv, FfxFloat32x2
const FfxFloat32x2 fReprojectedUv_HW = ClampUv(fReprojectedUv, PreviousFrameRenderSize(), MaxRenderSize());
fAccumulation = ffxSaturate(SampleAccumulation(fReprojectedUv_HW));
}
const FfxFloat32 fAccumulationAddedPerFrame= AccumulationAddedPerFrame(); //default is 0.333
// Assume at frame N+0 fShadingChange is 1.0, and all subsequent frames fShadingChange is 0.0 and fDisocclusion is 0.0. Then,
// frame N+0 fAccumulation will be 0.000
// frame N+2 fAccumulation will be 0.000 + 0.333 * 1 == 0.333
// frame N+3 fAccumulation will be 0.000 + 0.333 * 2 == 0.666
// frame N+4 fAccumulation will be 0.000 + 0.333 * 3 == 0.999
fAccumulation = ffxLerp(fAccumulation, 0.0f, fShadingChange);
fAccumulation = ffxLerp(fAccumulation, ffxMin(fAccumulation, 0.25f), fDisocclusion);
const FfxFloat32 fMinDisocclusionAccumulation = MinDisocclusionAccumulation(); //default is -0.333
// Assume at frame N+0 fDisocclusion is 1.0, and all subsequent frames fShadingChange is 0.0 and fDisocclusion is 0.0. Then,
// frame N+0 fAccumulation will be -0.333f (but normalized to store in unorm)
// frame N+1 fAccumulation will be -0.333f + 0.333 * 1 == 0.000
// frame N+2 fAccumulation will be -0.333f + 0.333 * 2 == 0.333
// frame N+3 fAccumulation will be -0.333f + 0.333 * 3 == 0.666
// frame N+4 fAccumulation will be -0.333f + 0.333 * 4 == 0.999
fAccumulation = ffxLerp(fAccumulation, ffxMin(fMinDisocclusionAccumulation, fAccumulation), fDisocclusion);
fAccumulation *= FfxFloat32(round(fAccumulation * 100.0f) > 1.0f);
// Update for next frame, normalize to store in unorm
const FfxFloat32 fAccumulatedFramesMax = 3.0f;
const FfxFloat32 fAccumulatedFramesToStore = ffxSaturate(fAccumulation + (1.0f / fAccumulatedFramesMax));
const FfxFloat32 fAccumulatedFramesToStore = ffxSaturate(fAccumulation + fAccumulationAddedPerFrame);
StoreAccumulation(iPxPos, fAccumulatedFramesToStore);
return fAccumulation;

Loading…
Cancel
Save