aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElias Åström <eliast.croc@gmail.com>2020-04-02 19:24:35 +0200
committerGitHub <noreply@github.com>2020-04-02 19:24:35 +0200
commit3d6b55d3e9b91e6afdbfdcea0268dfb88c69c1c2 (patch)
treee6dc65ea1e0f6e45f753d2b6e1e604d6902e73aa
parentd7825bca1b3e0ed21c766da3b86c69f1da98917f (diff)
downloadminetest-3d6b55d3e9b91e6afdbfdcea0268dfb88c69c1c2.tar.gz
minetest-3d6b55d3e9b91e6afdbfdcea0268dfb88c69c1c2.tar.bz2
minetest-3d6b55d3e9b91e6afdbfdcea0268dfb88c69c1c2.zip
Fix texture distortion for flowing liquids (#9561)
Previously textures of the side faces on flowing liquid nodes would become distorted on different axis depending on the liquid level. This is because the nodes always had the same texture coordinates, even when the generated face could have different sizes. This solves that problem by adjusting the texture coordinates for the vertices making up the top of the faces, so the textures will not look compressed for smaller faces.
-rw-r--r--src/client/content_mapblock.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp
index 5be0caf19..9b4fd221e 100644
--- a/src/client/content_mapblock.cpp
+++ b/src/client/content_mapblock.cpp
@@ -556,17 +556,24 @@ void MapblockMeshGenerator::drawLiquidSides()
for (int j = 0; j < 4; j++) {
const UV &vertex = base_vertices[j];
const v3s16 &base = face.p[vertex.u];
+ float v = vertex.v;
+
v3f pos;
- pos.X = (base.X - 0.5) * BS;
- pos.Z = (base.Z - 0.5) * BS;
- if (vertex.v)
- pos.Y = neighbor.is_same_liquid ? corner_levels[base.Z][base.X] : -0.5 * BS;
- else
- pos.Y = !top_is_same_liquid ? corner_levels[base.Z][base.X] : 0.5 * BS;
+ pos.X = (base.X - 0.5f) * BS;
+ pos.Z = (base.Z - 0.5f) * BS;
+ if (vertex.v) {
+ pos.Y = neighbor.is_same_liquid ? corner_levels[base.Z][base.X] : -0.5f * BS;
+ } else if (top_is_same_liquid) {
+ pos.Y = 0.5f * BS;
+ } else {
+ pos.Y = corner_levels[base.Z][base.X];
+ v += (0.5f * BS - corner_levels[base.Z][base.X]) / BS;
+ }
+
if (data->m_smooth_lighting)
color = blendLightColor(pos);
pos += origin;
- vertices[j] = video::S3DVertex(pos.X, pos.Y, pos.Z, 0, 0, 0, color, vertex.u, vertex.v);
+ vertices[j] = video::S3DVertex(pos.X, pos.Y, pos.Z, 0, 0, 0, color, vertex.u, v);
};
collector->append(tile_liquid, vertices, 4, quad_indices, 6);
}