Fix fog to draw Fog Cutoff Distance via a plane, not sphere test

Add support for negative Fog Cutoff Distance on fog to draw it in front of the camera Far Plane, no matter the setup.
Fix hot-reloading Fog shader in Editor.
This commit is contained in:
Wojtek Figat
2025-06-29 20:02:24 +02:00
parent 78d519cb9a
commit 448eb48c23
7 changed files with 39 additions and 47 deletions

View File

@@ -41,11 +41,10 @@ void ExponentialHeightFog::Draw(RenderContext& renderContext)
&& _shader->IsLoaded()
&& renderContext.View.IsPerspectiveProjection())
{
// Prepare
if (_psFog.States[0] == nullptr)
{
// Create pipeline states
_psFog.CreatePipelineStates();
if (!_psFog.States[0]->IsValid())
{
GPUPipelineState::Description psDesc = GPUPipelineState::Description::DefaultFullscreenTriangle;
psDesc.DepthWriteEnable = false;
psDesc.BlendMode.BlendEnable = true;
@@ -59,6 +58,7 @@ void ExponentialHeightFog::Draw(RenderContext& renderContext)
if (_psFog.Create(psDesc, _shader->GetShader(), "PS_Fog"))
{
LOG(Warning, "Cannot create graphics pipeline state object for '{0}'.", ToString());
return;
}
}
@@ -160,7 +160,7 @@ void ExponentialHeightFog::GetExponentialHeightFogData(const RenderView& view, S
result.FogAtViewPosition = density * Math::Pow(2.0f, Math::Clamp(-heightFalloff * (viewHeight - height), -125.f, 126.f));
result.StartDistance = StartDistance;
result.FogMinOpacity = 1.0f - FogMaxOpacity;
result.FogCutoffDistance = FogCutoffDistance;
result.FogCutoffDistance = FogCutoffDistance >= 0 ? FogCutoffDistance : view.Far + FogCutoffDistance;
if (useDirectionalLightInscattering)
{
result.InscatteringLightDirection = -DirectionalInscatteringLight->GetDirection();

View File

@@ -55,9 +55,9 @@ public:
float StartDistance = 0.0f;
/// <summary>
/// Scene elements past this distance will not have fog applied. This is useful for excluding skyboxes which already have fog baked in. Setting this value to 0 disables it.
/// Scene elements past this distance will not have fog applied. This is useful for excluding skyboxes which already have fog baked in. Setting this value to 0 disables it. Negative value sets the cutoff distance relative to the far plane of the camera.
/// </summary>
API_FIELD(Attributes="EditorOrder(60), DefaultValue(0.0f), Limit(0), EditorDisplay(\"Exponential Height Fog\")")
API_FIELD(Attributes="EditorOrder(60), DefaultValue(0.0f), EditorDisplay(\"Exponential Height Fog\")")
float FogCutoffDistance = 0.0f;
public: