nv2a: Fix BUMPENVMAP[_LUM] texture modes

This commit is contained in:
Wilhelm Kovatch 2020-11-09 22:35:45 +01:00 committed by mborgerson
parent bdd8375ba2
commit ff3deacae6
3 changed files with 44 additions and 11 deletions

View File

@ -3312,6 +3312,10 @@ static void pgraph_bind_shaders(PGRAPHState *pg)
GET_MASK(pg->regs[NV_PGRAPH_TEXFMT0 + i*4],
NV_PGRAPH_TEXFMT0_COLOR);
/* This is needed to detect cases where the wrong format for ds/dt textures is used
* and a remapping of the unsigned values to signed is needed (e.g. the boost dash in JSRF) */
state.psh.dsdt_tex[i] = kelvin_color_format_map[color_format].gl_type == GL_BYTE;
if (enabled && kelvin_color_format_map[color_format].linear) {
state.psh.rect_tex[i] = true;
}

View File

@ -685,27 +685,55 @@ static QString* psh_convert(struct PixelShader *ps)
}
case PS_TEXTUREMODES_BUMPENVMAP:
assert(i >= 1);
assert(!ps->state.rect_tex[i]);
sampler_type = "sampler2D";
if (!ps->state.dsdt_tex[ps->input_tex[i]]) {
/* Fix for cases using improper formats for the ds/dt offset texture,
* like the boost dash effect in JSRF */
/* FIXME: Figure out why the green and blue channels arrive reversed */
qstring_append_fmt(vars, "t%d.bg = dotmap_minus1_to_1_gl(t%d.rgb).gb;\n",
ps->input_tex[i], ps->input_tex[i]);
}
sampler_type = ps->state.rect_tex[i] ? "sampler2DRect" : "sampler2D";
qstring_append_fmt(preflight, "uniform mat2 bumpMat%d;\n", i);
/* FIXME: Do bumpMat swizzle on CPU before upload */
qstring_append_fmt(vars, "vec4 t%d = texture(texSamp%d, pT%d.xy + t%d.rg * mat2(bumpMat%d[0].xy,bumpMat%d[1].yx));\n",
i, i, i, ps->input_tex[i], i, i);
qstring_append_fmt(vars, "t%d.gb = mat2(bumpMat%d[0].xy, bumpMat%d[1].yx) * t%d.gb;\n",
ps->input_tex[i], i, i, ps->input_tex[i]);
qstring_append_fmt(vars, "vec4 t%d = texture(texSamp%d, pT%d.xy + t%d.gb);\n",
i, i, i, ps->input_tex[i]);
break;
case PS_TEXTUREMODES_BUMPENVMAP_LUM:
assert(i >= 1);
qstring_append_fmt(preflight, "uniform float bumpScale%d;\n", i);
qstring_append_fmt(preflight, "uniform float bumpOffset%d;\n", i);
qstring_append_fmt(ps->code, "/* BUMPENVMAP_LUM for stage %d */\n", i);
qstring_append_fmt(ps->code, "t%d = t%d * (bumpScale%d * t%d.b + bumpOffset%d);\n",
i, i, i, ps->input_tex[i], i);
if (!ps->state.dsdt_tex[ps->input_tex[i]]) {
/* Fix for cases using improper texture formats for the ds/dt offset texture */
/* FIXME: Figure out why the channels arrive reversed */
qstring_append_fmt(vars, "t%d.gbr = vec3(dotmap_minus1_to_1_gl(t%d.abg).gb, t%d.r);\n",
ps->input_tex[i], ps->input_tex[i], ps->input_tex[i]);
} else {
/* FIXME: Figure out why the green and blue channels arrive reversed */
qstring_append_fmt(vars, "t%d.rgb = vec3(t%d.rbg);\n",
ps->input_tex[i], ps->input_tex[i]);
}
/* Now the same as BUMPENVMAP */
assert(!ps->state.rect_tex[i]);
sampler_type = "sampler2D";
sampler_type = ps->state.rect_tex[i] ? "sampler2DRect" : "sampler2D";
qstring_append_fmt(preflight, "uniform mat2 bumpMat%d;\n", i);
/* FIXME: Do bumpMat swizzle on CPU before upload */
qstring_append_fmt(vars, "vec4 t%d = texture(texSamp%d, pT%d.xy + t%d.rg * mat2(bumpMat%d[0].xy,bumpMat%d[1].yx));\n",
i, i, i, ps->input_tex[i], i, i);
qstring_append_fmt(vars, "t%d.gb = mat2(bumpMat%d[0].xy, bumpMat%d[1].yx) * t%d.gb;\n",
ps->input_tex[i], i, i, ps->input_tex[i]);
qstring_append_fmt(vars, "vec4 t%d = texture(texSamp%d, pT%d.xy + t%d.gb);\n",
i, i, i, ps->input_tex[i]);
qstring_append_fmt(vars, "t%d = t%d * (bumpScale%d * t%d.r + bumpOffset%d);\n",
i, i, i, ps->input_tex[i], i);
break;
case PS_TEXTUREMODES_BRDF:
assert(i >= 2);

View File

@ -45,6 +45,7 @@ typedef struct PshState {
uint32_t alpha_inputs[8], alpha_outputs[8];
bool rect_tex[4];
bool dsdt_tex[4];
bool compare_mode[4][4];
bool alphakill[4];