From 804d6ae6507c66381725a9462786be231b608c71 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Wed, 2 Sep 2020 15:19:49 +0200 Subject: [PATCH 1/3] Skip biquadratic reconstruction when doing filtering --- .../Lighting/AtmosphericScattering/AtmosphericScattering.hlsl | 3 ++- .../Runtime/Lighting/AtmosphericScattering/Fog.cs | 2 ++ .../Runtime/ShaderLibrary/ShaderVariablesGlobal.cs | 2 +- .../Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl index 7b4921dcff6..fb192edd4f7 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl @@ -277,6 +277,7 @@ void EvaluateAtmosphericScattering(PositionInputs posInput, float3 V, out float3 if (_EnableVolumetricFog != 0) { + bool doBiquadraticReconstruction = _VolumetricFilteringEnabled < 0.5f; // Only if filtering is disabled. float4 value = SampleVBuffer(TEXTURE3D_ARGS(_VBufferLighting, s_linear_clamp_sampler), posInput.positionNDC, fogFragDist, @@ -285,7 +286,7 @@ void EvaluateAtmosphericScattering(PositionInputs posInput, float3 V, out float3 _VBufferLightingViewportLimit.xyz, _VBufferDistanceEncodingParams, _VBufferDistanceDecodingParams, - true, true, false); + true, doBiquadraticReconstruction, false); // TODO: add some slowly animated noise (dither?) to the reconstructed value. // TODO: re-enable tone mapping after implementing pre-exposure. diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/Fog.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/Fog.cs index 167bc8930e8..8a1567adbe6 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/Fog.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/Fog.cs @@ -164,6 +164,8 @@ void UpdateShaderVariablesGlobalCBFogParameters(ref ShaderVariablesGlobal cb, HD cb._HeightFogExponents = new Vector2(1.0f / H, H); cb._HeightFogBaseHeight = crBaseHeight; cb._GlobalFogAnisotropy = anisotropy.value; + + cb._VolumetricFilteringEnabled = filter.value ? 1.0f : 0.0f; } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs index 2deeaac0eee..c5aeb442333 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs @@ -129,7 +129,7 @@ unsafe struct ShaderVariablesGlobal public float _HeightFogBaseExtinction; public float _HeightFogBaseHeight; public float _GlobalFogAnisotropy; - public float _Pad3; + public float _VolumetricFilteringEnabled; public Vector2 _HeightFogExponents; // { 1/H, H } public float _Pad4; public float _Pad5; diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl index 38cdd93a601..063c625191c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl @@ -60,7 +60,7 @@ GLOBAL_CBUFFER_START(ShaderVariablesGlobal, b0) float _HeightFogBaseExtinction; float _HeightFogBaseHeight; float _GlobalFogAnisotropy; - float _Pad3; + float _VolumetricFilteringEnabled; float2 _HeightFogExponents; float _Pad4; float _Pad5; From 8ff43af21aa0476e94fd2f6949d847122b664917 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Wed, 2 Sep 2020 15:21:17 +0200 Subject: [PATCH 2/3] changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 3c15ff612bf..abb6635ba3d 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - Preparation pass for RTSSShadows to be supported by render graph. +- Skip biquadratic resampling of vbuffer when volumetric fog filtering is enabled. ## [10.0.0] - 2019-06-10 From b719e2a1451198a098b2e9116d6c90dff5a81295 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Wed, 9 Sep 2020 12:07:09 +0200 Subject: [PATCH 3/3] Use int instead of float (was doing experiment with multiple options) --- .../Lighting/AtmosphericScattering/AtmosphericScattering.hlsl | 2 +- .../Runtime/Lighting/AtmosphericScattering/Fog.cs | 2 +- .../Runtime/ShaderLibrary/ShaderVariablesGlobal.cs | 2 +- .../Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl index fb192edd4f7..a4a651e75cd 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl @@ -277,7 +277,7 @@ void EvaluateAtmosphericScattering(PositionInputs posInput, float3 V, out float3 if (_EnableVolumetricFog != 0) { - bool doBiquadraticReconstruction = _VolumetricFilteringEnabled < 0.5f; // Only if filtering is disabled. + bool doBiquadraticReconstruction = _VolumetricFilteringEnabled == 0; // Only if filtering is disabled. float4 value = SampleVBuffer(TEXTURE3D_ARGS(_VBufferLighting, s_linear_clamp_sampler), posInput.positionNDC, fogFragDist, diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/Fog.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/Fog.cs index 8a1567adbe6..4146f87177d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/Fog.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/Fog.cs @@ -165,7 +165,7 @@ void UpdateShaderVariablesGlobalCBFogParameters(ref ShaderVariablesGlobal cb, HD cb._HeightFogBaseHeight = crBaseHeight; cb._GlobalFogAnisotropy = anisotropy.value; - cb._VolumetricFilteringEnabled = filter.value ? 1.0f : 0.0f; + cb._VolumetricFilteringEnabled = filter.value ? 1 : 0; } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs index c5aeb442333..02d8a8af2f9 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs @@ -129,7 +129,7 @@ unsafe struct ShaderVariablesGlobal public float _HeightFogBaseExtinction; public float _HeightFogBaseHeight; public float _GlobalFogAnisotropy; - public float _VolumetricFilteringEnabled; + public int _VolumetricFilteringEnabled; public Vector2 _HeightFogExponents; // { 1/H, H } public float _Pad4; public float _Pad5; diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl index 063c625191c..e997d139b6f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl @@ -60,7 +60,7 @@ GLOBAL_CBUFFER_START(ShaderVariablesGlobal, b0) float _HeightFogBaseExtinction; float _HeightFogBaseHeight; float _GlobalFogAnisotropy; - float _VolumetricFilteringEnabled; + int _VolumetricFilteringEnabled; float2 _HeightFogExponents; float _Pad4; float _Pad5;