From c5f9a3ad2607dd26700ac9970425ca3b9e26776b Mon Sep 17 00:00:00 2001 From: Ian Curtis Date: Tue, 24 Oct 2023 10:17:15 +0100 Subject: [PATCH] Amend the ambient fog logic to be disabled if fog density/start is set to zero. This fixes a regression where the sky stops drawing in lost world. Rewrite the scroll fog shader slightly. Scroll fog is a 2d layer, it has no depth, or can be considered to be drawn at infinity, therefore is not effected by the viewport light. The scroll attenatuion value also I think attenatutes the scroll fog alpha value. This fixes various effects in emergency call ambulance. --- Src/Graphics/New3D/New3D.cpp | 13 +++++++++--- Src/Graphics/New3D/R3DScrollFog.cpp | 33 +++-------------------------- Src/Graphics/New3D/R3DScrollFog.h | 4 +--- 3 files changed, 14 insertions(+), 36 deletions(-) diff --git a/Src/Graphics/New3D/New3D.cpp b/Src/Graphics/New3D/New3D.cpp index ee0c583..1a5bb2e 100644 --- a/Src/Graphics/New3D/New3D.cpp +++ b/Src/Graphics/New3D/New3D.cpp @@ -207,7 +207,7 @@ void CNew3D::DrawScrollFog() rgba[2] = vp.fogParams[2]; rgba[3] = vp.scrollFog; glViewport(vp.x, vp.y, vp.width, vp.height); - m_r3dScrollFog.DrawScrollFog(rgba, vp.scrollAtt, vp.fogParams[6], vp.spotFogColor, vp.spotEllipse); + m_r3dScrollFog.DrawScrollFog(rgba, vp.scrollAtt, vp.fogParams[6]); } } } @@ -223,22 +223,29 @@ void CNew3D::DrawAmbientFog() // Does this work with scroll fog? Well technically scroll fog already takes into account the fog ambient as it darkens the fog colour // Let's pick the lowest fog ambient value + // Check for fog density or a fog start value, otherwise the effect seems to be disabled (lost world) float fogAmbient = 1.0f; Node* nodePtr = nullptr; for (auto& n : m_nodes) { + + // check to see if we have a fog density or fog start + if (n.viewport.fogParams[3] <= 0.0f && n.viewport.fogParams[4] <= 0.0f) { + continue; + } + if (n.viewport.fogParams[6] < fogAmbient) { nodePtr = &n; fogAmbient = n.viewport.fogParams[6]; } } - if (fogAmbient < 1.0f) { + if (nodePtr) { auto& vp = nodePtr->viewport; float rgba[] = { 0.0f, 0.0f, 0.0f, 1.0f - fogAmbient }; glViewport(vp.x, vp.y, vp.width, vp.height); - m_r3dScrollFog.DrawScrollFog(rgba, vp.scrollAtt, vp.fogParams[6], vp.spotFogColor, vp.spotEllipse); + m_r3dScrollFog.DrawScrollFog(rgba, 0.0f, 1.0f); } } diff --git a/Src/Graphics/New3D/R3DScrollFog.cpp b/Src/Graphics/New3D/R3DScrollFog.cpp index cc2c3b7..4469ec5 100644 --- a/Src/Graphics/New3D/R3DScrollFog.cpp +++ b/Src/Graphics/New3D/R3DScrollFog.cpp @@ -26,18 +26,6 @@ static const char *fragmentShaderFog = R"glsl( uniform float fogAttenuation; uniform float fogAmbient; uniform vec4 fogColour; -uniform vec3 spotFogColor; -uniform vec4 spotEllipse; - -// Spotlight on fog -float ellipse; -vec2 position, size; -vec3 lSpotFogColor; - -// Scroll fog -float lfogAttenuation; -vec3 lFogColor; -vec4 scrollFog; // outputs layout(location = 0) out vec4 out0; // opaque @@ -56,21 +44,10 @@ void WriteOutputs(vec4 colour) void main() { // Scroll fog base color - lFogColor = fogColour.rgb * fogAmbient; - - // Spotlight on fog (area) - position = spotEllipse.xy; - size = spotEllipse.zw; - ellipse = length((gl_FragCoord.xy - position) / size); - ellipse = ellipse * ellipse; // decay rate = square of distance from center - ellipse = 1.0 - ellipse; // invert - ellipse = max(0.0, ellipse); // clamp - - // Spotlight on fog (color) - lSpotFogColor = mix(spotFogColor * ellipse * fogColour.rgb, vec3(0.0), fogAttenuation); + vec3 lFogColor = fogColour.rgb * fogAmbient; // Scroll fog density - scrollFog = vec4(lFogColor + lSpotFogColor, fogColour.a); + vec4 scrollFog = vec4(lFogColor, fogColour.a * (1.0 - fogAttenuation)); // Final Color WriteOutputs(scrollFog); @@ -105,7 +82,7 @@ R3DScrollFog::~R3DScrollFog() } } -void R3DScrollFog::DrawScrollFog(float rgba[4], float attenuation, float ambient, float *spotRGB, float *spotEllipse) +void R3DScrollFog::DrawScrollFog(float rgba[4], float attenuation, float ambient) { // some ogl states glDepthMask (GL_FALSE); // disable z writes @@ -116,8 +93,6 @@ void R3DScrollFog::DrawScrollFog(float rgba[4], float attenuation, float ambient glUniform4fv (m_locFogColour, 1, rgba); glUniform1f (m_locFogAttenuation, attenuation); glUniform1f (m_locFogAmbient, ambient); - glUniform3fv (m_locSpotFogColor, 1, spotRGB); - glUniform4fv (m_locSpotEllipse, 1, spotEllipse); glDrawArrays (GL_TRIANGLE_STRIP, 0, 4); @@ -135,8 +110,6 @@ void R3DScrollFog::AllocResources() m_locFogColour = glGetUniformLocation(m_shaderProgram, "fogColour"); m_locFogAttenuation = glGetUniformLocation(m_shaderProgram, "fogAttenuation"); m_locFogAmbient = glGetUniformLocation(m_shaderProgram, "fogAmbient"); - m_locSpotFogColor = glGetUniformLocation(m_shaderProgram, "spotFogColor"); - m_locSpotEllipse = glGetUniformLocation(m_shaderProgram, "spotEllipse"); } void R3DScrollFog::DeallocResources() diff --git a/Src/Graphics/New3D/R3DScrollFog.h b/Src/Graphics/New3D/R3DScrollFog.h index 6e93449..8593a40 100644 --- a/Src/Graphics/New3D/R3DScrollFog.h +++ b/Src/Graphics/New3D/R3DScrollFog.h @@ -13,7 +13,7 @@ public: R3DScrollFog(const Util::Config::Node &config); ~R3DScrollFog(); - void DrawScrollFog(float rbga[4], float attenuation, float ambient, float *spotRGB, float *spotEllipse); + void DrawScrollFog(float rbga[4], float attenuation, float ambient); private: @@ -29,8 +29,6 @@ private: GLint m_locFogColour; GLint m_locFogAttenuation; GLint m_locFogAmbient; - GLint m_locSpotFogColor; - GLint m_locSpotEllipse; GLuint m_vao; };