From 3e0706c9f91e10d982c40ead41e881062baa7010 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Mon, 23 Jan 2023 10:49:49 +0100 Subject: [PATCH] Small tweaks to make a few textures on n64start a bit nicer --- main.cpp | 10 ++++++++-- texture.cpp | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index 8ff5307..3d66cff 100644 --- a/main.cpp +++ b/main.cpp @@ -158,6 +158,12 @@ int process_faces(const world_t* world, const std::vector& tex vertexSum = vertexSum + vertexPoint; } + // If the texture doesn't tile, we don't need to correct the UVs as much + float sRange = maxS - minS; + float tRange = maxT - minT; + if (sRange < 1) sRange = 1; + if (tRange < 1) tRange = 1; + // Go over the edges again to fudge some UVs for the vertices (this second pass is only necessary because we don't have texture tiling yet) for (int edgeListIdx = 0; edgeListIdx < face->ledge_num; ++edgeListIdx) { @@ -177,8 +183,8 @@ int process_faces(const world_t* world, const std::vector& tex // Calculate texture UVs float s = (vertexPoint.dotProduct(texinfo->vectorS) + texinfo->distS) / miptex->width; float t = (vertexPoint.dotProduct(texinfo->vectorT) + texinfo->distT) / miptex->height; - s = (s - minS) / (maxS - minS); - t = (t - minT) / (maxT - minT); + if (minS < 0 || maxS > 1) s = (s - minS) / sRange; + if (minT < 0 || maxT > 1) t = (t - minT) / tRange; // Rescale the UVs to the dimensions of the mipmap we've selected for our texture atlas faceVertex.u = (unsigned char)(s * (ps1tex.w - 1)); diff --git a/texture.cpp b/texture.cpp index 78b325c..4a94c04 100644 --- a/texture.cpp +++ b/texture.cpp @@ -46,6 +46,10 @@ bool process_textures(const world_t* world, std::vector& outTe // Shrink the larger textures, but keep smaller ones at their original size int ps1mip = miptex->width > 64 || miptex->height > 64 ? 1 : 0; + // Make an exception for the difficulty selection teleporters + if (!strncmp(miptex->name, "skill", 5) || !strcmp(miptex->name, "quake")) + ps1mip = 0; + if (strcmp(miptex->name, "clip") && strcmp(miptex->name, "trigger")) rectangles.emplace_back(rectpack2D::rect_xywh(0, 0, miptex->width >> ps1mip, miptex->height >> ps1mip)); else @@ -62,7 +66,7 @@ bool process_textures(const world_t* world, std::vector& outTe report_unsuccessful, rectpack2D::flipping_option::DISABLED ) - ); + ); printf("%d textures. Packed texture atlas size: %d x %d\n", world->mipheader.numtex, result_size.w, result_size.h); unsigned char* atlas = (unsigned char*)malloc(result_size.w * result_size.h * sizeof(unsigned char));