Merge pull request #9876 from Pokechu22/skyward-sword-map
Fix indirect textures when format is not ITF_8
This commit is contained in:
commit
20a8e9c872
|
@ -459,22 +459,22 @@ void Tev::Indirect(unsigned int stageNum, s32 s, s32 t)
|
||||||
AlphaBump = AlphaBump & 0xf8;
|
AlphaBump = AlphaBump & 0xf8;
|
||||||
break;
|
break;
|
||||||
case IndTexFormat::ITF_5:
|
case IndTexFormat::ITF_5:
|
||||||
indcoord[0] = (indmap[TextureSampler::ALP_SMP] & 0x1f) + bias[0];
|
indcoord[0] = (indmap[TextureSampler::ALP_SMP] >> 3) + bias[0];
|
||||||
indcoord[1] = (indmap[TextureSampler::BLU_SMP] & 0x1f) + bias[1];
|
indcoord[1] = (indmap[TextureSampler::BLU_SMP] >> 3) + bias[1];
|
||||||
indcoord[2] = (indmap[TextureSampler::GRN_SMP] & 0x1f) + bias[2];
|
indcoord[2] = (indmap[TextureSampler::GRN_SMP] >> 3) + bias[2];
|
||||||
AlphaBump = AlphaBump & 0xe0;
|
AlphaBump = AlphaBump << 5;
|
||||||
break;
|
break;
|
||||||
case IndTexFormat::ITF_4:
|
case IndTexFormat::ITF_4:
|
||||||
indcoord[0] = (indmap[TextureSampler::ALP_SMP] & 0x0f) + bias[0];
|
indcoord[0] = (indmap[TextureSampler::ALP_SMP] >> 4) + bias[0];
|
||||||
indcoord[1] = (indmap[TextureSampler::BLU_SMP] & 0x0f) + bias[1];
|
indcoord[1] = (indmap[TextureSampler::BLU_SMP] >> 4) + bias[1];
|
||||||
indcoord[2] = (indmap[TextureSampler::GRN_SMP] & 0x0f) + bias[2];
|
indcoord[2] = (indmap[TextureSampler::GRN_SMP] >> 4) + bias[2];
|
||||||
AlphaBump = AlphaBump & 0xf0;
|
AlphaBump = AlphaBump << 4;
|
||||||
break;
|
break;
|
||||||
case IndTexFormat::ITF_3:
|
case IndTexFormat::ITF_3:
|
||||||
indcoord[0] = (indmap[TextureSampler::ALP_SMP] & 0x07) + bias[0];
|
indcoord[0] = (indmap[TextureSampler::ALP_SMP] >> 5) + bias[0];
|
||||||
indcoord[1] = (indmap[TextureSampler::BLU_SMP] & 0x07) + bias[1];
|
indcoord[1] = (indmap[TextureSampler::BLU_SMP] >> 5) + bias[1];
|
||||||
indcoord[2] = (indmap[TextureSampler::GRN_SMP] & 0x07) + bias[2];
|
indcoord[2] = (indmap[TextureSampler::GRN_SMP] >> 5) + bias[2];
|
||||||
AlphaBump = AlphaBump & 0xf8;
|
AlphaBump = AlphaBump << 3;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PanicAlertFmt("Invalid indirect format {}", indirect.fmt);
|
PanicAlertFmt("Invalid indirect format {}", indirect.fmt);
|
||||||
|
|
|
@ -1006,17 +1006,22 @@ static void WriteStage(ShaderCode& out, const pixel_shader_uid_data* uid_data, i
|
||||||
"z",
|
"z",
|
||||||
};
|
};
|
||||||
|
|
||||||
// 0b11111000, 0b11100000, 0b11110000, 0b11111000
|
// According to libogc, the bump alpha value is 5 bits, and comes from the bottom bits of the
|
||||||
static constexpr std::array<const char*, 4> tev_ind_alpha_mask{
|
// component byte, except in the case of ITF_8, which presumably uses the top bits with a
|
||||||
"248",
|
// mask.
|
||||||
"224",
|
// https://github.com/devkitPro/libogc/blob/bd24a9b3f59502f9b30d6bac0ae35fc485045f78/gc/ogc/gx.h#L3038-L3041
|
||||||
"240",
|
// https://github.com/devkitPro/libogc/blob/bd24a9b3f59502f9b30d6bac0ae35fc485045f78/gc/ogc/gx.h#L790-L800
|
||||||
"248",
|
|
||||||
|
static constexpr std::array<char, 4> tev_ind_alpha_shift{
|
||||||
|
'0', // ITF_8: 0bXXXXXYYY -> 0bXXXXX000? No shift?
|
||||||
|
'5', // ITF_5: 0bIIIIIAAA -> 0bAAA00000, shift of 5
|
||||||
|
'4', // ITF_4: 0bIIIIAAAA -> 0bAAAA0000, shift of 4
|
||||||
|
'3', // ITF_3: 0bIIIAAAAA -> 0bAAAAA000, shift of 3
|
||||||
};
|
};
|
||||||
|
|
||||||
out.Write("alphabump = iindtex{}.{} & {};\n", tevind.bt.Value(),
|
out.Write("\talphabump = (iindtex{}.{} << {}) & 248;\n", tevind.bt.Value(),
|
||||||
tev_ind_alpha_sel[u32(tevind.bs.Value())],
|
tev_ind_alpha_sel[u32(tevind.bs.Value())],
|
||||||
tev_ind_alpha_mask[u32(tevind.fmt.Value())]);
|
tev_ind_alpha_shift[u32(tevind.fmt.Value())]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1026,14 +1031,14 @@ static void WriteStage(ShaderCode& out, const pixel_shader_uid_data* uid_data, i
|
||||||
if (has_ind_stage && tevind.matrix_index != IndMtxIndex::Off)
|
if (has_ind_stage && tevind.matrix_index != IndMtxIndex::Off)
|
||||||
{
|
{
|
||||||
// format
|
// format
|
||||||
static constexpr std::array<const char*, 4> tev_ind_fmt_mask{
|
static constexpr std::array<char, 4> tev_ind_fmt_shift{
|
||||||
"255",
|
'0', // ITF_8: 0bXXXXXXXX -> 0bXXXXXXXX, no shift
|
||||||
"31",
|
'3', // ITF_5: 0bIIIIIAAA -> 0b000IIIII, shift of 3
|
||||||
"15",
|
'4', // ITF_4: 0bIIIIAAAA -> 0b0000IIII, shift of 4
|
||||||
"7",
|
'5', // ITF_3: 0bIIIAAAAA -> 0b00000III, shift of 5
|
||||||
};
|
};
|
||||||
out.Write("\tint3 iindtevcrd{} = iindtex{} & {};\n", n, tevind.bt.Value(),
|
out.Write("\tint3 iindtevcrd{} = iindtex{} >> {};\n", n, tevind.bt.Value(),
|
||||||
tev_ind_fmt_mask[u32(tevind.fmt.Value())]);
|
tev_ind_fmt_shift[u32(tevind.fmt.Value())]);
|
||||||
|
|
||||||
// bias - TODO: Check if this needs to be this complicated...
|
// bias - TODO: Check if this needs to be this complicated...
|
||||||
// indexed by bias
|
// indexed by bias
|
||||||
|
|
|
@ -828,24 +828,24 @@ ShaderCode GenPixelShader(APIType ApiType, const ShaderHostConfig& host_config,
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" case {:s}:\n",
|
" case {:s}:\n",
|
||||||
IndTexFormat::ITF_5);
|
IndTexFormat::ITF_5);
|
||||||
out.Write(" indcoord.x = (indcoord.x & 0x1f) + ((bias & 1u) != 0u ? 1 : 0);\n"
|
out.Write(" indcoord.x = (indcoord.x >> 3) + ((bias & 1u) != 0u ? 1 : 0);\n"
|
||||||
" indcoord.y = (indcoord.y & 0x1f) + ((bias & 2u) != 0u ? 1 : 0);\n"
|
" indcoord.y = (indcoord.y >> 3) + ((bias & 2u) != 0u ? 1 : 0);\n"
|
||||||
" indcoord.z = (indcoord.z & 0x1f) + ((bias & 4u) != 0u ? 1 : 0);\n"
|
" indcoord.z = (indcoord.z >> 3) + ((bias & 4u) != 0u ? 1 : 0);\n"
|
||||||
" s.AlphaBump = s.AlphaBump & 0xe0;\n"
|
" s.AlphaBump = s.AlphaBump << 5;\n"
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" case {:s}:\n",
|
" case {:s}:\n",
|
||||||
IndTexFormat::ITF_4);
|
IndTexFormat::ITF_4);
|
||||||
out.Write(" indcoord.x = (indcoord.x & 0x0f) + ((bias & 1u) != 0u ? 1 : 0);\n"
|
out.Write(" indcoord.x = (indcoord.x >> 4) + ((bias & 1u) != 0u ? 1 : 0);\n"
|
||||||
" indcoord.y = (indcoord.y & 0x0f) + ((bias & 2u) != 0u ? 1 : 0);\n"
|
" indcoord.y = (indcoord.y >> 4) + ((bias & 2u) != 0u ? 1 : 0);\n"
|
||||||
" indcoord.z = (indcoord.z & 0x0f) + ((bias & 4u) != 0u ? 1 : 0);\n"
|
" indcoord.z = (indcoord.z >> 4) + ((bias & 4u) != 0u ? 1 : 0);\n"
|
||||||
" s.AlphaBump = s.AlphaBump & 0xf0;\n"
|
" s.AlphaBump = s.AlphaBump << 4;\n"
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" case {:s}:\n",
|
" case {:s}:\n",
|
||||||
IndTexFormat::ITF_3);
|
IndTexFormat::ITF_3);
|
||||||
out.Write(" indcoord.x = (indcoord.x & 0x07) + ((bias & 1u) != 0u ? 1 : 0);\n"
|
out.Write(" indcoord.x = (indcoord.x >> 5) + ((bias & 1u) != 0u ? 1 : 0);\n"
|
||||||
" indcoord.y = (indcoord.y & 0x07) + ((bias & 2u) != 0u ? 1 : 0);\n"
|
" indcoord.y = (indcoord.y >> 5) + ((bias & 2u) != 0u ? 1 : 0);\n"
|
||||||
" indcoord.z = (indcoord.z & 0x07) + ((bias & 4u) != 0u ? 1 : 0);\n"
|
" indcoord.z = (indcoord.z >> 5) + ((bias & 4u) != 0u ? 1 : 0);\n"
|
||||||
" s.AlphaBump = s.AlphaBump & 0xf8;\n"
|
" s.AlphaBump = s.AlphaBump << 3;\n"
|
||||||
" break;\n"
|
" break;\n"
|
||||||
" }}\n"
|
" }}\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
|
Loading…
Reference in New Issue