From f701573d442a7d8f847f549312ef71880755a938 Mon Sep 17 00:00:00 2001 From: Erik Abair Date: Wed, 5 Mar 2025 10:10:14 -0800 Subject: [PATCH] nv2a: Use rounded values for alpha testing --- hw/xbox/nv2a/pgraph/gl/shaders.c | 6 +++--- hw/xbox/nv2a/pgraph/glsl/psh.c | 6 ++++-- hw/xbox/nv2a/pgraph/vk/shaders.c | 7 +++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/hw/xbox/nv2a/pgraph/gl/shaders.c b/hw/xbox/nv2a/pgraph/gl/shaders.c index f47105980c..3095ca3c3a 100644 --- a/hw/xbox/nv2a/pgraph/gl/shaders.c +++ b/hw/xbox/nv2a/pgraph/gl/shaders.c @@ -712,9 +712,9 @@ static void shader_update_constants(PGRAPHState *pg, ShaderBinding *binding, } } if (binding->alpha_ref_loc != -1) { - float alpha_ref = GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_CONTROL_0), - NV_PGRAPH_CONTROL_0_ALPHAREF) / 255.0; - glUniform1f(binding->alpha_ref_loc, alpha_ref); + int alpha_ref = GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_CONTROL_0), + NV_PGRAPH_CONTROL_0_ALPHAREF); + glUniform1i(binding->alpha_ref_loc, alpha_ref); } diff --git a/hw/xbox/nv2a/pgraph/glsl/psh.c b/hw/xbox/nv2a/pgraph/glsl/psh.c index 9775db2a8a..44c56a9c9b 100644 --- a/hw/xbox/nv2a/pgraph/glsl/psh.c +++ b/hw/xbox/nv2a/pgraph/glsl/psh.c @@ -743,7 +743,7 @@ static MString* psh_convert(struct PixelShader *ps) "layout(location = 0) out vec4 fragColor;\n"); } - mstring_append_fmt(preflight, "%sfloat alphaRef;\n" + mstring_append_fmt(preflight, "%sint alphaRef;\n" "%svec4 fogColor;\n" "%sivec4 clipRegion[8];\n", u, u, u); @@ -1190,7 +1190,9 @@ static MString* psh_convert(struct PixelShader *ps) assert(false); break; } - mstring_append_fmt(ps->code, "if (!(fragColor.a %s alphaRef)) discard;\n", + mstring_append_fmt(ps->code, + "int fragAlpha = int(round(fragColor.a * 255.0));\n" + "if (!(fragAlpha %s alphaRef)) discard;\n", alpha_op); } } diff --git a/hw/xbox/nv2a/pgraph/vk/shaders.c b/hw/xbox/nv2a/pgraph/vk/shaders.c index 1f4ad765de..5fce943d49 100644 --- a/hw/xbox/nv2a/pgraph/vk/shaders.c +++ b/hw/xbox/nv2a/pgraph/vk/shaders.c @@ -477,10 +477,9 @@ static void shader_update_constants(PGRAPHState *pg, ShaderBinding *binding, } } if (binding->alpha_ref_loc != -1) { - float alpha_ref = GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_CONTROL_0), - NV_PGRAPH_CONTROL_0_ALPHAREF) / - 255.0; - uniform1f(&binding->fragment->uniforms, binding->alpha_ref_loc, + int alpha_ref = GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_CONTROL_0), + NV_PGRAPH_CONTROL_0_ALPHAREF); + uniform1i(&binding->fragment->uniforms, binding->alpha_ref_loc, alpha_ref); }