diff --git a/assets/models/kettle.fbx b/assets/models/kettle.fbx index 37b83ca..f1bfb65 100644 Binary files a/assets/models/kettle.fbx and b/assets/models/kettle.fbx differ diff --git a/assets/models/plane.fbx b/assets/models/plane.fbx index bea9bbc..41e0324 100644 Binary files a/assets/models/plane.fbx and b/assets/models/plane.fbx differ diff --git a/assets/models/plane.json b/assets/models/plane.json index 7354c8b..a8c0550 100644 --- a/assets/models/plane.json +++ b/assets/models/plane.json @@ -5,5 +5,6 @@ "modifiers": [ "gamma_correct_alpha" ], + "texture": "assets/textures/bricks1.tex", "normals": false } \ No newline at end of file diff --git a/assets/textures/bricks1.json b/assets/textures/bricks1.json index 1b4be9a..ac5ef94 100644 --- a/assets/textures/bricks1.json +++ b/assets/textures/bricks1.json @@ -2,5 +2,5 @@ "type": "texture", "psm": "palette", "alpha": false, - "file": "vjofdal_2K_Albedo.gif" + "file": "uv_tester.png" } \ No newline at end of file diff --git a/assets/textures/uv_tester.png b/assets/textures/uv_tester.png new file mode 100644 index 0000000..ddf16a1 Binary files /dev/null and b/assets/textures/uv_tester.png differ diff --git a/assets/textures/vjofdal_2K_Albedo.png b/assets/textures/vjofdal_2K_Albedo.png new file mode 100644 index 0000000..4ae4451 Binary files /dev/null and b/assets/textures/vjofdal_2K_Albedo.png differ diff --git a/dependencies/egg-library/include/egg/texture_header.hpp b/dependencies/egg-library/include/egg/texture_header.hpp index 7dcf7e3..68fc9a7 100644 --- a/dependencies/egg-library/include/egg/texture_header.hpp +++ b/dependencies/egg-library/include/egg/texture_header.hpp @@ -31,19 +31,19 @@ struct TextureFileHeader static size_t serialize(Serializer& serializer, const TextureFileHeader& texture_header, size_t alignment = 1) { - const size_t begin = serialize(serializer, texture_header.size_x); - serialize(serializer, texture_header.size_y); - serialize(serializer, texture_header.psm); - serialize(serializer, texture_header.function); - serialize(serializer, texture_header.components); - - serialize(serializer, texture_header.horizontal); - serialize(serializer, texture_header.vertical); - - serialize(serializer, texture_header.minu); - serialize(serializer, texture_header.maxu); - serialize(serializer, texture_header.minv); - serialize(serializer, texture_header.maxv); + const size_t begin = serialize(serializer, texture_header.size_x, 1); + serialize(serializer, texture_header.size_y, 1); + serialize(serializer, texture_header.psm, 1); + serialize(serializer, texture_header.function, 1); + serialize(serializer, texture_header.components, 1); + + serialize(serializer, texture_header.horizontal, 1); + serialize(serializer, texture_header.vertical, 1); + + serialize(serializer, texture_header.minu, 1); + serialize(serializer, texture_header.maxu, 1); + serialize(serializer, texture_header.minv, 1); + serialize(serializer, texture_header.maxv, 1); serialize(serializer, texture_header.clut, 1, 16); serialize(serializer, texture_header.data, 1, 16); diff --git a/dependencies/egg-ps2-graphics-lib/src/texture.cc b/dependencies/egg-ps2-graphics-lib/src/texture.cc index 4c0929e..204610c 100644 --- a/dependencies/egg-ps2-graphics-lib/src/texture.cc +++ b/dependencies/egg-ps2-graphics-lib/src/texture.cc @@ -94,7 +94,7 @@ void upload_texture(texture_descriptor& texture, void* texture_data, void* clut_ clut_height, texture.clut.psm, texture.clut.address, - 64)); + clut_width)); } printf("Texture max: %d, %d\n", texture.wrap.maxu, texture.wrap.maxv); diff --git a/src/renderer/texture.cc b/src/renderer/texture.cc index af819cb..cb3fb4d 100644 --- a/src/renderer/texture.cc +++ b/src/renderer/texture.cc @@ -22,15 +22,16 @@ Texture::Texture(Asset::Reference texture_asset_ref, AssetRegistry::Asset* in_te debug_name = Asset::lookup_path(texture_asset_ref).data(); const TextureFileHeader* texture = get_texture(); - if (texture) { + printf("Texture width height: %u, %u\n", texture->size_x, texture->size_y); + texture_descriptor.t_texbuff.info.components = texture->components; texture_descriptor.t_texbuff.info.function = texture->function; texture_descriptor.t_texbuff.psm = texture->psm; texture_descriptor.clut.psm = GS_PSM_32; - texture_descriptor.clut.load_method = CLUT_LOAD; + texture_descriptor.clut.load_method = texture->clut.length > 0 ? CLUT_LOAD : CLUT_NO_LOAD; texture_descriptor.clut.storage_mode = CLUT_STORAGE_MODE1; texture_descriptor.wrap.horizontal = texture->horizontal; diff --git a/tools/ps2-mesh-converter/src/texture/texture.cpp b/tools/ps2-mesh-converter/src/texture/texture.cpp index 7845239..a6e638b 100644 --- a/tools/ps2-mesh-converter/src/texture/texture.cpp +++ b/tools/ps2-mesh-converter/src/texture/texture.cpp @@ -84,6 +84,16 @@ union PalleteColor }; static_assert(sizeof(PalleteColor) == 4); +static PalleteColor fromColorRGB(const Magick::ColorRGB& c, bool alpha) +{ + PalleteColor new_color; + new_color.alpha = alpha ? c.alpha() * 255 : 255; + new_color.red = c.red() * 255; + new_color.green = c.green() * 255; + new_color.blue = c.blue() * 255; + return new_color; +} + union PalleteColor16 { struct @@ -129,13 +139,7 @@ static bool collectPalette(const Magick::Image& image, std::vector& pa // The pixel read doesn't work without this line. I don't understand why const void* pixel = image.getConstPixels(x, y, 1, 1); - ColorRGB c = image.pixelColor(x, y); - - PalleteColor new_color; - new_color.alpha = alpha ? c.alpha() * 255 : 255; - new_color.red = c.red() * 255; - new_color.green = c.green() * 255; - new_color.blue = c.blue() * 255; + PalleteColor new_color = fromColorRGB(image.pixelColor(x, y), alpha); colors.insert(new_color); } @@ -167,6 +171,7 @@ static bool collectPalette(const Magick::Image& image, std::vector& pa for (const PalleteColor& c : colors) { palette_colors[i] = c.color; + print("Palette color: r: %u, g: %u, b: %u, a: %u", c.red, c.green, c.blue, c.alpha); i++; } @@ -201,13 +206,7 @@ static bool writePalletizedImageData(const Magick::Image& image, const std::vect // The pixel read doesn't work without this line. I don't understand why const void* pixel = image.getConstPixels(x, y, 1, 1); - ColorRGB c = image.pixelColor(x, y); - - PalleteColor new_color; - new_color.alpha = alpha ? c.alpha() * 255 : 255; - new_color.red = c.red() * 255; - new_color.green = c.green() * 255; - new_color.blue = c.blue() * 255; + PalleteColor new_color = fromColorRGB(image.pixelColor(x, y), alpha); ptrdiff_t new_index = std::find(palette_colors.begin(), palette_colors.end(), new_color.color) - palette_colors.begin(); assert(new_index < palette_colors.size()); @@ -251,11 +250,32 @@ static std::vector serialize_texture(const TextureFileHeader& texture { std::vector out_data; Serializer texture_serializer(out_data); - serialize(texture_serializer, texture_header); + assert(serialize(texture_serializer, texture_header) == 0); texture_serializer.finish_serialization(); return out_data; } +void checkTextureHeader(const TextureFileHeader& texture_header, const std::vector& data) +{ + const TextureFileHeader& new_texture_header = *(const TextureFileHeader*)data.data(); + assert(texture_header.size_x == new_texture_header.size_x); + assert(texture_header.size_y == new_texture_header.size_y); + assert(texture_header.psm == new_texture_header.psm); + assert(texture_header.function == new_texture_header.function); + assert(texture_header.components == new_texture_header.components); + assert(texture_header.horizontal == new_texture_header.horizontal); + assert(texture_header.vertical == new_texture_header.vertical); + assert(texture_header.minu == new_texture_header.minu); + assert(texture_header.maxu == new_texture_header.maxu); + assert(texture_header.minv == new_texture_header.minv); + assert(texture_header.maxv == new_texture_header.maxv); + + print("Texture header length: %lu", texture_header.data.length); + assert(memcmp(texture_header.data.get_ptr(), new_texture_header.data.get_ptr(), texture_header.data.length) == 0); + + assert(memcmp(texture_header.clut.get_ptr(), new_texture_header.clut.get_ptr(), texture_header.clut.length) == 0); +} + bool parseTexture(std::string_view path, const Json::Value& obj, std::vector& out_data) { using namespace Magick; @@ -311,6 +331,7 @@ bool parseTexture(std::string_view path, const Json::Value& obj, std::vector