From 3bc91678850b2c3735d300307316a5dc79652a70 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Wed, 25 Jan 2023 10:52:48 +0100 Subject: [PATCH] Tweaked heuristics of the rectpack algorithm to produce better results for our non-square texture atlases. Ensure we don't exceed the maximum range of PS1 UV coordinates by limiting texture width and height. --- rectpack/finders_interface.h | 6 +++--- texture.cpp | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/rectpack/finders_interface.h b/rectpack/finders_interface.h index 48af3f3..3dea071 100644 --- a/rectpack/finders_interface.h +++ b/rectpack/finders_interface.h @@ -132,6 +132,9 @@ namespace rectpack2D { subjects, input, + [](const rect_type* const a, const rect_type* const b) { + return a->w > b->w; + }, [](const rect_type* const a, const rect_type* const b) { return a->area() > b->area(); }, @@ -141,9 +144,6 @@ namespace rectpack2D { [](const rect_type* const a, const rect_type* const b) { return std::max(a->w, a->h) > std::max(b->w, b->h); }, - [](const rect_type* const a, const rect_type* const b) { - return a->w > b->w; - }, [](const rect_type* const a, const rect_type* const b) { return a->h > b->h; }, diff --git a/texture.cpp b/texture.cpp index 75a7b32..1feb7cb 100644 --- a/texture.cpp +++ b/texture.cpp @@ -94,6 +94,14 @@ bool process_textures(const world_t* world, std::vector& outTe if (!strncmp(miptex->name, "skill", 5))// || !strcmp(miptex->name, "quake")) ps1mip = 0; + // Ensure we don't include any textures that are larger than the PS1 can address + // Texture pages are 64 pixels wide, effectively 128 texels in 8-bit mode, and with U offset added no U value may exceed 255 + // We could solve this more elegantly by page-aligning larger textures, but I'm not sure if that's actually necessary + while ((miptex->width >> ps1mip) > 128 || (miptex->height >> ps1mip) > 256) + ps1mip++; + + // TODO: make an exception for the QUAKE sign that's displayed on the start map. It needs to be bold and detailed, but it's too wide for the PS1 to address at full resolution, so it'll need to be broken up. + if (strcmp(miptex->name, "clip") && strcmp(miptex->name, "trigger")) rectangles.emplace_back(rectpack2D::rect_xywh(0, 0, miptex->width >> ps1mip, miptex->height >> ps1mip)); else