diff --git a/binaries/data/mods/mod/shaders/glsl/common/fog.h b/binaries/data/mods/mod/shaders/glsl/common/fog.h index 48b46cb5ec..98f1a898e0 100644 --- a/binaries/data/mods/mod/shaders/glsl/common/fog.h +++ b/binaries/data/mods/mod/shaders/glsl/common/fog.h @@ -3,7 +3,6 @@ vec3 applyFog(vec3 color, vec3 fogColor, vec2 fogParams) { -#if USE_FOG float density = fogParams.x; float maxFog = fogParams.y; @@ -16,9 +15,6 @@ vec3 applyFog(vec3 color, vec3 fogColor, vec2 fogParams) fogFactor = clamp(fogFactor, 0.0, 1.0); return mix(fogColor, color, fogFactor); -#else - return color; -#endif } #endif // INCLUDED_COMMON_FOG diff --git a/source/graphics/LightEnv.cpp b/source/graphics/LightEnv.cpp index b7fb76e216..b4746d24af 100644 --- a/source/graphics/LightEnv.cpp +++ b/source/graphics/LightEnv.cpp @@ -20,6 +20,10 @@ #include "LightEnv.h" #include "maths/MathUtil.h" +#include "ps/CStrInternStatic.h" +#include "renderer/backend/IDeviceCommandContext.h" +#include "renderer/backend/IShaderProgram.h" +#include "renderer/RenderingOptions.h" #include @@ -56,3 +60,22 @@ void CLightEnv::CalculateSunDirection() m_SunDir.Z = scale * cosf(m_Rotation); m_SunDir.Normalize(); } + +void CLightEnv::Bind( + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IShaderProgram* shaderProgram) const +{ + deviceCommandContext->SetUniform( + shaderProgram->GetBindingSlot(str_ambient), m_AmbientColor.AsFloatArray()); + deviceCommandContext->SetUniform( + shaderProgram->GetBindingSlot(str_sunDir), GetSunDir().AsFloatArray()); + deviceCommandContext->SetUniform( + shaderProgram->GetBindingSlot(str_sunColor), m_SunColor.AsFloatArray()); + + deviceCommandContext->SetUniform( + shaderProgram->GetBindingSlot(str_fogColor), + m_FogColor.AsFloatArray()); + deviceCommandContext->SetUniform( + shaderProgram->GetBindingSlot(str_fogParams), + m_FogFactor, g_RenderingOptions.GetFog() ? m_FogMax : 1.0f); +} diff --git a/source/graphics/LightEnv.h b/source/graphics/LightEnv.h index 0b52ee3e08..3dd830b320 100644 --- a/source/graphics/LightEnv.h +++ b/source/graphics/LightEnv.h @@ -25,6 +25,9 @@ #include "graphics/Color.h" #include "maths/Vector3D.h" +namespace Renderer::Backend { class IDeviceCommandContext; } +namespace Renderer::Backend { class IShaderProgram; } + /** * Class CLightEnv: description of a lighting environment - contains all the * necessary parameters for representation of the lighting within a scenario @@ -90,6 +93,10 @@ public: return !(*this == o); } + void Bind( + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IShaderProgram* shaderProgram) const; + private: friend class CMapWriter; friend class CMapReader; diff --git a/source/graphics/ParticleEmitter.cpp b/source/graphics/ParticleEmitter.cpp index 73ec66c4ba..314b27f497 100644 --- a/source/graphics/ParticleEmitter.cpp +++ b/source/graphics/ParticleEmitter.cpp @@ -224,14 +224,7 @@ void CParticleEmitter::Bind( shader->GetBindingSlot(str_losTransform), los.GetTextureMatrix()[0], los.GetTextureMatrix()[12]); - const CLightEnv& lightEnv = g_Renderer.GetSceneRenderer().GetLightEnv(); - - deviceCommandContext->SetUniform( - shader->GetBindingSlot(str_sunColor), lightEnv.m_SunColor.AsFloatArray()); - deviceCommandContext->SetUniform( - shader->GetBindingSlot(str_fogColor), lightEnv.m_FogColor.AsFloatArray()); - deviceCommandContext->SetUniform( - shader->GetBindingSlot(str_fogParams), lightEnv.m_FogFactor, lightEnv.m_FogMax); + g_Renderer.GetSceneRenderer().GetLightEnv().Bind(deviceCommandContext, shader); deviceCommandContext->SetTexture( shader->GetBindingSlot(str_baseTex), m_Type->m_Texture->GetBackendTexture()); diff --git a/source/ps/CStrInternStatic.h b/source/ps/CStrInternStatic.h index 33f91ebcd0..3deb660be4 100644 --- a/source/ps/CStrInternStatic.h +++ b/source/ps/CStrInternStatic.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2024 Wildfire Games. +/* Copyright (C) 2025 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -76,7 +76,6 @@ X(USE_REFRACTION) X(USE_SHADOW) X(USE_SHADOW_PCF) X(USE_SHADOW_SAMPLER) -X(USE_FOG) X(WATERTYPE_CLAP) X(WATERTYPE_LAKE) X2(_emptystring, "") diff --git a/source/renderer/RenderModifiers.cpp b/source/renderer/RenderModifiers.cpp index 9b56149529..adc05fda6a 100644 --- a/source/renderer/RenderModifiers.cpp +++ b/source/renderer/RenderModifiers.cpp @@ -83,24 +83,7 @@ void ShaderRenderModifier::BeginPass( GetShadowMap()->BindTo(deviceCommandContext, shader); if (GetLightEnv()) - { - deviceCommandContext->SetUniform( - shader->GetBindingSlot(str_ambient), - GetLightEnv()->m_AmbientColor.AsFloatArray()); - deviceCommandContext->SetUniform( - shader->GetBindingSlot(str_sunDir), - GetLightEnv()->GetSunDir().AsFloatArray()); - deviceCommandContext->SetUniform( - shader->GetBindingSlot(str_sunColor), - GetLightEnv()->m_SunColor.AsFloatArray()); - - deviceCommandContext->SetUniform( - shader->GetBindingSlot(str_fogColor), - GetLightEnv()->m_FogColor.AsFloatArray()); - deviceCommandContext->SetUniform( - shader->GetBindingSlot(str_fogParams), - GetLightEnv()->m_FogFactor, GetLightEnv()->m_FogMax); - } + GetLightEnv()->Bind(deviceCommandContext, shader); if (shader->GetBindingSlot(str_losTex) >= 0) { diff --git a/source/renderer/SceneRenderer.cpp b/source/renderer/SceneRenderer.cpp index 8c1f8657c2..317574a0e8 100644 --- a/source/renderer/SceneRenderer.cpp +++ b/source/renderer/SceneRenderer.cpp @@ -241,9 +241,6 @@ void CSceneRenderer::ReloadShaders(Renderer::Backend::IDevice* device) m->globalContext.Add(str_RENDER_DEBUG_MODE, RenderDebugModeEnum::ToString(g_RenderingOptions.GetRenderDebugMode())); - if (device->GetBackend() != Renderer::Backend::Backend::GL_ARB && g_RenderingOptions.GetFog()) - m->globalContext.Add(str_USE_FOG, str_1); - m->Model.ModShader = LitRenderModifierPtr(new ShaderRenderModifier()); ENSURE(g_RenderingOptions.GetRenderPath() != RenderPath::FIXED); diff --git a/source/renderer/TerrainRenderer.cpp b/source/renderer/TerrainRenderer.cpp index 7823bc5da4..987bde0274 100644 --- a/source/renderer/TerrainRenderer.cpp +++ b/source/renderer/TerrainRenderer.cpp @@ -305,22 +305,7 @@ void TerrainRenderer::PrepareShader( shader->GetBindingSlot(str_losTransform), los.GetTextureMatrix()[0], los.GetTextureMatrix()[12]); - deviceCommandContext->SetUniform( - shader->GetBindingSlot(str_ambient), - lightEnv.m_AmbientColor.AsFloatArray()); - deviceCommandContext->SetUniform( - shader->GetBindingSlot(str_sunColor), - lightEnv.m_SunColor.AsFloatArray()); - deviceCommandContext->SetUniform( - shader->GetBindingSlot(str_sunDir), - lightEnv.GetSunDir().AsFloatArray()); - - deviceCommandContext->SetUniform( - shader->GetBindingSlot(str_fogColor), - lightEnv.m_FogColor.AsFloatArray()); - deviceCommandContext->SetUniform( - shader->GetBindingSlot(str_fogParams), - lightEnv.m_FogFactor, lightEnv.m_FogMax); + lightEnv.Bind(deviceCommandContext, shader); } void TerrainRenderer::RenderTerrainShader( @@ -584,12 +569,6 @@ bool TerrainRenderer::RenderFancyWater( waterManager.m_ReflectionMatrix.AsFloatArray()); } - deviceCommandContext->SetUniform( - fancyWaterShader->GetBindingSlot(str_ambient), lightEnv.m_AmbientColor.AsFloatArray()); - deviceCommandContext->SetUniform( - fancyWaterShader->GetBindingSlot(str_sunDir), lightEnv.GetSunDir().AsFloatArray()); - deviceCommandContext->SetUniform( - fancyWaterShader->GetBindingSlot(str_sunColor), lightEnv.m_SunColor.AsFloatArray()); deviceCommandContext->SetUniform( fancyWaterShader->GetBindingSlot(str_color), waterManager.m_WaterColor.AsFloatArray()); deviceCommandContext->SetUniform( @@ -610,12 +589,8 @@ bool TerrainRenderer::RenderFancyWater( fancyWaterShader->GetBindingSlot(str_cameraPos), camera.GetOrientation().GetTranslation().AsFloatArray()); - deviceCommandContext->SetUniform( - fancyWaterShader->GetBindingSlot(str_fogColor), - lightEnv.m_FogColor.AsFloatArray()); - deviceCommandContext->SetUniform( - fancyWaterShader->GetBindingSlot(str_fogParams), - lightEnv.m_FogFactor, lightEnv.m_FogMax); + lightEnv.Bind(deviceCommandContext, fancyWaterShader); + deviceCommandContext->SetUniform( fancyWaterShader->GetBindingSlot(str_time), static_cast(time)); const float scale{g_Renderer.GetPostprocManager().IsEnabled()