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

Fixes https://github.com/open-goal/jak-project/issues/2814

Previously we didn't handle `GREATER` vs `GEQUAL` correctly. I just left
this as a TODO by accident.


![image](https://github.com/open-goal/jak-project/assets/48171810/bfa7bd98-e40e-4850-af9c-ed6954c00958)
This commit is contained in:
water111 2023-08-17 19:13:15 -04:00 committed by GitHub
parent 5c00f1abe1
commit f3f8ccc9ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View file

@ -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;
@ -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);

View file

@ -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;
@ -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));