[jak 2] ETIE (#2326)

Definitely needs a clean up pass, but I think the functionality is very
close.

There's a few "hacks" still:
- I am using the emerc logic for environment mapping, which doesn't care
about the length of the normals. I can't figure out how the normal
scaling worked in etie. I want to do a little bit more experimentation
with this before merging.
- There is some part about adgifs for TIE and ETIE that I don't
understand. The clearly correct behavior of TIE/ETIE is that the alpha
settings from the adgif shader are overwritten by the settings from the
renderer. But I can't figure out how this happens in all cases.
- Fade out is completely disabled. I think this is fine because the
performance difference isn't bad. But if you are comparing screenshots
with PCSX2, it will make things look a tiny bit different.
This commit is contained in:
water111
2023-03-17 20:35:26 -04:00
committed by GitHub
parent 6670124296
commit 2fa4a23ea1
41 changed files with 9101 additions and 858 deletions
+36
View File
@@ -445,6 +445,15 @@ std::string TFragment::print(const PrintSettings& settings, int indent) const {
return result;
}
void memcpy_plain_data(u8* dst, const Ref& ref, size_t size_bytes) {
const auto& words = ref.data->words_by_seg.at(ref.seg);
for (size_t i = 0; i < size_bytes; i++) {
size_t byte_offset = ref.byte_offset + i;
u8 byte = words.at(byte_offset / 4).get_byte(byte_offset % 4);
memcpy(dst + i, &byte, sizeof(u8));
}
}
void TieFragment::read_from_file(TypedRef ref,
const decompiler::DecompilerTypeSystem& dts,
DrawStats* stats,
@@ -492,6 +501,15 @@ void TieFragment::read_from_file(TypedRef ref,
}
stats->total_tie_prototype_tris += num_tris;
if (version > GameVersion::Jak1) {
u16 normals_qwc = read_plain_data_field<u16>(ref, "normal-count", dts);
if (normals_qwc) {
normals.resize(16 * normals_qwc);
auto normals_data_ref = deref_label(get_field_ref(ref, "normal-ref", dts));
memcpy_plain_data((u8*)normals.data(), normals_data_ref, normals_qwc * 16);
}
}
}
std::string TieFragment::print(const PrintSettings& /*settings*/, int indent) const {
@@ -1037,6 +1055,24 @@ void PrototypeBucketTie::read_from_file(TypedRef ref,
for (int i = 0; i < int(8 * time_of_day.height); i++) {
time_of_day.colors.push_back(deref_u32(palette, 3 + i));
}
if (version > GameVersion::Jak1) {
auto fr = get_field_ref(ref, "envmap-shader", dts);
const auto& word = fr.data->words_by_seg.at(fr.seg).at(fr.byte_offset / 4);
if (word.kind() == decompiler::LinkedWord::PTR) {
has_envmap_shader = true;
Ref envmap_shader_ref(deref_label(fr));
for (int i = 0; i < 5 * 16; i++) {
int byte = envmap_shader_ref.byte_offset + i;
u8 val =
ref.ref.data->words_by_seg.at(envmap_shader_ref.seg).at(byte / 4).get_byte(byte % 4);
envmap_shader[i] = val;
}
}
u32 tint = read_plain_data_field<u32>(ref, "tint-color", dts);
memcpy(tint_color.data(), &tint, 4);
}
}
std::string PrototypeBucketTie::print(const PrintSettings& settings, int indent) const {
+6 -1
View File
@@ -6,6 +6,7 @@
#include <vector>
#include "common/common_types.h"
#include "common/math/Vector.h"
#include "common/versions.h"
#include "decompiler/level_extractor/common_formats.h"
@@ -406,6 +407,8 @@ struct TieFragment : public Drawable {
std::string debug_label_name;
std::vector<s8> normals;
// todo, lots more
};
@@ -479,7 +482,9 @@ struct PrototypeBucketTie {
TimeOfDayPalette time_of_day;
// todo envmap shader
bool has_envmap_shader = false;
u8 envmap_shader[5 * 16]; // jak 2 only
math::Vector<u8, 4> tint_color;
// todo collide-frag
DrawableInlineArrayCollideFragment collide_frag;
// todo tie-colors
+2 -3
View File
@@ -2070,9 +2070,8 @@ void make_tfrag3_data(std::map<u32, std::vector<GroupedDraw>>& draws,
vtx.z = vert.pre_cam_trans_pos.z();
vtx.s = vert.stq.x();
vtx.t = vert.stq.y();
vtx.q_unused = vert.stq.z();
// if this is true, we can remove a divide in the shader
ASSERT(vtx.q_unused == 1.f);
// because this is true, we can remove a divide in the shader
ASSERT(vert.stq.z() == 1.f);
vtx.color_index = vert.rgba / 4;
// ASSERT((vert.rgba >> 2) < 1024); spider cave has 2048?
ASSERT((vert.rgba & 3) == 0);
File diff suppressed because it is too large Load Diff