[jak2] fix atest flag in tfrag (#2381)

Support the weird `tfrag-gs-test` and `texture-page-flag` stuff added in
jak 2. Solves some issues with partially invisible tfrags.
This commit is contained in:
water111
2023-03-21 20:40:29 -04:00
committed by GitHub
parent df646282ab
commit b18198e655
6 changed files with 45 additions and 15 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ struct MemoryUsageTracker {
void add(MemoryUsageCategory category, u32 size_bytes) { data[category] += size_bytes; }
};
constexpr int TFRAG3_VERSION = 29;
constexpr int TFRAG3_VERSION = 30;
// These vertices should be uploaded to the GPU at load time and don't change
struct PreloadedVertex {
+5
View File
@@ -1942,6 +1942,11 @@ void BspHeader::read_from_file(const decompiler::LinkedObjectFile& file,
texture_remap_table.push_back(remap);
}
}
if (version > GameVersion::Jak1) {
auto ff = get_field_ref(ref, "texture-flags", dts);
memcpy_plain_data((u8*)texture_flags, ff, sizeof(u16) * kNumTextureFlags);
}
}
std::string BspHeader::print(const PrintSettings& settings) const {
+3
View File
@@ -827,6 +827,9 @@ struct BspHeader {
// (texture-remap-table (pointer uint64) :offset-assert 52)
// (texture-remap-table-len int32 :offset-assert 56)
std::vector<TextureRemap> texture_remap_table;
static constexpr int kNumTextureFlags = 10;
u16 texture_flags[kNumTextureFlags]; // jak 2 only
//
// (texture-ids (pointer texture-id) :offset-assert 60)
// (texture-page-count int32 :offset-assert 64)
+7 -1
View File
@@ -178,9 +178,15 @@ std::vector<level_tools::TextureRemap> extract_bsp_from_level(const ObjectFileDB
if (it != hacks.missing_textures_by_level.end()) {
expected_missing_textures = it->second;
}
bool atest_disable_flag = false;
if (db.version() == GameVersion::Jak2) {
if (bsp_header.texture_flags[0] & 1) {
atest_disable_flag = true;
}
}
extract_tfrag(as_tfrag_tree, fmt::format("{}-{}", dgo_name, i++),
bsp_header.texture_remap_table, tex_db, expected_missing_textures, level_data,
false, level_name);
false, level_name, atest_disable_flag);
} else if (draw_tree->my_type() == "drawable-tree-instance-tie") {
auto as_tie_tree = dynamic_cast<level_tools::DrawableTreeInstanceTie*>(draw_tree.get());
ASSERT(as_tie_tree);
+27 -12
View File
@@ -1825,7 +1825,8 @@ u32 remap_texture(u32 original, const std::vector<level_tools::TextureRemap>& ma
void process_draw_mode(std::vector<TFragDraw>& all_draws,
const std::vector<level_tools::TextureRemap>& map,
tfrag3::TFragmentTreeKind tree_kind) {
tfrag3::TFragmentTreeKind tree_kind,
bool disable_atest_for_normal_tfrag) {
// set up the draw mode based on the code in background.gc and tfrag-methods.gc
DrawMode mode;
mode.set_alpha_test(DrawMode::AlphaTest::GEQUAL);
@@ -1838,13 +1839,24 @@ void process_draw_mode(std::vector<TFragDraw>& all_draws,
switch (tree_kind) {
case tfrag3::TFragmentTreeKind::NORMAL:
case tfrag3::TFragmentTreeKind::LOWRES:
mode.enable_at(); // :ate #x1
mode.set_alpha_test(DrawMode::AlphaTest::GEQUAL); // :atst (gs-atest greater-equal)
mode.set_aref(0x26); // :aref #x26
mode.set_alpha_fail(GsTest::AlphaFail::KEEP);
mode.enable_zt(); // :zte #x1
mode.set_depth_test(GsTest::ZTest::GEQUAL); // :ztst (gs-ztest greater-equal))
mode.disable_ab();
if (disable_atest_for_normal_tfrag) {
mode.enable_at(); // :ate #x1
mode.set_alpha_test(DrawMode::AlphaTest::ALWAYS); // :atst (gs-atest greater-equal)
mode.set_aref(0x0); // :aref #x26
mode.set_alpha_fail(GsTest::AlphaFail::KEEP);
mode.enable_zt(); // :zte #x1
mode.set_depth_test(GsTest::ZTest::GEQUAL); // :ztst (gs-ztest greater-equal))
mode.disable_ab();
} else {
mode.enable_at(); // :ate #x1
mode.set_alpha_test(DrawMode::AlphaTest::GEQUAL); // :atst (gs-atest greater-equal)
mode.set_aref(0x26); // :aref #x26
mode.set_alpha_fail(GsTest::AlphaFail::KEEP);
mode.enable_zt(); // :zte #x1
mode.set_depth_test(GsTest::ZTest::GEQUAL); // :ztst (gs-ztest greater-equal))
mode.disable_ab();
}
break;
case tfrag3::TFragmentTreeKind::TRANS:
case tfrag3::TFragmentTreeKind::LOWRES_TRANS:
@@ -2097,7 +2109,8 @@ void emulate_tfrags(int geom,
const TextureDB& tdb,
const std::vector<std::pair<int, int>>& expected_missing_textures,
bool dump_level,
const std::string& level_name) {
const std::string& level_name,
bool disable_alpha_test_in_normal) {
TFragExtractStats stats;
std::vector<u8> vu_mem;
@@ -2113,7 +2126,7 @@ void emulate_tfrags(int geom,
all_draws.insert(all_draws.end(), draws.begin(), draws.end());
}
process_draw_mode(all_draws, map, tree_out.kind);
process_draw_mode(all_draws, map, tree_out.kind, disable_alpha_test_in_normal);
auto groups = make_draw_groups(all_draws);
make_tfrag3_data(groups, tree_out, vertices, level_out.textures, tdb, expected_missing_textures,
@@ -2160,7 +2173,8 @@ void extract_tfrag(const level_tools::DrawableTreeTfrag* tree,
const std::vector<std::pair<int, int>>& expected_missing_textures,
tfrag3::Level& out,
bool dump_level,
const std::string& level_name) {
const std::string& level_name,
bool disable_atest_in_normal) {
// go through 3 lods(?)
for (int geom = 0; geom < GEOM_MAX; ++geom) {
tfrag3::TfragTree this_tree;
@@ -2223,7 +2237,8 @@ void extract_tfrag(const level_tools::DrawableTreeTfrag* tree,
std::vector<tfrag3::PreloadedVertex> vertices;
emulate_tfrags(geom, as_tfrag_array->tfragments, debug_name, map, out, this_tree, vertices,
tex_db, expected_missing_textures, dump_level, level_name);
tex_db, expected_missing_textures, dump_level, level_name,
disable_atest_in_normal);
pack_tfrag_vertices(&this_tree.packed_vertices, vertices);
extract_time_of_day(tree, this_tree);
+2 -1
View File
@@ -29,6 +29,7 @@ void extract_tfrag(const level_tools::DrawableTreeTfrag* tree,
const std::vector<std::pair<int, int>>& expected_missing_textures,
tfrag3::Level& out,
bool dump_level,
const std::string& level_name);
const std::string& level_name,
bool disable_atest_in_normal);
} // namespace decompiler