Browse Source

Updated upscaler constants definition and implemented modifications to the constants setup function.

fsr3.1
Nico de Poel 2 years ago
parent
commit
3cd8b41224
  1. 25
      Assets/Scripts/Core/Fsr3Upscaler.cs
  2. 47
      Assets/Scripts/Core/Fsr3UpscalerContext.cs

25
Assets/Scripts/Core/Fsr3Upscaler.cs

@ -1,4 +1,4 @@
// Copyright (c) 2023 Nico de Poel
// Copyright (c) 2024 Nico de Poel
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -240,27 +240,30 @@ namespace FidelityFX
internal struct UpscalerConstants internal struct UpscalerConstants
{ {
public Vector2Int renderSize; public Vector2Int renderSize;
public Vector2Int previousFrameRenderSize;
public Vector2Int upscaleSize;
public Vector2Int previousFrameUpscaleSize;
public Vector2Int maxRenderSize; public Vector2Int maxRenderSize;
public Vector2Int displaySize;
public Vector2Int inputColorResourceDimensions;
public Vector2Int lumaMipDimensions;
public int lumaMipLevelToUse;
public int frameIndex;
public Vector2Int maxUpscaleSize;
public Vector4 deviceToViewDepth; public Vector4 deviceToViewDepth;
public Vector2 jitterOffset; public Vector2 jitterOffset;
public Vector2 previousFrameJitterOffset;
public Vector2 motionVectorScale; public Vector2 motionVectorScale;
public Vector2 downscaleFactor; public Vector2 downscaleFactor;
public Vector2 motionVectorJitterCancellation; public Vector2 motionVectorJitterCancellation;
public float preExposure;
public float previousFramePreExposure;
public float tanHalfFOV; public float tanHalfFOV;
public float jitterPhaseCount; public float jitterPhaseCount;
public float deltaTime; public float deltaTime;
public float dynamicResChangeFactor;
public float deltaPreExposure;
public float viewSpaceToMetersFactor; public float viewSpaceToMetersFactor;
public int dummy;
public float frameIndex;
} }
[Serializable, StructLayout(LayoutKind.Sequential)] [Serializable, StructLayout(LayoutKind.Sequential)]

47
Assets/Scripts/Core/Fsr3UpscalerContext.cs

