Skip to content

Commit

Permalink
Fix texture distortion for flowing liquids (#9561)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ryvnf committed Apr 2, 2020
1 parent d7825bc commit 3d6b55d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/client/content_mapblock.cpp
Expand Up @@ -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);
}
Expand Down

0 comments on commit 3d6b55d

Please sign in to comment.