Browse Source

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.
master
Nico de Poel 3 years ago
parent
commit
3bc9167885
  1. 6
      rectpack/finders_interface.h
  2. 8
      texture.cpp

6
rectpack/finders_interface.h

@ -132,6 +132,9 @@ namespace rectpack2D {
subjects, subjects,
input, 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) { [](const rect_type* const a, const rect_type* const b) {
return a->area() > b->area(); return a->area() > b->area();
}, },
@ -141,9 +144,6 @@ namespace rectpack2D {
[](const rect_type* const a, const rect_type* const b) { [](const rect_type* const a, const rect_type* const b) {
return std::max(a->w, a->h) > std::max(b->w, b->h); 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) { [](const rect_type* const a, const rect_type* const b) {
return a->h > b->h; return a->h > b->h;
}, },

8
texture.cpp

@ -94,6 +94,14 @@ bool process_textures(const world_t* world, std::vector<ps1bsp_texture_t>& outTe
if (!strncmp(miptex->name, "skill", 5))// || !strcmp(miptex->name, "quake")) if (!strncmp(miptex->name, "skill", 5))// || !strcmp(miptex->name, "quake"))
ps1mip = 0; 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")) if (strcmp(miptex->name, "clip") && strcmp(miptex->name, "trigger"))
rectangles.emplace_back(rectpack2D::rect_xywh(0, 0, miptex->width >> ps1mip, miptex->height >> ps1mip)); rectangles.emplace_back(rectpack2D::rect_xywh(0, 0, miptex->width >> ps1mip, miptex->height >> ps1mip));
else else

Loading…
Cancel
Save