@ -1,4 +1,4 @@
// Copyright (c) 2023 Nico de Poel
// Copyright (c) 2024 Nico de Poel
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -70,8 +70,10 @@ namespace FidelityFX
private ref Fsr3Upscaler.GenerateReactiveConstants2 TcrAutoGenConsts => ref _tcrAutogenerateConstantsArray[0]; private ref Fsr3Upscaler.GenerateReactiveConstants2 TcrAutoGenConsts => ref _tcrAutogenerateConstantsArray[0];
private bool _firstExecution; private bool _firstExecution;
private Vector2 _previousJitterOffset;
private int _resourceFrameIndex; private int _resourceFrameIndex;
private Vector2 _previousJitterOffset;
private float _preExposure;
private float _previousFramePreExposure;
public void Create(Fsr3Upscaler.ContextDescription contextDescription) public void Create(Fsr3Upscaler.ContextDescription contextDescription)
{ {
@ -88,7 +90,7 @@ namespace FidelityFX
_firstExecution = true; _firstExecution = true;
_resourceFrameIndex = 0; _resourceFrameIndex = 0;
UpscalerConsts.displaySize = _contextDescription.MaxUpscaleSize;
UpscalerConsts.maxUpscaleSize = _contextDescription.MaxUpscaleSize;
_resources.Create(_contextDescription); _resources.Create(_contextDescription);
CreatePasses(); CreatePasses();
@ -309,11 +311,13 @@ namespace FidelityFX
private void SetupConstants(Fsr3Upscaler.DispatchDescription dispatchParams, bool resetAccumulation) private void SetupConstants(Fsr3Upscaler.DispatchDescription dispatchParams, bool resetAccumulation)
{ {
ref Fsr3Upscaler.UpscalerConstants constants = ref UpscalerConsts; ref Fsr3Upscaler.UpscalerConstants constants = ref UpscalerConsts;
constants.previousFrameJitterOffset = constants.jitterOffset;
constants.jitterOffset = dispatchParams.JitterOffset; constants.jitterOffset = dispatchParams.JitterOffset;
constants.previousFrameRenderSize = constants.renderSize;
constants.renderSize = dispatchParams.RenderSize; constants.renderSize = dispatchParams.RenderSize;
constants.maxRenderSize = _contextDescription.MaxRenderSize; constants.maxRenderSize = _contextDescription.MaxRenderSize;
constants.inputColorResourceDimensions = dispatchParams.UpscaleSize;
// Compute the horizontal FOV for the shader from the vertical one // Compute the horizontal FOV for the shader from the vertical one
float aspectRatio = (float)dispatchParams.RenderSize.x / dispatchParams.RenderSize.y; float aspectRatio = (float)dispatchParams.RenderSize.x / dispatchParams.RenderSize.y;
@ -323,14 +327,32 @@ namespace FidelityFX
// Compute params to enable device depth to view space depth computation in shader // Compute params to enable device depth to view space depth computation in shader
constants.deviceToViewDepth = SetupDeviceDepthToViewSpaceDepthParams(dispatchParams); constants.deviceToViewDepth = SetupDeviceDepthToViewSpaceDepthParams(dispatchParams);
constants.previousFrameUpscaleSize = constants.upscaleSize;
if (dispatchParams.UpscaleSize.x == 0 && dispatchParams.UpscaleSize.y == 0)
{
constants.upscaleSize = _contextDescription.MaxUpscaleSize;
}
else
{
constants.upscaleSize = dispatchParams.UpscaleSize;
}
// To be updated if resource is larger than the actual image size // To be updated if resource is larger than the actual image size
constants.downscaleFactor = new Vector2((float)constants.renderSize.x / _contextDescription.MaxUpscaleSize.x, (float)constants.renderSize.y / _contextDescription.MaxUpscaleSize.y); constants.downscaleFactor = new Vector2((float)constants.renderSize.x / _contextDescription.MaxUpscaleSize.x, (float)constants.renderSize.y / _contextDescription.MaxUpscaleSize.y);
constants.previousFramePreExposure = constants.preExposure;
constants.preExposure = (dispatchParams.PreExposure != 0) ? dispatchParams.PreExposure : 1.0f;
// Calculate pre-exposure relevant factors
constants.deltaPreExposure = 1.0f;
_previousFramePreExposure = _preExposure;
_preExposure = dispatchParams.PreExposure != 0.0f ? dispatchParams.PreExposure : 1.0f;
if (_previousFramePreExposure > 0.0f)
{
constants.deltaPreExposure = _preExposure / _previousFramePreExposure;
}
// Motion vector data // Motion vector data
Vector2Int motionVectorsTargetSize = (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDisplayResolutionMotionVectors) != 0 ? constants.displaySize : constants.renderSize;
Vector2Int motionVectorsTargetSize = (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDisplayResolutionMotionVectors) != 0 ? constants.upscaleSize : constants.renderSize;
constants.motionVectorScale = dispatchParams.MotionVectorScale / motionVectorsTargetSize; constants.motionVectorScale = dispatchParams.MotionVectorScale / motionVectorsTargetSize;
// Compute jitter cancellation // Compute jitter cancellation
@ -360,14 +382,7 @@ namespace FidelityFX
if (resetAccumulation) if (resetAccumulation)
constants.frameIndex = 0; constants.frameIndex = 0;
else else
constants.frameIndex++;
// Shading change usage of the SPD mip levels
constants.lumaMipLevelToUse = Fsr3UpscalerPass.ShadingChangeMipLevel;
float mipDiv = 2 << constants.lumaMipLevelToUse;
constants.lumaMipDimensions.x = (int)(constants.maxRenderSize.x / mipDiv);
constants.lumaMipDimensions.y = (int)(constants.maxRenderSize.y / mipDiv);
constants.frameIndex += 1.0f;
} }
private Vector4 SetupDeviceDepthToViewSpaceDepthParams(Fsr3Upscaler.DispatchDescription dispatchParams) private Vector4 SetupDeviceDepthToViewSpaceDepthParams(Fsr3Upscaler.DispatchDescription dispatchParams)

Loading…
Cancel
Save