Skip to content

Commit

Permalink
Merge pull request #8 from polymetal0/master
Browse files Browse the repository at this point in the history
Zfix
  • Loading branch information
backgamon authored Jan 4, 2025
2 parents 34e0b06 + 6f4a9b1 commit e182ce4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions hw/xbox/nv2a/pgraph/gl/shaders.c
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,8 @@ static void shader_update_constants(PGRAPHState *pg, ShaderBinding *binding,
uint32_t v[2];
v[0] = pgraph_reg_r(pg, NV_PGRAPH_ZCLIPMIN);
v[1] = pgraph_reg_r(pg, NV_PGRAPH_ZCLIPMAX);
float zclip_min = *(float*)&v[0] / zmax * 2.0 - 1.0;
float zclip_max = *(float*)&v[1] / zmax * 2.0 - 1.0;
float zclip_min = *(float*)&v[0];// / zmax * 2.0 - 1.0;
float zclip_max = *(float*)&v[1];// / zmax * 2.0 - 1.0;
glUniform4f(binding->clip_range_loc, 0, zmax, zclip_min, zclip_max);
}

Expand Down
2 changes: 1 addition & 1 deletion hw/xbox/nv2a/pgraph/glsl/psh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ static MString *psh_convert(struct PixelShader *ps, bool z_perspective)
}

if (z_perspective) {
mstring_append(ps->code, "gl_FragDepth = (1.0/gl_FragCoord.w)/clipRange.y;\n");
mstring_append(ps->code, "gl_FragDepth = 1.0/(gl_FragCoord.w * clipRange.y);\n");
}

for (i = 0; i < ps->num_var_refs; i++) {
Expand Down
12 changes: 8 additions & 4 deletions hw/xbox/nv2a/pgraph/glsl/vsh-prog.c
Original file line number Diff line number Diff line change
Expand Up @@ -856,14 +856,18 @@ void pgraph_gen_vsh_prog_glsl(uint16_t version,
"/ surfaceSize.y;\n");
}

if (z_perspective) {
mstring_append(body, " oPos.z = oPos.w;\n");
}

mstring_append(body,
" if (clipRange.y != clipRange.x) {\n");
if (vulkan) {
mstring_append(body, " oPos.z /= clipRange.y;\n");
mstring_append(body, " oPos.z = (oPos.z - clipRange.z)/(clipRange.w - clipRange.z);\n");
} else {
mstring_append(body,
" oPos.z = (oPos.z - clipRange.x)/(0.5*(clipRange.y "
"- clipRange.x)) - 1;\n");
" oPos.z = (oPos.z - clipRange.z)/(0.5*(clipRange.w "
"- clipRange.z)) - 1;\n");
}
mstring_append(body,
" }\n"
Expand All @@ -875,7 +879,7 @@ void pgraph_gen_vsh_prog_glsl(uint16_t version,
body,

/* Correct for the perspective divide */
" if (oPos.w < 0.0) {\n"
" if (oPos.w < clipRange.z) {\n"
/* undo the perspective divide in the case where the point would be
* clipped so opengl can clip it correctly */
" oPos.xyz *= oPos.w;\n"
Expand Down
4 changes: 2 additions & 2 deletions hw/xbox/nv2a/pgraph/vk/shaders.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,8 @@ static void shader_update_constants(PGRAPHState *pg, ShaderBinding *binding,
uint32_t v[2];
v[0] = pgraph_reg_r(pg, NV_PGRAPH_ZCLIPMIN);
v[1] = pgraph_reg_r(pg, NV_PGRAPH_ZCLIPMAX);
float zclip_min = *(float *)&v[0] / zmax * 2.0 - 1.0;
float zclip_max = *(float *)&v[1] / zmax * 2.0 - 1.0;
float zclip_min = *(float *)&v[0];// / zmax * 2.0 - 1.0;
float zclip_max = *(float *)&v[1];// / zmax * 2.0 - 1.0;

if (binding->clip_range_loc != -1) {
uniform4f(&binding->vertex->uniforms, binding->clip_range_loc, 0,
Expand Down

0 comments on commit e182ce4

Please sign in to comment.