|
|
@ -320,7 +320,10 @@ namespace FidelityFX.FSR2 |
|
|
constants.viewSpaceToMetersFactor = (dispatchParams.ViewSpaceToMetersFactor > 0.0f) ? dispatchParams.ViewSpaceToMetersFactor : 1.0f; |
|
|
constants.viewSpaceToMetersFactor = (dispatchParams.ViewSpaceToMetersFactor > 0.0f) ? dispatchParams.ViewSpaceToMetersFactor : 1.0f; |
|
|
|
|
|
|
|
|
// 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); |
|
|
|
|
|
|
|
|
bool inverted = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInverted) != 0; |
|
|
|
|
|
bool infinite = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInfinite) != 0; |
|
|
|
|
|
constants.deviceToViewDepth = FfxUtils.SetupDeviceDepthToViewSpaceDepthParams( |
|
|
|
|
|
dispatchParams.RenderSize, dispatchParams.CameraNear, dispatchParams.CameraFar, dispatchParams.CameraFovAngleVertical, inverted, infinite); |
|
|
|
|
|
|
|
|
// 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.DisplaySize.x, (float)constants.renderSize.y / _contextDescription.DisplaySize.y); |
|
|
constants.downscaleFactor = new Vector2((float)constants.renderSize.x / _contextDescription.DisplaySize.x, (float)constants.renderSize.y / _contextDescription.DisplaySize.y); |
|
|
@ -367,39 +370,6 @@ namespace FidelityFX.FSR2 |
|
|
constants.lumaMipDimensions.x = (int)(constants.maxRenderSize.x / mipDiv); |
|
|
constants.lumaMipDimensions.x = (int)(constants.maxRenderSize.x / mipDiv); |
|
|
constants.lumaMipDimensions.y = (int)(constants.maxRenderSize.y / mipDiv); |
|
|
constants.lumaMipDimensions.y = (int)(constants.maxRenderSize.y / mipDiv); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private Vector4 SetupDeviceDepthToViewSpaceDepthParams(Fsr2.DispatchDescription dispatchParams) |
|
|
|
|
|
{ |
|
|
|
|
|
bool inverted = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInverted) != 0; |
|
|
|
|
|
bool infinite = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInfinite) != 0; |
|
|
|
|
|
|
|
|
|
|
|
// make sure it has no impact if near and far plane values are swapped in dispatch params
|
|
|
|
|
|
// the flags "inverted" and "infinite" will decide what transform to use
|
|
|
|
|
|
float min = Mathf.Min(dispatchParams.CameraNear, dispatchParams.CameraFar); |
|
|
|
|
|
float max = Mathf.Max(dispatchParams.CameraNear, dispatchParams.CameraFar); |
|
|
|
|
|
|
|
|
|
|
|
if (inverted) |
|
|
|
|
|
{ |
|
|
|
|
|
(min, max) = (max, min); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
float q = max / (min - max); |
|
|
|
|
|
float d = -1.0f; |
|
|
|
|
|
|
|
|
|
|
|
Vector4 matrixElemC = new Vector4(q, -1.0f - Mathf.Epsilon, q, 0.0f + Mathf.Epsilon); |
|
|
|
|
|
Vector4 matrixElemE = new Vector4(q * min, -min - Mathf.Epsilon, q * min, max); |
|
|
|
|
|
|
|
|
|
|
|
// Revert x and y coords
|
|
|
|
|
|
float aspect = (float)dispatchParams.RenderSize.x / dispatchParams.RenderSize.y; |
|
|
|
|
|
float cotHalfFovY = Mathf.Cos(0.5f * dispatchParams.CameraFovAngleVertical) / Mathf.Sin(0.5f * dispatchParams.CameraFovAngleVertical); |
|
|
|
|
|
|
|
|
|
|
|
int matrixIndex = (inverted ? 2 : 0) + (infinite ? 1 : 0); |
|
|
|
|
|
return new Vector4( |
|
|
|
|
|
d * matrixElemC[matrixIndex], |
|
|
|
|
|
matrixElemE[matrixIndex], |
|
|
|
|
|
aspect / cotHalfFovY, |
|
|
|
|
|
1.0f / cotHalfFovY); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void SetupRcasConstants(Fsr2.DispatchDescription dispatchParams) |
|
|
private void SetupRcasConstants(Fsr2.DispatchDescription dispatchParams) |
|
|
{ |
|
|
{ |
|
|
|