Fix missing volumetric fog affecting transparent materials

#3436
This commit is contained in:
Wojtek Figat
2025-09-20 00:13:52 +02:00
parent 47711ec5be
commit 92f4327fc2
5 changed files with 18 additions and 3 deletions

View File

@@ -10,7 +10,7 @@
/// <summary>
/// Current materials shader version.
/// </summary>
#define MATERIAL_GRAPH_VERSION 174
#define MATERIAL_GRAPH_VERSION 175
class Material;
class GPUShader;

View File

@@ -2,6 +2,7 @@
#include "MaterialShaderFeatures.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/Textures/GPUTexture.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Renderer/ShadowsPass.h"
@@ -24,18 +25,27 @@ void ForwardShadingFeature::Bind(MaterialShader::BindParameters& params, Span<by
const int32 skyLightShaderRegisterIndex = srv + 1;
const int32 shadowsBufferRegisterIndex = srv + 2;
const int32 shadowMapShaderRegisterIndex = srv + 3;
const int32 volumetricFogTextureRegisterIndex = srv + 4;
const bool canUseShadow = view.Pass != DrawPass::Depth;
// Set fog input
GPUTextureView* volumetricFogTexture = nullptr;
if (cache->Fog)
{
cache->Fog->GetExponentialHeightFogData(view, data.ExponentialHeightFog);
VolumetricFogOptions volumetricFog;
cache->Fog->GetVolumetricFogOptions(volumetricFog);
if (volumetricFog.UseVolumetricFog() && params.RenderContext.Buffers->VolumetricFog)
volumetricFogTexture = params.RenderContext.Buffers->VolumetricFog->ViewVolume();
else
data.ExponentialHeightFog.VolumetricFogMaxDistance = -1.0f;
}
else
{
data.ExponentialHeightFog.FogMinOpacity = 1.0f;
data.ExponentialHeightFog.ApplyDirectionalInscattering = 0.0f;
}
params.GPUContext->BindSR(volumetricFogTextureRegisterIndex, volumetricFogTexture);
// Set directional light input
if (cache->DirectionalLights.HasItems())

View File

@@ -25,7 +25,7 @@ struct ForwardShadingFeature : MaterialShaderFeature
{
enum { MaxLocalLights = 4 };
enum { SRVs = 4 };
enum { SRVs = 5 };
PACK_STRUCT(struct Data
{

View File

@@ -92,4 +92,9 @@ float4 GetExponentialHeightFog(ExponentialHeightFogData exponentialHeightFog, fl
return GetExponentialHeightFog(exponentialHeightFog, posWS, camWS, skipDistance, distance(posWS, camWS));
}
float4 CombineVolumetricFog(float4 fog, float4 volumetricFog)
{
return float4(volumetricFog.rgb + fog.rgb * volumetricFog.a, volumetricFog.a * fog.a);
}
#endif

View File

@@ -63,7 +63,7 @@ float4 PS_Fog(Quad_VS2PS input) : SV_Target0
#if VOLUMETRIC_FOG
// Sample volumetric fog and mix it in
float4 volumetricFog = IntegratedLightScattering.SampleLevel(SamplerLinearClamp, volumeUV, 0);
fog = float4(volumetricFog.rgb + fog.rgb * volumetricFog.a, volumetricFog.a * fog.a);
fog = CombineVolumetricFog(fog, volumetricFog);
#endif
return fog;