|
|
@ -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) |
|
|
|