Fix Volumetric Fog sampling to use the same code path for depth slices conversion
This commit is contained in:
@@ -27,6 +27,8 @@ struct ExponentialHeightFogData
|
||||
float VolumetricFogMaxDistance;
|
||||
float DirectionalInscatteringStartDistance;
|
||||
float StartDistance;
|
||||
|
||||
float4 VolumetricFogGrid;
|
||||
};
|
||||
|
||||
float4 GetExponentialHeightFog(ExponentialHeightFogData exponentialHeightFog, float3 posWS, float3 camWS, float skipDistance, float sceneDistance)
|
||||
|
||||
@@ -46,7 +46,7 @@ float4 PS_Fog(Quad_VS2PS input) : SV_Target0
|
||||
|
||||
#if VOLUMETRIC_FOG
|
||||
// Sample volumetric fog and mix it in
|
||||
float4 volumetricFog = SampleVolumetricFog(VolumetricFogTexture, worldPos - GBuffer.ViewPos, ExponentialHeightFog.VolumetricFogMaxDistance, input.TexCoord);
|
||||
float4 volumetricFog = SampleVolumetricFog(VolumetricFogTexture, ExponentialHeightFog.VolumetricFogGrid, worldPos - GBuffer.ViewPos, input.TexCoord);
|
||||
fog = CombineVolumetricFog(fog, volumetricFog);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#define VOLUMETRIC_FOG_GRID_Z_LINEAR 1
|
||||
|
||||
float GetDepthFromSlice(float3 gridSliceParameters, float zSlice)
|
||||
float GetDepthFromSlice(float4 gridSliceParameters, float zSlice)
|
||||
{
|
||||
#if VOLUMETRIC_FOG_GRID_Z_LINEAR
|
||||
return zSlice * gridSliceParameters.x;
|
||||
@@ -14,7 +14,7 @@ float GetDepthFromSlice(float3 gridSliceParameters, float zSlice)
|
||||
#endif
|
||||
}
|
||||
|
||||
float GetSliceFromDepth(float3 gridSliceParameters, float sceneDepth)
|
||||
float GetSliceFromDepth(float4 gridSliceParameters, float sceneDepth)
|
||||
{
|
||||
#if VOLUMETRIC_FOG_GRID_Z_LINEAR
|
||||
return sceneDepth * gridSliceParameters.y;
|
||||
@@ -23,11 +23,10 @@ float GetSliceFromDepth(float3 gridSliceParameters, float sceneDepth)
|
||||
#endif
|
||||
}
|
||||
|
||||
float4 SampleVolumetricFog(Texture3D volumetricFogTexture, float3 viewVector, float maxDistance, float2 uv)
|
||||
float4 SampleVolumetricFog(Texture3D volumetricFogTexture, float4 gridSliceParameters, float3 viewVector, float2 uv)
|
||||
{
|
||||
float sceneDepth = length(viewVector);
|
||||
float zSlice = sceneDepth / maxDistance;
|
||||
// TODO: use GetSliceFromDepth instead to handle non-linear depth distributions
|
||||
float zSlice = GetSliceFromDepth(gridSliceParameters, sceneDepth) * gridSliceParameters.w;
|
||||
float3 volumeUV = float3(uv, zSlice);
|
||||
return volumetricFogTexture.SampleLevel(SamplerLinearClamp, volumeUV, 0);
|
||||
}
|
||||
|
||||
@@ -52,8 +52,7 @@ float VolumetricFogMaxDistance;
|
||||
float InverseSquaredLightDistanceBiasScale;
|
||||
|
||||
float4 FogParameters;
|
||||
float3 GridSliceParameters;
|
||||
float Dummy1;
|
||||
float4 GridSliceParameters;
|
||||
|
||||
float4x4 PrevWorldToClip;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user