Browse Source

Apply uv offsets only on non-repeating textures, to avoid overflow errors on textures near the texture page edges. Fixes wonky textures on maps like E1M1 and E1M8.

master
Nico de Poel 3 years ago
parent
commit
39fa8bcb14
  1. 8
      tesselate.cpp
  2. 7
      texture.cpp

8
tesselate.cpp

@ -42,8 +42,8 @@ std::vector<Tesselator::Polygon> Tesselator::tesselateFace(const face_t* face)
// Transform the vertex to texture space and calculate the texture UV bounds
Vec3 st = textureTrsf.TransformPoint(vertexPoint);
if (st.x > maxS) maxS = ceil(st.x); if (st.x < minS) minS = floor(st.x);
if (st.y > maxT) maxT = ceil(st.y); if (st.y < minT) minT = floor(st.y);
if (st.x > maxS) maxS = st.x; if (st.x < minS) minS = st.x;
if (st.y > maxT) maxT = st.y; if (st.y < minT) minT = st.y;
contour.vertex[edgeListIdx] = gpc_vertex{ st.x, st.y };
}
@ -68,9 +68,9 @@ std::vector<Tesselator::Polygon> Tesselator::tesselateFace(const face_t* face)
minT = floor(minT / cellHeight) * cellHeight;
}
for (double y = minT; y < maxT; y += cellHeight)
for (double y = floor(minT); y < ceil(maxT); y += cellHeight)
{
for (double x = minS; x < maxS; x += cellWidth)
for (double x = floor(minS); x < ceil(maxS); x += cellWidth)
{
// Create a square polygon that covers the entire cell
gpc_polygon cell = { 0 };

7
texture.cpp

@ -351,11 +351,16 @@ bool process_textures(const world_t* world, TextureList& outTextures)
tex.uoffs = (u_char)((x % 64) << (2 - outTim.format));
tex.voffs = (u_char)(y & 0xFF);
if (texture_isRepeatable(miptex))
tex.ps1tex.twin = getTexWindow(tex.uoffs, tex.voffs, tex.w, tex.h); // TODO: figure out the right offsets that are multiples of w and h; NOTE: if uoffs has to >> 1, then w probably has to as well
{
tex.ps1tex.twin = getTexWindow(tex.uoffs, tex.voffs, tex.w, tex.h);
tex.uoffs = tex.voffs = 0; // Apply offset only through the texture window, otherwise we can get overflowing UV values
}
else
{
tex.ps1tex.twin = getTexWindow(0, 0, 0, 0);
}
}
}
// Use the smallest mip level for analysis, should be good enough
analyze_texture(world->textures[texNum * 4 + 3], (miptex->width >> 3) * (miptex->height >> 3), palette, tex);

Loading…
Cancel
Save