mirror of
https://github.com/jmarshall23/DoomRTX.git
synced 2026-08-17 19:23:51 +02:00
Added denoising.
This commit is contained in:
@@ -1298,7 +1298,7 @@ struct GLState
|
||||
bool motionHistoryReset = true;
|
||||
|
||||
QD3D12UpscalerBackend upscalerBackend = QD3D12_UPSCALER_DLSS;
|
||||
QD3D12UpscalerQuality upscalerQuality = QD3D12_QUALITY_PERFORMANCE;
|
||||
QD3D12UpscalerQuality upscalerQuality = QD3D12_QUALITY_DLAA;
|
||||
bool enableInternalTAA = true;
|
||||
bool enableRayAIDenoise = false;
|
||||
bool enableDLSSRayReconstruction = true;
|
||||
@@ -2513,7 +2513,7 @@ cbuffer DrawCB : register(b0)
|
||||
// Pixel-shader POM depth in UV space. Keep this conservative: legacy idTech
|
||||
// normal maps often do not have a true height channel, so the POM path below
|
||||
// gates fallback height by local detail before applying any offset.
|
||||
#define gParallaxScale (clamp(gNormalMapStrength, 0.0, 4.0) * 0.026)
|
||||
#define gParallaxScale (clamp(gNormalMapStrength, 0.0, 4.0) * 0.020)
|
||||
#define gCameraWorldPos gCameraPomPad.xyz
|
||||
#define gCameraPomValid gCameraPomPad.w
|
||||
#define gUseNeuralPOM gNeuralPomPad.x
|
||||
@@ -2777,6 +2777,14 @@ float3 QD3D12_DecodeTangentSpaceNormal(float3 encodedNormal)
|
||||
return QD3D12_SafeNormalize(n, float3(0.0, 0.0, 1.0));
|
||||
}
|
||||
|
||||
float3 QD3D12_DecodeTangentSpaceNormalScaled(float3 encodedNormal, float strengthScale)
|
||||
{
|
||||
float3 n = encodedNormal * 2.0 - 1.0;
|
||||
n.y *= gNormalMapYSign;
|
||||
n.xy *= max(gNormalMapStrength, 0.0) * saturate(strengthScale);
|
||||
return QD3D12_SafeNormalize(n, float3(0.0, 0.0, 1.0));
|
||||
}
|
||||
|
||||
float QD3D12_HeightFromNormalSample(float4 nm)
|
||||
{
|
||||
// Many legacy normal maps are RGB/DXT uploads with an implicitly forced
|
||||
@@ -2883,7 +2891,8 @@ void QD3D12_BuildPixelTBN(VSOut i, out float3 n, out float3 t, out float3 b)
|
||||
t = derivedT;
|
||||
b = derivedB;
|
||||
}
|
||||
|
||||
)HLSL"
|
||||
R"HLSL(
|
||||
float QD3D12_AuthoredPomAlphaWeight(float alphaValue)
|
||||
{
|
||||
// Alpha == 1 is frequently forced by RGB/DXT uploads in this shim. Treat only
|
||||
@@ -2993,6 +3002,29 @@ float QD3D12_GetPomConfidence(float2 uv)
|
||||
return confidence * confidence * (3.0 - 2.0 * confidence);
|
||||
}
|
||||
|
||||
float QD3D12_GetRegularPomFade(VSOut i, float2 baseUv)
|
||||
{
|
||||
if (gUseNormalMap < 0.5)
|
||||
return 0.0;
|
||||
|
||||
float confidence = QD3D12_GetPomConfidence(baseUv);
|
||||
if (confidence <= 0.03)
|
||||
return 0.0;
|
||||
|
||||
float3 n, t, b;
|
||||
QD3D12_BuildPixelTBN(i, n, t, b);
|
||||
|
||||
float3 rawViewWS = (gCameraPomValid >= 0.5) ? (gCameraWorldPos - i.worldPos) : (-i.worldPos);
|
||||
float3 viewWS = QD3D12_SafeNormalize(rawViewWS, n);
|
||||
float NoV = saturate(dot(n, viewWS));
|
||||
|
||||
float viewDistance = (gCameraPomValid >= 0.5) ? max(length(gCameraWorldPos - i.worldPos), 1.0) : max(abs(i.currClip.w), 1.0);
|
||||
float distanceFade = 1.0 - smoothstep(QD3D12_POM_DISTANCE_NEAR, QD3D12_POM_DISTANCE_FAR, viewDistance);
|
||||
float grazingFade = smoothstep(0.10, 0.26, NoV);
|
||||
|
||||
return saturate(confidence * distanceFade * grazingFade);
|
||||
}
|
||||
|
||||
|
||||
// Keep the runtime network bounded. Most payloads do not need the full 128-wide
|
||||
// MLP in a fixed-function material pass; clamping evaluation here prevents a
|
||||
@@ -3269,7 +3301,7 @@ float2 QD3D12_ComputeParallaxUVWithNeural(VSOut i, float2 baseUv, QD3D12NeuralPO
|
||||
return baseUv;
|
||||
|
||||
float confidence = QD3D12_GetPomConfidence(baseUv);
|
||||
if (confidence <= 0.03)
|
||||
if (confidence <= 0.05)
|
||||
return baseUv;
|
||||
|
||||
float parallaxScale = gParallaxScale * confidence;
|
||||
@@ -3320,7 +3352,7 @@ float2 QD3D12_ComputeParallaxUVWithNeural(VSOut i, float2 baseUv, QD3D12NeuralPO
|
||||
// authored alpha height.
|
||||
float2 parallaxVector = (viewTS.xy / vz) * scale;
|
||||
float parallaxLen = length(parallaxVector);
|
||||
float maxParallaxShift = lerp(0.024, 0.058, confidence);
|
||||
float maxParallaxShift = lerp(0.016, 0.040, confidence);
|
||||
if (parallaxLen > maxParallaxShift && parallaxLen > 1e-6)
|
||||
parallaxVector *= maxParallaxShift / parallaxLen;
|
||||
|
||||
@@ -3358,9 +3390,10 @@ float2 QD3D12_ComputeParallaxUVWithNeural(VSOut i, float2 baseUv, QD3D12NeuralPO
|
||||
// Blend the final result in instead of applying a manual half-vector center
|
||||
// correction. The center correction was the source of several texture-offset
|
||||
// bugs on flat/low-confidence areas.
|
||||
return lerp(baseUv, refinedUv, saturate(distanceFade * grazingFade));
|
||||
return lerp(baseUv, refinedUv, saturate(distanceFade * grazingFade * confidence));
|
||||
}
|
||||
|
||||
)HLSL"
|
||||
R"HLSL(
|
||||
float2 QD3D12_ComputeParallaxUV(VSOut i, float2 baseUv)
|
||||
{
|
||||
QD3D12NeuralPOMResult nr = QD3D12_EvaluateNeuralPOM(i, baseUv);
|
||||
@@ -3515,7 +3548,11 @@ float4 BuildSpecularAlbedoCached(VSOut i, QD3D12MaterialEval m)
|
||||
{
|
||||
if (gUseSpecularMap > 0.0)
|
||||
{
|
||||
float4 spec = gSpecularMap.Sample(gSamp4, m.uv0);
|
||||
float regularPomFade = (gUseNeuralPOM <= 0.5 || m.neural.active <= 0.5)
|
||||
? QD3D12_GetRegularPomFade(i, i.uv0)
|
||||
: 0.0;
|
||||
float2 specUv = lerp(i.uv0, m.uv0, regularPomFade);
|
||||
float4 spec = gSpecularMap.Sample(gSamp4, specUv);
|
||||
float strength = max(gSpecularMapStrength, 0.0);
|
||||
|
||||
// RGB-only legacy spec maps are uploaded with forced opaque alpha. For real
|
||||
@@ -3526,6 +3563,8 @@ float4 BuildSpecularAlbedoCached(VSOut i, QD3D12MaterialEval m)
|
||||
bool alphaLooksForcedOpaque = (spec.a >= 0.999);
|
||||
float alphaMask = alphaLooksForcedOpaque ? 1.0 : saturate(spec.a);
|
||||
float3 specRgb = saturate(spec.rgb) * alphaMask * strength;
|
||||
if (regularPomFade > 0.0)
|
||||
specRgb = min(specRgb, float3(0.82, 0.82, 0.82));
|
||||
return float4(specRgb, 1.0);
|
||||
}
|
||||
|
||||
@@ -3573,7 +3612,12 @@ float3 BuildGBufferNormalCached(VSOut i, QD3D12MaterialEval m)
|
||||
float3 t, b;
|
||||
QD3D12_BuildPixelTBN(i, n, t, b);
|
||||
|
||||
float3 tangentNormal = QD3D12_DecodeTangentSpaceNormal(gNormalMap.Sample(gSamp2, m.uv0).xyz);
|
||||
float regularPomFade = (gUseNeuralPOM <= 0.5 || m.neural.active <= 0.5)
|
||||
? QD3D12_GetRegularPomFade(i, i.uv0)
|
||||
: 0.0;
|
||||
float3 tangentBase = QD3D12_DecodeTangentSpaceNormalScaled(gNormalMap.Sample(gSamp2, i.uv0).xyz, 1.0);
|
||||
float3 tangentPom = QD3D12_DecodeTangentSpaceNormalScaled(gNormalMap.Sample(gSamp2, m.uv0).xyz, lerp(0.70, 1.0, regularPomFade));
|
||||
float3 tangentNormal = QD3D12_SafeNormalize(lerp(tangentBase, tangentPom, regularPomFade), tangentBase);
|
||||
|
||||
return QD3D12_SafeNormalize(
|
||||
tangentNormal.x * t +
|
||||
|
||||
Reference in New Issue
Block a user