From d136aec00fba11010d414a3921d65e1d8bf1c12e Mon Sep 17 00:00:00 2001 From: water111 <48171810+water111@users.noreply.github.com> Date: Wed, 16 Mar 2022 21:28:02 -0400 Subject: [PATCH] [graphics] fix ocean alpha and ocean near depth (#1236) * fix up some graphics bugs * less of a hack fix --- .../opengl_renderer/DirectRenderer.cpp | 28 ++++++++----------- .../opengl_renderer/DirectRenderer2.cpp | 12 ++++---- .../background/background_common.cpp | 10 +++---- .../opengl_renderer/ocean/OceanTexture.cpp | 2 +- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/game/graphics/opengl_renderer/DirectRenderer.cpp b/game/graphics/opengl_renderer/DirectRenderer.cpp index d6d1d5cae..62242fc4d 100644 --- a/game/graphics/opengl_renderer/DirectRenderer.cpp +++ b/game/graphics/opengl_renderer/DirectRenderer.cpp @@ -361,7 +361,8 @@ void DirectRenderer::update_gl_blend() { // (Cs - Cd) * As + Cd // Cs * As + (1 - As) * Cd // s, d - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); glBlendEquation(GL_FUNC_ADD); } else if (state.a == GsAlpha::BlendMode::SOURCE && state.b == GsAlpha::BlendMode::ZERO_OR_FIXED && @@ -370,7 +371,7 @@ void DirectRenderer::update_gl_blend() { // Cs * As + (1) * Cd // s, d ASSERT(state.fix == 0); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ZERO); glBlendEquation(GL_FUNC_ADD); } else if (state.a == GsAlpha::BlendMode::ZERO_OR_FIXED && state.b == GsAlpha::BlendMode::SOURCE && state.c == GsAlpha::BlendMode::SOURCE && @@ -378,26 +379,26 @@ void DirectRenderer::update_gl_blend() { // (0 - Cs) * As + Cd // Cd - Cs * As // s, d - glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ZERO); glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); } else if (state.a == GsAlpha::BlendMode::SOURCE && state.b == GsAlpha::BlendMode::DEST && state.c == GsAlpha::BlendMode::ZERO_OR_FIXED && state.d == GsAlpha::BlendMode::DEST) { // (Cs - Cd) * fix + Cd // Cs * fix + (1 - fx) * Cd - glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA); + glBlendFuncSeparate(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_ONE, GL_ZERO); glBlendColor(0, 0, 0, state.fix / 127.f); glBlendEquation(GL_FUNC_ADD); } else if (state.a == GsAlpha::BlendMode::SOURCE && state.b == GsAlpha::BlendMode::SOURCE && state.c == GsAlpha::BlendMode::SOURCE && state.d == GsAlpha::BlendMode::SOURCE) { // this is very weird... - glBlendFunc(GL_ONE, GL_ZERO); + glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO); glBlendEquation(GL_FUNC_ADD); } else if (state.a == GsAlpha::BlendMode::SOURCE && state.b == GsAlpha::BlendMode::ZERO_OR_FIXED && state.c == GsAlpha::BlendMode::DEST && state.d == GsAlpha::BlendMode::DEST) { // (Cs - 0) * Ad + Cd - glBlendFunc(GL_DST_ALPHA, GL_ONE); + glBlendFuncSeparate(GL_DST_ALPHA, GL_ONE, GL_ONE, GL_ZERO); glBlendEquation(GL_FUNC_ADD); m_ogl.color_mult = 0.5; } else { @@ -412,16 +413,9 @@ void DirectRenderer::update_gl_blend() { if (state.a == GsAlpha::BlendMode::SOURCE && state.b == GsAlpha::BlendMode::DEST && state.c == GsAlpha::BlendMode::SOURCE && state.d == GsAlpha::BlendMode::DEST) { if (m_prim_gl_state.fogging_enable) { - // first draw. - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - m_ogl.alpha_mult = .5f; - glBlendEquation(GL_FUNC_ADD); } else { - // second draw. - m_ogl.alpha_mult = 2.f; - glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_SRC_ALPHA, GL_ZERO); - glBlendEquation(GL_FUNC_ADD); + glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_ONE, GL_ZERO); } } } @@ -457,7 +451,10 @@ void DirectRenderer::update_gl_test() { ASSERT(false); } - if (state.depth_writes) { + bool alpha_trick_to_disable = m_test_state.alpha_test_enable && + m_test_state.alpha_test == GsTest::AlphaTest::NEVER && + m_test_state.afail == GsTest::AlphaFail::FB_ONLY; + if (state.depth_writes && !alpha_trick_to_disable) { glDepthMask(GL_TRUE); } else { glDepthMask(GL_FALSE); @@ -831,7 +828,6 @@ void DirectRenderer::handle_zbuf1(u64 val, bool write = !x.zmsk(); // ASSERT(write); - if (write != m_test_state.depth_writes) { m_stats.flush_from_zbuf++; flush_pending(render_state, prof); diff --git a/game/graphics/opengl_renderer/DirectRenderer2.cpp b/game/graphics/opengl_renderer/DirectRenderer2.cpp index 7f4d31533..b495c29df 100644 --- a/game/graphics/opengl_renderer/DirectRenderer2.cpp +++ b/game/graphics/opengl_renderer/DirectRenderer2.cpp @@ -251,35 +251,35 @@ void DirectRenderer2::setup_opengl_for_draw_mode(const Draw& draw, // (Cs - Cd) * As + Cd // Cs * As + (1 - As) * Cd // s, d - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); glBlendEquation(GL_FUNC_ADD); } else if (draw.mode.get_alpha_blend() == DrawMode::AlphaBlend::SRC_0_SRC_DST) { // (Cs - 0) * As + Cd // Cs * As + (1) * Cd // s, d ASSERT(draw.fix == 0); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ZERO); glBlendEquation(GL_FUNC_ADD); } else if (draw.mode.get_alpha_blend() == DrawMode::AlphaBlend::ZERO_SRC_SRC_DST) { // (0 - Cs) * As + Cd // Cd - Cs * As // s, d - glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ZERO); glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); } else if (draw.mode.get_alpha_blend() == DrawMode::AlphaBlend::SRC_DST_FIX_DST) { // (Cs - Cd) * fix + Cd // Cs * fix + (1 - fx) * Cd - glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA); + glBlendFuncSeparate(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_ONE, GL_ZERO); glBlendColor(0, 0, 0, draw.fix / 127.f); glBlendEquation(GL_FUNC_ADD); } else if (draw.mode.get_alpha_blend() == DrawMode::AlphaBlend::SRC_SRC_SRC_SRC) { // this is very weird... // Cs - glBlendFunc(GL_ONE, GL_ZERO); + glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO); glBlendEquation(GL_FUNC_ADD); } else if (draw.mode.get_alpha_blend() == DrawMode::AlphaBlend::SRC_0_DST_DST) { // (Cs - 0) * Ad + Cd - glBlendFunc(GL_DST_ALPHA, GL_ONE); + glBlendFuncSeparate(GL_DST_ALPHA, GL_ONE, GL_ONE, GL_ZERO); glBlendEquation(GL_FUNC_ADD); color_mult = 0.5; } else { diff --git a/game/graphics/opengl_renderer/background/background_common.cpp b/game/graphics/opengl_renderer/background/background_common.cpp index 92027c573..aefd747f0 100644 --- a/game/graphics/opengl_renderer/background/background_common.cpp +++ b/game/graphics/opengl_renderer/background/background_common.cpp @@ -37,26 +37,26 @@ DoubleDraw setup_opengl_from_draw_mode(DrawMode mode, u32 tex_unit, bool mipmap) switch (mode.get_alpha_blend()) { case DrawMode::AlphaBlend::SRC_DST_SRC_DST: glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); break; case DrawMode::AlphaBlend::SRC_0_SRC_DST: glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ZERO); break; case DrawMode::AlphaBlend::SRC_0_FIX_DST: glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_ONE, GL_ONE); + glBlendFuncSeparate(GL_ONE, GL_ONE, GL_ONE, GL_ZERO); break; case DrawMode::AlphaBlend::SRC_DST_FIX_DST: // Cv = (Cs - Cd) * FIX + Cd // Cs * FIX * 0.5 // Cd * FIX * 0.5 glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_CONSTANT_COLOR, GL_CONSTANT_COLOR); + glBlendFuncSeparate(GL_CONSTANT_COLOR, GL_CONSTANT_COLOR, GL_ONE, GL_ZERO); glBlendColor(0.5, 0.5, 0.5, 0.5); break; case DrawMode::AlphaBlend::ZERO_SRC_SRC_DST: - glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ZERO); glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); break; default: diff --git a/game/graphics/opengl_renderer/ocean/OceanTexture.cpp b/game/graphics/opengl_renderer/ocean/OceanTexture.cpp index 6d8eb413a..dca60afe6 100644 --- a/game/graphics/opengl_renderer/ocean/OceanTexture.cpp +++ b/game/graphics/opengl_renderer/ocean/OceanTexture.cpp @@ -305,7 +305,7 @@ void OceanTexture::make_texture_with_mipmaps(SharedRenderState* render_state, FramebufferTexturePairContext ctxt(m_result_texture, i); glUniform1f(glGetUniformLocation(render_state->shaders[ShaderId::OCEAN_TEXTURE_MIPMAP].id(), "alpha_intensity"), - std::max(0.f, 1.f - 0.4f * i)); + std::max(0.f, 1.f - 0.51f * i)); glUniform1f( glGetUniformLocation(render_state->shaders[ShaderId::OCEAN_TEXTURE_MIPMAP].id(), "scale"), 1.f / (1 << i));