From 86d477263f0eacc88f42142d33a6e3eedf00dfa8 Mon Sep 17 00:00:00 2001 From: Ian Curtis Date: Sun, 15 Oct 2023 17:16:52 +0100 Subject: [PATCH] Scroll fog is like a clear colour for the render target, but can be semi transparent as the tilegen layer can be shown underneath. I assumed that transprent polys would be drawn to the render target for transparent polys but unfortunately the logic does not work. So where else could it be drawn? Well with limited memory it must be draw to the buffer for opaque polys, which means this render target is also blended. --- Src/Graphics/New3D/New3D.cpp | 2 +- Src/Graphics/New3D/R3DFrameBuffers.cpp | 11 +++-------- Src/Graphics/New3D/R3DScrollFog.cpp | 15 +++------------ 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/Src/Graphics/New3D/New3D.cpp b/Src/Graphics/New3D/New3D.cpp index 1360c67..ccec53e 100644 --- a/Src/Graphics/New3D/New3D.cpp +++ b/Src/Graphics/New3D/New3D.cpp @@ -380,7 +380,7 @@ void CNew3D::RenderFrame(void) m_r3dShader.SetLayer(Layer::trans2); m_r3dFrameBuffers.SetFBO(Layer::trans2); RenderScene(pri, renderOverlay, Layer::trans2); - + DisableRenderStates(); if (!hasOverlay) break; // no high priority polys diff --git a/Src/Graphics/New3D/R3DFrameBuffers.cpp b/Src/Graphics/New3D/R3DFrameBuffers.cpp index 27a82fc..b91fd7c 100644 --- a/Src/Graphics/New3D/R3DFrameBuffers.cpp +++ b/Src/Graphics/New3D/R3DFrameBuffers.cpp @@ -227,9 +227,7 @@ void R3DFrameBuffers::AllocShaderBase() void main() { - vec4 colBase = texture(tex1, fsTexCoord); - if(colBase.a < 1.0) discard; - fragColor = colBase; + fragColor = texture(tex1, fsTexCoord); } )glsl"; @@ -302,7 +300,8 @@ void R3DFrameBuffers::Draw() glViewport (0, 0, m_width, m_height); // cover the entire screen glDisable (GL_DEPTH_TEST); // disable depth testing / writing glDisable (GL_CULL_FACE); - glDisable (GL_BLEND); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable (GL_BLEND); for (int i = 0; i < (int)std::size(m_texIDs); i++) { // bind our textures to correct texture units glActiveTexture(GL_TEXTURE0 + i); @@ -313,10 +312,6 @@ void R3DFrameBuffers::Draw() glBindVertexArray (m_vao); DrawBaseLayer (); - - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable (GL_BLEND); - DrawAlphaLayer (); glDisable (GL_BLEND); diff --git a/Src/Graphics/New3D/R3DScrollFog.cpp b/Src/Graphics/New3D/R3DScrollFog.cpp index e4ca6ed..cc2c3b7 100644 --- a/Src/Graphics/New3D/R3DScrollFog.cpp +++ b/Src/Graphics/New3D/R3DScrollFog.cpp @@ -48,16 +48,9 @@ void WriteOutputs(vec4 colour) { vec4 blank = vec4(0.0); - if(colour.a < 1.0) { // some transparency - out0 = blank; - out1 = colour; - out2 = blank; - } - else { // opaque - out0 = colour; - out1 = blank; - out2 = blank; - } + out0 = colour; + out1 = blank; + out2 = blank; } void main() @@ -117,8 +110,6 @@ void R3DScrollFog::DrawScrollFog(float rgba[4], float attenuation, float ambient // some ogl states glDepthMask (GL_FALSE); // disable z writes glDisable (GL_DEPTH_TEST); // disable depth testing - glEnable (GL_BLEND); - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBindVertexArray (m_vao); glUseProgram (m_shaderProgram);