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

Fix alpha test > vs >= (minimap arrow fix) #2913

Merged
merged 1 commit into from Aug 17, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion game/graphics/opengl_renderer/DirectRenderer.cpp
Expand Up @@ -334,14 +334,20 @@ void DirectRenderer::update_gl_prim(SharedRenderState* render_state) {
if (state.texture_enable) {
float alpha_min = 0.0;
float alpha_max = 10;
int greater = 0;
if (m_test_state.alpha_test_enable) {
switch (m_test_state.alpha_test) {
case GsTest::AlphaTest::ALWAYS:
break;
case GsTest::AlphaTest::GEQUAL:
case GsTest::AlphaTest::GREATER: // todo
alpha_min = m_test_state.aref / 128.f;
m_double_draw_aref = alpha_min;
greater = 0;
break;
case GsTest::AlphaTest::GREATER:
alpha_min = (1 + m_test_state.aref) / 128.f;
m_double_draw_aref = alpha_min;
greater = 1;
break;
case GsTest::AlphaTest::NEVER:
break;
Expand Down Expand Up @@ -370,6 +376,9 @@ void DirectRenderer::update_gl_prim(SharedRenderState* render_state) {
glUniform1i(glGetUniformLocation(render_state->shaders[ShaderId::DIRECT_BASIC_TEXTURED].id(),
"offscreen_mode"),
m_offscreen_mode);
glUniform1i(glGetUniformLocation(render_state->shaders[ShaderId::DIRECT_BASIC_TEXTURED].id(),
"greater"),
greater);
glUniform1f(
glGetUniformLocation(render_state->shaders[ShaderId::DIRECT_BASIC_TEXTURED].id(), "ta0"),
state.ta0 / 255.f);
Expand Down
15 changes: 13 additions & 2 deletions game/graphics/opengl_renderer/shaders/direct_basic_textured.frag
Expand Up @@ -13,6 +13,7 @@ uniform float alpha_mult;
uniform float alpha_sub;
uniform float ta0;
uniform int scissor_enable;
uniform bool greater;
// game width, game height, viewport width, viewport height
uniform vec4 game_sizes;

Expand Down Expand Up @@ -85,8 +86,18 @@ void main() {
color *= 2;
color.xyz *= color_mult;
color.w *= alpha_mult;
if (color.a < alpha_min || color.a > alpha_max) {
discard;
if (greater) {
// pass if alpha > min, so discard if alpha <= min
// greater than check should use the opposite, so alpha values equal to aref are only passed once for
// any double-draw
if (color.a <= alpha_min || color.a > alpha_max) {
discard;
}
} else {
// and this is just flipped from the case above.
if (color.a < alpha_min || color.a >= alpha_max) {
discard;
}
}
if (tex_info.w == 1) {
color.xyz = mix(color.xyz, fog_color.rgb, clamp(fog_color.a * fog, 0, 1));
Expand Down