mirror of https://github.com/xemu-project/xemu.git
nv2a/psh: Normalize coords at sample time
This commit is contained in:
parent
ec59148333
commit
1c38a0a42b
|
@ -645,13 +645,17 @@ static void psh_append_shadowmap(const struct PixelShader *ps, int i, bool compa
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_autofree gchar *normalize_tex_coords = g_strdup_printf("norm%d", i);
|
||||||
|
const char *tex_remap = ps->state.rect_tex[i] ? normalize_tex_coords : "";
|
||||||
|
|
||||||
const char *comparison = shadow_comparison_map[ps->state.shadow_depth_func];
|
const char *comparison = shadow_comparison_map[ps->state.shadow_depth_func];
|
||||||
|
|
||||||
bool extract_msb_24b = ps->state.tex_x8y24[i] && ps->state.vulkan;
|
bool extract_msb_24b = ps->state.tex_x8y24[i] && ps->state.vulkan;
|
||||||
|
|
||||||
mstring_append_fmt(vars,
|
mstring_append_fmt(
|
||||||
"%svec4 t%d_depth%s = textureProj(texSamp%d, pT%d.xyw);\n",
|
vars, "%svec4 t%d_depth%s = textureProj(texSamp%d, %s(pT%d.xyw));\n",
|
||||||
extract_msb_24b ? "u" : "", i, extract_msb_24b ? "_raw" : "", i, i);
|
extract_msb_24b ? "u" : "", i, extract_msb_24b ? "_raw" : "", i,
|
||||||
|
tex_remap, i);
|
||||||
|
|
||||||
if (extract_msb_24b) {
|
if (extract_msb_24b) {
|
||||||
mstring_append_fmt(vars,
|
mstring_append_fmt(vars,
|
||||||
|
@ -707,12 +711,17 @@ static void apply_border_adjustment(const struct PixelShader *ps, MString *vars,
|
||||||
static void apply_convolution_filter(const struct PixelShader *ps, MString *vars, int tex)
|
static void apply_convolution_filter(const struct PixelShader *ps, MString *vars, int tex)
|
||||||
{
|
{
|
||||||
// FIXME: Quincunx
|
// FIXME: Quincunx
|
||||||
|
|
||||||
|
g_autofree gchar *normalize_tex_coords = g_strdup_printf("norm%d", tex);
|
||||||
|
const char *tex_remap = ps->state.rect_tex[tex] ? normalize_tex_coords : "";
|
||||||
|
|
||||||
mstring_append_fmt(vars,
|
mstring_append_fmt(vars,
|
||||||
"vec4 t%d = vec4(0.0);\n"
|
"vec4 t%d = vec4(0.0);\n"
|
||||||
"for (int i = 0; i < 9; i++) {\n"
|
"for (int i = 0; i < 9; i++) {\n"
|
||||||
" vec3 texCoord = pT%d.xyw + vec3(convolution3x3[i] / (textureSize(texSamp%d, 0) * texScale%d), 0);\n"
|
" vec3 texCoordDelta = vec3(convolution3x3[i], 0);\n"
|
||||||
" t%d += textureProj(texSamp%d, texCoord) * gaussian3x3[i];\n"
|
" texCoordDelta.xy /= textureSize(texSamp%d, 0);\n"
|
||||||
"}\n", tex, tex, tex, tex, tex, tex, tex);
|
" t%d += textureProj(texSamp%d, %s(pT%d.xyw) + texCoordDelta) * gaussian3x3[i];\n"
|
||||||
|
"}\n", tex, tex, tex, tex, tex_remap, tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static MString* psh_convert(struct PixelShader *ps)
|
static MString* psh_convert(struct PixelShader *ps)
|
||||||
|
@ -884,16 +893,13 @@ static MString* psh_convert(struct PixelShader *ps)
|
||||||
|
|
||||||
ps->code = mstring_new();
|
ps->code = mstring_new();
|
||||||
|
|
||||||
for (i = 0; i < 4; i++) {
|
|
||||||
if (ps->state.rect_tex[i]) {
|
|
||||||
mstring_append_fmt(vars, "pT%d.xy /= textureSize(texSamp%d, 0) / texScale%d;\n", i, i, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
|
|
||||||
const char *sampler_type = get_sampler_type(ps->tex_modes[i], &ps->state, i);
|
const char *sampler_type = get_sampler_type(ps->tex_modes[i], &ps->state, i);
|
||||||
|
|
||||||
|
g_autofree gchar *normalize_tex_coords = g_strdup_printf("norm%d", i);
|
||||||
|
const char *tex_remap = ps->state.rect_tex[i] ? normalize_tex_coords : "";
|
||||||
|
|
||||||
assert(ps->dot_map[i] < 8);
|
assert(ps->dot_map[i] < 8);
|
||||||
const char *dotmap_func = dotmap_funcs[ps->dot_map[i]];
|
const char *dotmap_func = dotmap_funcs[ps->dot_map[i]];
|
||||||
if (ps->dot_map[i] > 3) {
|
if (ps->dot_map[i] > 3) {
|
||||||
|
@ -914,8 +920,8 @@ static MString* psh_convert(struct PixelShader *ps)
|
||||||
(ps->state.conv_tex[i] == CONVOLUTION_FILTER_QUINCUNX))) {
|
(ps->state.conv_tex[i] == CONVOLUTION_FILTER_QUINCUNX))) {
|
||||||
apply_convolution_filter(ps, vars, i);
|
apply_convolution_filter(ps, vars, i);
|
||||||
} else {
|
} else {
|
||||||
mstring_append_fmt(vars, "vec4 t%d = textureProj(texSamp%d, pT%d.xyw);\n",
|
mstring_append_fmt(vars, "vec4 t%d = textureProj(texSamp%d, %s(pT%d.xyw));\n",
|
||||||
i, i, i);
|
i, i, tex_remap, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -964,8 +970,8 @@ static MString* psh_convert(struct PixelShader *ps)
|
||||||
|
|
||||||
mstring_append_fmt(vars, "dsdt%d = bumpMat%d * dsdt%d;\n",
|
mstring_append_fmt(vars, "dsdt%d = bumpMat%d * dsdt%d;\n",
|
||||||
i, i, i, i);
|
i, i, i, i);
|
||||||
mstring_append_fmt(vars, "vec4 t%d = texture(texSamp%d, (pT%d.xy + dsdt%d));\n",
|
mstring_append_fmt(vars, "vec4 t%d = texture(texSamp%d, %s(pT%d.xy + dsdt%d));\n",
|
||||||
i, i, i, i);
|
i, i, tex_remap, i, i);
|
||||||
break;
|
break;
|
||||||
case PS_TEXTUREMODES_BUMPENVMAP_LUM:
|
case PS_TEXTUREMODES_BUMPENVMAP_LUM:
|
||||||
assert(i >= 1);
|
assert(i >= 1);
|
||||||
|
@ -982,8 +988,8 @@ static MString* psh_convert(struct PixelShader *ps)
|
||||||
|
|
||||||
mstring_append_fmt(vars, "dsdtl%d.st = bumpMat%d * dsdtl%d.st;\n",
|
mstring_append_fmt(vars, "dsdtl%d.st = bumpMat%d * dsdtl%d.st;\n",
|
||||||
i, i, i, i);
|
i, i, i, i);
|
||||||
mstring_append_fmt(vars, "vec4 t%d = texture(texSamp%d, (pT%d.xy + dsdtl%d.st));\n",
|
mstring_append_fmt(vars, "vec4 t%d = texture(texSamp%d, %s(pT%d.xy + dsdtl%d.st));\n",
|
||||||
i, i, i, i);
|
i, i, tex_remap, i, i);
|
||||||
mstring_append_fmt(vars, "t%d = t%d * (bumpScale%d * dsdtl%d.p + bumpOffset%d);\n",
|
mstring_append_fmt(vars, "t%d = t%d * (bumpScale%d * dsdtl%d.p + bumpOffset%d);\n",
|
||||||
i, i, i, i, i);
|
i, i, i, i, i);
|
||||||
break;
|
break;
|
||||||
|
@ -1002,8 +1008,8 @@ static MString* psh_convert(struct PixelShader *ps)
|
||||||
i, i, dotmap_func, ps->input_tex[i], i, i-1, i);
|
i, i, dotmap_func, ps->input_tex[i], i, i-1, i);
|
||||||
|
|
||||||
apply_border_adjustment(ps, vars, i, "dotST%d");
|
apply_border_adjustment(ps, vars, i, "dotST%d");
|
||||||
mstring_append_fmt(vars, "vec4 t%d = texture(texSamp%d, dotST%d);\n",
|
mstring_append_fmt(vars, "vec4 t%d = texture(texSamp%d, %s(dotST%d));\n",
|
||||||
i, i, i);
|
i, i, tex_remap, i);
|
||||||
break;
|
break;
|
||||||
case PS_TEXTUREMODES_DOT_ZW:
|
case PS_TEXTUREMODES_DOT_ZW:
|
||||||
assert(i >= 2);
|
assert(i >= 2);
|
||||||
|
@ -1071,16 +1077,16 @@ static MString* psh_convert(struct PixelShader *ps)
|
||||||
assert(!ps->state.rect_tex[i]);
|
assert(!ps->state.rect_tex[i]);
|
||||||
mstring_append_fmt(vars, "vec2 t%dAR = t%d.ar;\n", i, ps->input_tex[i]);
|
mstring_append_fmt(vars, "vec2 t%dAR = t%d.ar;\n", i, ps->input_tex[i]);
|
||||||
apply_border_adjustment(ps, vars, i, "t%dAR");
|
apply_border_adjustment(ps, vars, i, "t%dAR");
|
||||||
mstring_append_fmt(vars, "vec4 t%d = texture(texSamp%d, t%dAR);\n",
|
mstring_append_fmt(vars, "vec4 t%d = texture(texSamp%d, %s(t%dAR));\n",
|
||||||
i, i, i);
|
i, i, tex_remap, i);
|
||||||
break;
|
break;
|
||||||
case PS_TEXTUREMODES_DPNDNT_GB:
|
case PS_TEXTUREMODES_DPNDNT_GB:
|
||||||
assert(i >= 1);
|
assert(i >= 1);
|
||||||
assert(!ps->state.rect_tex[i]);
|
assert(!ps->state.rect_tex[i]);
|
||||||
mstring_append_fmt(vars, "vec2 t%dGB = t%d.gb;\n", i, ps->input_tex[i]);
|
mstring_append_fmt(vars, "vec2 t%dGB = t%d.gb;\n", i, ps->input_tex[i]);
|
||||||
apply_border_adjustment(ps, vars, i, "t%dGB");
|
apply_border_adjustment(ps, vars, i, "t%dGB");
|
||||||
mstring_append_fmt(vars, "vec4 t%d = texture(texSamp%d, t%dGB);\n",
|
mstring_append_fmt(vars, "vec4 t%d = texture(texSamp%d, %s(t%dGB));\n",
|
||||||
i, i, i);
|
i, i, tex_remap, i);
|
||||||
break;
|
break;
|
||||||
case PS_TEXTUREMODES_DOTPRODUCT:
|
case PS_TEXTUREMODES_DOTPRODUCT:
|
||||||
assert(i == 1 || i == 2);
|
assert(i == 1 || i == 2);
|
||||||
|
@ -1112,6 +1118,19 @@ static MString* psh_convert(struct PixelShader *ps)
|
||||||
mstring_append_fmt(vars, "if (t%d.a == 0.0) { discard; };\n",
|
mstring_append_fmt(vars, "if (t%d.a == 0.0) { discard; };\n",
|
||||||
i);
|
i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ps->state.rect_tex[i]) {
|
||||||
|
mstring_append_fmt(preflight,
|
||||||
|
"vec2 norm%d(vec2 coord) {\n"
|
||||||
|
" return coord / (textureSize(texSamp%d, 0) / texScale%d);\n"
|
||||||
|
"}\n",
|
||||||
|
i, i, i);
|
||||||
|
mstring_append_fmt(preflight,
|
||||||
|
"vec3 norm%d(vec3 coord) {\n"
|
||||||
|
" return vec3(norm%d(coord.xy), coord.z);\n"
|
||||||
|
"}\n",
|
||||||
|
i, i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue