Skip to content

Commit

Permalink
Https/GitHub.com/xemu project/xemu/pull/1651
Browse files Browse the repository at this point in the history
Https/GitHub.com/xemu project/xemu/pull/1651
  • Loading branch information
user18081972 authored Nov 11, 2024
2 parents 238cf64 + 4902a4c commit 498695b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
11 changes: 9 additions & 2 deletions hw/xbox/nv2a/shaders.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,8 @@ GLSL_DEFINE(texMat2, GLSL_C_MAT4(NV_IGRAPH_XF_XFCTX_T2MAT))
GLSL_DEFINE(texMat3, GLSL_C_MAT4(NV_IGRAPH_XF_XFCTX_T3MAT))

"\n"
"bool perspective = false;\n"
"float depth = 0.0;\n"
"vec4 oPos = vec4(0.0,0.0,0.0,1.0);\n"
"vec4 oD0 = vec4(0.0,0.0,0.0,1.0);\n"
"vec4 oD1 = vec4(0.0,0.0,0.0,1.0);\n"
Expand Down Expand Up @@ -976,8 +978,13 @@ GLSL_DEFINE(texMat3, GLSL_C_MAT4(NV_IGRAPH_XF_XFCTX_T3MAT))
" vtxT3 = oT3 * vtx_inv_w;\n"
" gl_Position = oPos;\n"
" gl_PointSize = oPts.x;\n"
" gl_ClipDistance[0] = oPos.z - oPos.w*clipRange.z;\n" // Near
" gl_ClipDistance[1] = oPos.w*clipRange.w - oPos.z;\n" // Far
" if (perspective) {\n"
" gl_ClipDistance[0] = oPos.z - oPos.w*clipRange.z;\n" // Near
" gl_ClipDistance[1] = oPos.w*clipRange.w - min(0.0, oPos.z);\n" // Far
" } else { \n"
" gl_ClipDistance[0] = clipRange.x;\n;"//oPos.z - oPos.w*clipRange.z;\n" // Near
" gl_ClipDistance[1] = oPos.w*clipRange.w - oPos.z;\n" // Far
" }\n"
"\n"
"}\n",
shade_model_mult,
Expand Down
28 changes: 22 additions & 6 deletions hw/xbox/nv2a/vsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,13 +846,29 @@ void vsh_translate(uint16_t version,
" oPos.y = -2.0 * (oPos.y - surfaceSize.y * 0.5) / surfaceSize.y;\n"
);
if (z_perspective) {
mstring_append(body, " oPos.z = oPos.w;\n");
mstring_append(body,
" perspective = true;\n"
//" depth = 2.0 * (oPos.w - clipRange.x)/(clipRange.y - clipRange.x) - 1.0;\n"

" if (oPos.w != oPos.z) {\n"
" oPos.z = 2.0 * (oPos.w - clipRange.x)/(clipRange.y - clipRange.x) - 1.0;\n"
" } else {\n"
" oPos.z = 0.0;\n"
" }\n"
);
} else {
mstring_append(body,
" perspective = false;\n"

" if (clipRange.y != clipRange.x) {\n"
" oPos.z = 2.0 * (oPos.z - clipRange.x)/(clipRange.y - clipRange.x) - 1.0;\n"
" }\n"
" if (oPos.w >= 0.0) {\n"
" oPos.z = min(1.0, oPos.z);\n"
" }\n"
);
}
mstring_append(body,
" if (clipRange.y != clipRange.x) {\n"
" oPos.z = (oPos.z - clipRange.x)/(0.5*(clipRange.y - clipRange.x)) - 1;\n"
" }\n"

mstring_append(body,
/* Correct for the perspective divide */
" if (oPos.w < 0.0) {\n"
/* undo the perspective divide in the case where the point would be
Expand Down

0 comments on commit 498695b

Please sign in to comment.