Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[graphics] fix ocean alpha and ocean near depth #1236

Merged
merged 2 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions game/graphics/opengl_renderer/DirectRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -370,34 +371,34 @@ 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 &&
state.d == GsAlpha::BlendMode::DEST) {
// (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 {
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions game/graphics/opengl_renderer/DirectRenderer2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions game/graphics/opengl_renderer/background/background_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion game/graphics/opengl_renderer/ocean/OceanTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down