From ac52be1a6c3264cb3c3d389a6cfbca0529350f0a Mon Sep 17 00:00:00 2001 From: water111 <48171810+water111@users.noreply.github.com> Date: Sun, 13 Aug 2023 16:06:59 -0400 Subject: [PATCH] [shrub] Fix bug with gs-prim settings (#2899) Fix the bug described in https://github.com/open-goal/jak-project/issues/2882 where some shrubs are transparent when they shouldn't be. The problem was that we never carefully looked at the settings in `gs-prim`, which has a bit to enable/disable alpha blending entirely. Now it should be correct for both jak 1 and jak 2. To see this change, you'll need to re-extract. Also adds a setting to disable saving texture .pngs, to speed up decompilation. I left it on for jak 1 (to avoid confusion for texture swapping(, but off for jak 2 for now. --- decompiler/ObjectFile/ObjectFileDB.cpp | 3 +- decompiler/config.cpp | 3 ++ decompiler/config.h | 1 + decompiler/config/jak1/jak1_config.jsonc | 2 + decompiler/config/jak2/jak2_config.jsonc | 2 + decompiler/data/tpage.cpp | 39 +++++++++++++------- decompiler/data/tpage.h | 3 +- decompiler/level_extractor/extract_shrub.cpp | 2 + decompiler/level_extractor/extract_tie.cpp | 2 +- 9 files changed, 41 insertions(+), 16 deletions(-) diff --git a/decompiler/ObjectFile/ObjectFileDB.cpp b/decompiler/ObjectFile/ObjectFileDB.cpp index 66deffca63..2febc5271e 100644 --- a/decompiler/ObjectFile/ObjectFileDB.cpp +++ b/decompiler/ObjectFile/ObjectFileDB.cpp @@ -741,7 +741,8 @@ std::string ObjectFileDB::process_tpages(TextureDB& tex_db, std::string result; for_each_obj([&](ObjectFileData& data) { if (data.name_in_dgo.substr(0, tpage_string.length()) == tpage_string) { - auto statistics = process_tpage(data, tex_db, output_path, cfg.animated_textures); + auto statistics = + process_tpage(data, tex_db, output_path, cfg.animated_textures, cfg.save_texture_pngs); total += statistics.total_textures; success += statistics.successful_textures; total_px += statistics.num_px; diff --git a/decompiler/config.cpp b/decompiler/config.cpp index 8145f69bbe..ffc1a2d60a 100644 --- a/decompiler/config.cpp +++ b/decompiler/config.cpp @@ -272,6 +272,9 @@ Config make_config_via_json(nlohmann::json& json) { config.levels_to_extract = inputs_json.at("levels_to_extract").get>(); config.levels_extract = json.at("levels_extract").get(); + if (json.contains("save_texture_pngs")) { + config.save_texture_pngs = json.at("save_texture_pngs").get(); + } if (inputs_json.contains("animated_textures")) { config.animated_textures = diff --git a/decompiler/config.h b/decompiler/config.h index 50531367a7..f9689bc31d 100644 --- a/decompiler/config.h +++ b/decompiler/config.h @@ -165,6 +165,7 @@ struct Config { std::vector levels_to_extract; bool levels_extract; + bool save_texture_pngs = false; DecompileHacks hacks; diff --git a/decompiler/config/jak1/jak1_config.jsonc b/decompiler/config/jak1/jak1_config.jsonc index cf6750aace..6a3a5aafef 100644 --- a/decompiler/config/jak1/jak1_config.jsonc +++ b/decompiler/config/jak1/jak1_config.jsonc @@ -104,6 +104,8 @@ // should we extract collision meshes? // these can be displayed in game, but makes the .fr3 files slightly larger "extract_collision": true, + // save game textures as .png files. + "save_texture_pngs": true, //////////////////////////// // PATCHING OPTIONS diff --git a/decompiler/config/jak2/jak2_config.jsonc b/decompiler/config/jak2/jak2_config.jsonc index 87f76cc7e5..ee33e295bb 100644 --- a/decompiler/config/jak2/jak2_config.jsonc +++ b/decompiler/config/jak2/jak2_config.jsonc @@ -115,6 +115,8 @@ // these can be displayed in game, but makes the .fr3 files slightly larger "extract_collision": true, + "save_texture_pngs": false, + //////////////////////////// // PATCHING OPTIONS //////////////////////////// diff --git a/decompiler/data/tpage.cpp b/decompiler/data/tpage.cpp index 005e14a578..a1579f602e 100644 --- a/decompiler/data/tpage.cpp +++ b/decompiler/data/tpage.cpp @@ -433,7 +433,8 @@ TexturePage read_texture_page(ObjectFileData& data, TPageResultStats process_tpage(ObjectFileData& data, TextureDB& texture_db, const fs::path& output_path, - const std::unordered_set& animated_textures) { + const std::unordered_set& animated_textures, + bool save_pngs) { TPageResultStats stats; auto& words = data.linked_data.words_by_seg.at(0); const auto& level_names = data.dgo_names; @@ -596,8 +597,10 @@ TPageResultStats process_tpage(ObjectFileData& data, } // write texture to a PNG. - file_util::write_rgba_png(texture_dump_dir / fmt::format("{}.png", tex.name), out.data(), - tex.w, tex.h); + if (save_pngs) { + file_util::write_rgba_png(texture_dump_dir / fmt::format("{}.png", tex.name), out.data(), + tex.w, tex.h); + } texture_db.add_texture(texture_page.id, tex_id, out, tex.w, tex.h, tex.name, texture_page.name, level_names, tex.num_mips, tex.dest[0]); stats.successful_textures++; @@ -639,8 +642,10 @@ TPageResultStats process_tpage(ObjectFileData& data, } // write texture to a PNG. - file_util::write_rgba_png(texture_dump_dir / fmt::format("{}.png", tex.name), out.data(), - tex.w, tex.h); + if (save_pngs) { + file_util::write_rgba_png(texture_dump_dir / fmt::format("{}.png", tex.name), out.data(), + tex.w, tex.h); + } texture_db.add_texture(texture_page.id, tex_id, out, tex.w, tex.h, tex.name, texture_page.name, level_names, tex.num_mips, tex.dest[0]); stats.successful_textures++; @@ -664,8 +669,10 @@ TPageResultStats process_tpage(ObjectFileData& data, } // write texture to a PNG. - file_util::write_rgba_png(texture_dump_dir / fmt::format("{}.png", tex.name), out.data(), - tex.w, tex.h); + if (save_pngs) { + file_util::write_rgba_png(texture_dump_dir / fmt::format("{}.png", tex.name), out.data(), + tex.w, tex.h); + } texture_db.add_texture(texture_page.id, tex_id, out, tex.w, tex.h, tex.name, texture_page.name, level_names, tex.num_mips, tex.dest[0]); stats.successful_textures++; @@ -705,8 +712,10 @@ TPageResultStats process_tpage(ObjectFileData& data, } // write texture to a PNG. - file_util::write_rgba_png(texture_dump_dir / fmt::format("{}.png", tex.name), out.data(), - tex.w, tex.h); + if (save_pngs) { + file_util::write_rgba_png(texture_dump_dir / fmt::format("{}.png", tex.name), out.data(), + tex.w, tex.h); + } texture_db.add_texture(texture_page.id, tex_id, out, tex.w, tex.h, tex.name, texture_page.name, level_names, tex.num_mips, tex.dest[0]); stats.successful_textures++; @@ -746,8 +755,10 @@ TPageResultStats process_tpage(ObjectFileData& data, } // write texture to a PNG. - file_util::write_rgba_png(texture_dump_dir / fmt::format("{}.png", tex.name), out.data(), - tex.w, tex.h); + if (save_pngs) { + file_util::write_rgba_png(texture_dump_dir / fmt::format("{}.png", tex.name), out.data(), + tex.w, tex.h); + } texture_db.add_texture(texture_page.id, tex_id, out, tex.w, tex.h, tex.name, texture_page.name, level_names, tex.num_mips, tex.dest[0]); stats.successful_textures++; @@ -771,8 +782,10 @@ TPageResultStats process_tpage(ObjectFileData& data, } // write texture to a PNG. - file_util::write_rgba_png(texture_dump_dir / fmt::format("{}.png", tex.name), out.data(), - tex.w, tex.h); + if (save_pngs) { + file_util::write_rgba_png(texture_dump_dir / fmt::format("{}.png", tex.name), out.data(), + tex.w, tex.h); + } texture_db.add_texture(texture_page.id, tex_id, out, tex.w, tex.h, tex.name, texture_page.name, level_names, tex.num_mips, tex.dest[0]); stats.successful_textures++; diff --git a/decompiler/data/tpage.h b/decompiler/data/tpage.h index d9592f71a8..6ee3d6df3e 100644 --- a/decompiler/data/tpage.h +++ b/decompiler/data/tpage.h @@ -16,5 +16,6 @@ struct TPageResultStats { TPageResultStats process_tpage(ObjectFileData& data, TextureDB& texture_db, const fs::path& output_path, - const std::unordered_set& animated_textures); + const std::unordered_set& animated_textures, + bool save_pngs); } // namespace decompiler diff --git a/decompiler/level_extractor/extract_shrub.cpp b/decompiler/level_extractor/extract_shrub.cpp index fdb3f95ec3..eb86c33714 100644 --- a/decompiler/level_extractor/extract_shrub.cpp +++ b/decompiler/level_extractor/extract_shrub.cpp @@ -155,11 +155,13 @@ DrawSettings adgif_to_draw_mode(const AdGifData& ad, current_mode.set_depth_write_enable(true); // todo, is this actual true current_mode.set_alpha_blend(DrawMode::AlphaBlend::SRC_SRC_SRC_SRC); current_mode.enable_fog(); + current_mode.set_ab(false); if (alpha_tpage_flag) { current_mode.set_alpha_test(DrawMode::AlphaTest::NEVER); current_mode.set_aref(0); current_mode.set_alpha_fail(GsTest::AlphaFail::FB_ONLY); + current_mode.set_ab(true); } // ADGIF 0 diff --git a/decompiler/level_extractor/extract_tie.cpp b/decompiler/level_extractor/extract_tie.cpp index e247cc5850..c6db02d090 100644 --- a/decompiler/level_extractor/extract_tie.cpp +++ b/decompiler/level_extractor/extract_tie.cpp @@ -2442,7 +2442,7 @@ void handle_draw_for_strip(tfrag3::TieTree& tree, std::vector& category_draws, const std::vector>>& packed_vert_indices, DrawMode mode, - u32 idx_in_lev_data, + s32 idx_in_lev_data, const TieStrip& strip, const TieInstanceInfo& inst, const TieInstanceFragInfo& ifrag,