Skip to content

Commit

Permalink
Merge remote-tracking branch 'vanilla/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
dallmeyer committed Nov 28, 2024
2 parents 8c46d07 + 4c2e1a8 commit 5d8bf33
Show file tree
Hide file tree
Showing 604 changed files with 34,140 additions and 14,025 deletions.
27 changes: 27 additions & 0 deletions common/util/gltf_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,28 @@ EnvmapSettings envmap_settings_from_gltf(const tinygltf::Material& mat) {
return settings;
}

bool material_has_envmap(const tinygltf::Material& mat) {
return mat.extensions.contains("KHR_materials_specular");
}

bool envmap_is_valid(const tinygltf::Material& mat, bool die) {
if (material_has_envmap(mat) && mat.pbrMetallicRoughness.metallicRoughnessTexture.index < 0) {
std::string error = fmt::format(
"Material \"{}\" has specular property set, but is missing a metallic roughness texture! "
"Check "
"that the Specular IOR level for the material is at the default of 0.5 if this is "
"unintended.",
mat.name);
if (die) {
lg::die(error);
} else {
lg::error(error);
}
return false;
}
return true;
}

std::optional<int> find_single_skin(const tinygltf::Model& model,
const std::vector<NodeWithTransform>& all_nodes) {
std::optional<int> skin_index;
Expand All @@ -695,6 +717,11 @@ std::optional<int> find_single_skin(const tinygltf::Model& model,
return skin_index;
}

int get_joint_count(const tinygltf::Model& model, int skin_idx) {
const auto& skin = model.skins.at(skin_idx);
return skin.joints.size();
}

std::vector<float> extract_floats(const tinygltf::Model& model, int accessor_idx) {
const auto& accessor = model.accessors[accessor_idx];
const auto& buffer_view = model.bufferViews[accessor.bufferView];
Expand Down
3 changes: 3 additions & 0 deletions common/util/gltf_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,16 @@ struct EnvmapSettings {
};

EnvmapSettings envmap_settings_from_gltf(const tinygltf::Material& mat);
bool material_has_envmap(const tinygltf::Material& mat);
bool envmap_is_valid(const tinygltf::Material& mat, bool die);

/*!
* Find the index of the skin for this model. Returns nullopt if there is no skin, the index of the
* skin if there is a single skin used, or fatal error if there are multiple skins.
*/
std::optional<int> find_single_skin(const tinygltf::Model& model,
const std::vector<NodeWithTransform>& all_nodes);
int get_joint_count(const tinygltf::Model& model, int skin_idx);

template <typename T, int n>
std::vector<math::Vector<T, n>> extract_vec(const tinygltf::Model& model,
Expand Down
2 changes: 1 addition & 1 deletion decompiler/config/jak1/ntsc_v1/tex-info.min.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion decompiler/config/jak2/ntsc_v1/tex-info.min.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion decompiler/config/jak3/ntsc_v1/tex-info.min.json

Large diffs are not rendered by default.

28 changes: 16 additions & 12 deletions decompiler/level_extractor/merc_replacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ using namespace gltf_util;

namespace decompiler {

bool material_has_envmap(const tinygltf::Material& mat) {
return mat.extensions.contains("KHR_materials_specular");
}

void extract(const std::string& name,
MercExtractData& out,
const tinygltf::Model& model,
Expand All @@ -22,6 +18,11 @@ void extract(const std::string& name,
int mesh_count = 0;
int prim_count = 0;
bool has_envmaps = false;
int joints = 3;
auto skin_idx = find_single_skin(model, all_nodes);
if (skin_idx) {
joints += get_joint_count(model, *skin_idx);
}

for (const auto& n : all_nodes) {
const auto& node = model.nodes[n.node_idx];
Expand Down Expand Up @@ -80,8 +81,8 @@ void extract(const std::string& name,
tfrag3::MercEffect e;
tfrag3::MercEffect envmap_eff;
out.new_model.name = name;
out.new_model.max_bones = 100; // idk
out.new_model.max_draws = 200;
out.new_model.max_bones = joints;
out.new_model.max_draws = 0;

auto process_normal_draw = [&](tfrag3::MercEffect& eff, int mat_idx, const tfrag3::MercDraw& d_) {
const auto& mat = model.materials[mat_idx];
Expand Down Expand Up @@ -129,14 +130,13 @@ void extract(const std::string& name,
return;
}

int roughness_tex_idx = mat.pbrMetallicRoughness.metallicRoughnessTexture.index;
ASSERT(roughness_tex_idx >= 0);
const auto& base_tex = model.textures[base_tex_idx];
ASSERT(base_tex.sampler >= 0);
ASSERT(base_tex.source >= 0);
gltf_util::setup_draw_mode_from_sampler(model.samplers.at(base_tex.sampler), &draw.mode);
gltf_util::setup_alpha_from_material(mat, &draw.mode);
const auto& roughness_tex = model.textures.at(roughness_tex_idx);
const auto& roughness_tex =
model.textures.at(mat.pbrMetallicRoughness.metallicRoughnessTexture.index);
ASSERT(roughness_tex.sampler >= 0);
ASSERT(roughness_tex.source >= 0);

Expand Down Expand Up @@ -164,15 +164,13 @@ void extract(const std::string& name,
if (!material_has_envmap(mat)) {
process_normal_draw(e, mat_idx, d_);
} else {
envmap_is_valid(mat, true);
has_envmaps = true;
envmap_eff.has_envmap = true;
process_envmap_draw(envmap_eff, mat_idx, d_);
}
}

lg::info("total of {} unique materials ({} normal, {} envmap)",
e.all_draws.size() + envmap_eff.all_draws.size(), e.all_draws.size(),
envmap_eff.all_draws.size());
// in case a model only has envmap draws, we don't push the normal merc effect
if (!e.all_draws.empty()) {
out.new_model.effects.push_back(e);
Expand All @@ -181,6 +179,12 @@ void extract(const std::string& name,
out.new_model.effects.push_back(envmap_eff);
}

for (auto& effect : out.new_model.effects) {
out.new_model.max_draws += effect.all_draws.size();
}

lg::info("total of {} unique materials ({} normal, {} envmap)", out.new_model.max_draws,
e.all_draws.size(), envmap_eff.all_draws.size());
lg::info("Merged {} meshes and {} prims into {} vertices", mesh_count, prim_count,
out.new_vertices.size());
}
Expand Down
6 changes: 2 additions & 4 deletions game/kernel/jak1/kmachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,12 @@ u64 kopen(u64 fs, u64 name, u64 mode) {
file_stream->name = name;
file_stream->flags = 0;
lg::print("****** CALL TO kopen() ******\n");
char buffer[128];
// sprintf(buffer, "host:%s", Ptr<String>(name)->data());
sprintf(buffer, "%s", Ptr<String>(name)->data());
if (!strcmp(info(Ptr<Symbol>(mode))->str->data(), "read")) {
file_stream->file = sceOpen(buffer, SCE_RDONLY);
file_stream->file = sceOpen(Ptr<String>(name)->data(), SCE_RDONLY);
} else {
// 0x602
file_stream->file = sceOpen(buffer, SCE_TRUNC | SCE_CREAT | SCE_WRONLY);
file_stream->file = sceOpen(Ptr<String>(name)->data(), SCE_TRUNC | SCE_CREAT | SCE_WRONLY);
}

return fs;
Expand Down
8 changes: 3 additions & 5 deletions game/kernel/jak2/kmachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,19 +505,17 @@ u64 kopen(u64 fs, u64 name, u64 mode) {
file_stream->name = name;
file_stream->flags = 0;
lg::print("****** CALL TO kopen() ******\n");
char buffer[128];
// sprintf(buffer, "host:%s", Ptr<String>(name)->data());
sprintf(buffer, "%s", Ptr<String>(name)->data());
if (!strcmp(symbol_name_cstr(*Ptr<Symbol4<u8>>(mode)), "read")) {
// 0x1
file_stream->file = sceOpen(buffer, SCE_RDONLY);
file_stream->file = sceOpen(Ptr<String>(name)->data(), SCE_RDONLY);
} else if (!strcmp(symbol_name_cstr(*Ptr<Symbol4<u8>>(mode)), "append")) {
// new in jak 2!
// 0x202
file_stream->file = sceOpen(buffer, SCE_CREAT | SCE_WRONLY);
file_stream->file = sceOpen(Ptr<String>(name)->data(), SCE_CREAT | SCE_WRONLY);
} else {
// 0x602
file_stream->file = sceOpen(buffer, SCE_TRUNC | SCE_CREAT | SCE_WRONLY);
file_stream->file = sceOpen(Ptr<String>(name)->data(), SCE_TRUNC | SCE_CREAT | SCE_WRONLY);
}

return fs;
Expand Down
8 changes: 3 additions & 5 deletions game/kernel/jak3/kmachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,17 @@ u64 kopen(u64 fs, u64 name, u64 mode) {
file_stream->name = name;
file_stream->flags = 0;
lg::print("****** CALL TO kopen() ******\n");
char buffer[128];
// sprintf(buffer, "host:%s", Ptr<String>(name)->data());
sprintf(buffer, "%s", Ptr<String>(name)->data());
if (!strcmp(sym_to_cstring(Ptr<Symbol4<u8>>(mode)), "read")) {
// 0x1
file_stream->file = ee::sceOpen(buffer, SCE_RDONLY);
file_stream->file = ee::sceOpen(Ptr<String>(name)->data(), SCE_RDONLY);
} else if (!strcmp(sym_to_cstring(Ptr<Symbol4<u8>>(mode)), "append")) {
// new in jak 2!
// 0x202
file_stream->file = ee::sceOpen(buffer, SCE_CREAT | SCE_WRONLY);
file_stream->file = ee::sceOpen(Ptr<String>(name)->data(), SCE_CREAT | SCE_WRONLY);
} else {
// 0x602
file_stream->file = ee::sceOpen(buffer, SCE_TRUNC | SCE_CREAT | SCE_WRONLY);
file_stream->file = ee::sceOpen(Ptr<String>(name)->data(), SCE_TRUNC | SCE_CREAT | SCE_WRONLY);
}

return fs;
Expand Down
2 changes: 1 addition & 1 deletion game/overlord/jak3/iso.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ void ProcessMusic() {
// handle pausing request.
if (!g_bMusicIsPaused && g_bMusicPause) {
cmd = FindMusicStreamName(g_szCurrentMusicName);
if (cmd && cmd->id & !cmd->flags.stop) {
if (cmd && cmd->id && !cmd->flags.stop) {
PauseVAG(cmd);
}
g_bMusicIsPaused = true;
Expand Down
Loading

0 comments on commit 5d8bf33

Please sign in to comment.