|
|
@ -17,6 +17,7 @@ namespace FidelityFX |
|
|
private ComputeShader _generateReactiveShader; |
|
|
private ComputeShader _generateReactiveShader; |
|
|
private ComputeShader _rcasShader; |
|
|
private ComputeShader _rcasShader; |
|
|
private ComputeShader _computeLuminancePyramidShader; |
|
|
private ComputeShader _computeLuminancePyramidShader; |
|
|
|
|
|
private ComputeShader _tcrAutogenShader; |
|
|
|
|
|
|
|
|
private ComputeBuffer _fsr2ConstantsBuffer; |
|
|
private ComputeBuffer _fsr2ConstantsBuffer; |
|
|
private readonly Fsr2Constants[] _fsr2ConstantsArray = { new Fsr2Constants() }; |
|
|
private readonly Fsr2Constants[] _fsr2ConstantsArray = { new Fsr2Constants() }; |
|
|
@ -37,9 +38,6 @@ namespace FidelityFX |
|
|
|
|
|
|
|
|
// Set defaults
|
|
|
// Set defaults
|
|
|
_fsr2ConstantsArray[0].displaySize = _contextDescription.DisplaySize; |
|
|
_fsr2ConstantsArray[0].displaySize = _contextDescription.DisplaySize; |
|
|
_fsr2ConstantsArray[0].displaySizeRcp = new Vector2( |
|
|
|
|
|
1.0f / _contextDescription.DisplaySize.x, |
|
|
|
|
|
1.0f / _contextDescription.DisplaySize.y); |
|
|
|
|
|
|
|
|
|
|
|
// Generate the data for the LUT
|
|
|
// Generate the data for the LUT
|
|
|
const uint lanczos2LutWidth = 128; |
|
|
const uint lanczos2LutWidth = 128; |
|
|
@ -52,6 +50,12 @@ namespace FidelityFX |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
InitShaders(); |
|
|
InitShaders(); |
|
|
|
|
|
|
|
|
|
|
|
// TODO: create resources, i.e. render textures used for intermediate results.
|
|
|
|
|
|
// Note that "aliasable" resources should be equivalent to GetTemporary render textures
|
|
|
|
|
|
// UAVs *may* be an issue with the PS4 not handling simultaneous reading and writing to an RT properly
|
|
|
|
|
|
// Unity does have Graphics.SetRandomWriteTarget for enabling UAV on ComputeBuffers or RTs
|
|
|
|
|
|
// Unity doesn't do 1D textures so just default to Texture2D
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void InitShaders() |
|
|
private void InitShaders() |
|
|
@ -64,6 +68,7 @@ namespace FidelityFX |
|
|
LoadComputeShader("FSR2/ffx_fsr2_lock_pass", ref _lockShader); |
|
|
LoadComputeShader("FSR2/ffx_fsr2_lock_pass", ref _lockShader); |
|
|
LoadComputeShader("FSR2/ffx_fsr2_accumulate_pass", ref _accumulateShader); |
|
|
LoadComputeShader("FSR2/ffx_fsr2_accumulate_pass", ref _accumulateShader); |
|
|
LoadComputeShader("FSR2/ffx_fsr2_autogen_reactive_pass", ref _generateReactiveShader); |
|
|
LoadComputeShader("FSR2/ffx_fsr2_autogen_reactive_pass", ref _generateReactiveShader); |
|
|
|
|
|
LoadComputeShader("FSR2/ffx_fsr2_tcr_autogen_pass", ref _tcrAutogenShader); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void LoadComputeShader(string name, ref ComputeShader shaderRef) |
|
|
private void LoadComputeShader(string name, ref ComputeShader shaderRef) |
|
|
@ -85,7 +90,7 @@ namespace FidelityFX |
|
|
|
|
|
|
|
|
// Run the RCAS sharpening filter on the upscaled image
|
|
|
// Run the RCAS sharpening filter on the upscaled image
|
|
|
int rcasKernel = _rcasShader.FindKernel("CS"); |
|
|
int rcasKernel = _rcasShader.FindKernel("CS"); |
|
|
_rcasShader.SetTexture(rcasKernel, "r_exposure", dispatchDescription.Exposure); |
|
|
|
|
|
|
|
|
_rcasShader.SetTexture(rcasKernel, "r_input_exposure", dispatchDescription.Exposure); |
|
|
_rcasShader.SetTexture(rcasKernel, "r_rcas_input", dispatchDescription.Input); |
|
|
_rcasShader.SetTexture(rcasKernel, "r_rcas_input", dispatchDescription.Input); |
|
|
_rcasShader.SetTexture(rcasKernel, "rw_upscaled_output", dispatchDescription.Output); |
|
|
_rcasShader.SetTexture(rcasKernel, "rw_upscaled_output", dispatchDescription.Output); |
|
|
_rcasShader.SetConstantBuffer("cbFSR2", _fsr2ConstantsBuffer, 0, Marshal.SizeOf<Fsr2Constants>()); |
|
|
_rcasShader.SetConstantBuffer("cbFSR2", _fsr2ConstantsBuffer, 0, Marshal.SizeOf<Fsr2Constants>()); |
|
|
@ -128,27 +133,25 @@ namespace FidelityFX |
|
|
private struct Fsr2Constants |
|
|
private struct Fsr2Constants |
|
|
{ |
|
|
{ |
|
|
public Vector2Int renderSize; |
|
|
public Vector2Int renderSize; |
|
|
|
|
|
public Vector2Int maxRenderSize; |
|
|
public Vector2Int displaySize; |
|
|
public Vector2Int displaySize; |
|
|
public uint lumaMipDimensionsX, lumaMipDimensionsY; |
|
|
|
|
|
public uint lumaMipLevelToUse; |
|
|
|
|
|
public uint frameIndex; |
|
|
|
|
|
public Vector2 displaySizeRcp; |
|
|
|
|
|
public Vector2 jitterOffset; |
|
|
|
|
|
|
|
|
public Vector2Int inputColorResourceDimensions; |
|
|
|
|
|
public Vector2Int lumaMipDimensions; |
|
|
|
|
|
public int lumaMipLevelToUse; |
|
|
|
|
|
public int frameIndex; |
|
|
|
|
|
|
|
|
public Vector4 deviceToViewDepth; |
|
|
public Vector4 deviceToViewDepth; |
|
|
public Vector2 depthClipUVScale; |
|
|
|
|
|
public Vector2 postLockStatusUVScale; |
|
|
|
|
|
public Vector2 reactiveMaskDimRcp; |
|
|
|
|
|
|
|
|
public Vector2 jitterOffset; |
|
|
public Vector2 motionVectorScale; |
|
|
public Vector2 motionVectorScale; |
|
|
public Vector2 downscaleFactor; |
|
|
public Vector2 downscaleFactor; |
|
|
|
|
|
public Vector2 motionVectorJitterCancellation; |
|
|
public float preExposure; |
|
|
public float preExposure; |
|
|
|
|
|
public float previousFramePreExposure; |
|
|
public float tanHalfFOV; |
|
|
public float tanHalfFOV; |
|
|
public Vector2 motionVectorJitterCancellation; |
|
|
|
|
|
public float jitterPhaseCount; |
|
|
public float jitterPhaseCount; |
|
|
public float lockInitialLifetime; |
|
|
|
|
|
public float lockTickDelta; |
|
|
|
|
|
public float deltaTime; |
|
|
public float deltaTime; |
|
|
public float dynamicResChangeFactor; |
|
|
public float dynamicResChangeFactor; |
|
|
public float lumaMipRcp; |
|
|
|
|
|
|
|
|
public float viewSpaceToMetersFactor; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Serializable, StructLayout(LayoutKind.Sequential)] |
|
|
[Serializable, StructLayout(LayoutKind.Sequential)] |
|
|
|