Skip to content

Commit

Permalink
per-node waving check
Browse files Browse the repository at this point in the history
  • Loading branch information
Desour committed Nov 15, 2024
1 parent 0bbcb92 commit d22639c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion client/shaders/nodes_shader/opengl_vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void main(void)
// Flowing liquid waveheight is scaled by node height, so it doesn't wave
// into the floor.
// Also, vertices that are exactly on the border do not wave, see
// liquid_y_offset_allow_wave in content_mapblock.h.
// cur_liquid.y_offset_allow_wave in content_mapblock.h.
float nodecorner_height = fract(pos.y * (1.0 / BS) + 0.5 + 0.001);
pos.y += (snoise(wavePos) - 1.0) * WATER_WAVE_HEIGHT * 5.0 * nodecorner_height;
#elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_LEAVES && ENABLE_WAVING_LEAVES
Expand Down
18 changes: 12 additions & 6 deletions src/client/content_mapblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ MapblockMeshGenerator::MapblockMeshGenerator(MeshMakeData *input, MeshCollector
meshmanip(mm),
blockpos_nodes(data->m_blockpos * MAP_BLOCKSIZE),
smooth_liquids(g_settings->getBool("enable_water_reflections")),
liquid_y_offset_allow_wave(g_settings->getBool("enable_waving_water") ? -0.002f : 0.0f)
enable_waving_water(g_settings->getBool("enable_waving_water"))
{
}

Expand Down Expand Up @@ -475,10 +475,14 @@ void MapblockMeshGenerator::drawSolidNode()
f32 texture_coord_buf[24];
box.MinEdge += cur_node.origin;
box.MaxEdge += cur_node.origin;
if (cur_node.f->drawtype == NDT_LIQUID) {
cur_liquid.y_offset_allow_wave =
enable_waving_water && cur_node.f->waving == 3 ? -0.002f : 0.0f;
}
generateCuboidTextureCoords(box, texture_coord_buf);
/*if (cur_node.f->drawtype == NDT_LIQUID && top_corner_waving == 15) {
// FIXME: don't allow wave if a neighbor on vertex side has no top
box.MaxEdge.Y += BS * liquid_y_offset_allow_wave;
box.MaxEdge.Y += BS * cur_liquid.y_offset_allow_wave;
}*/
if (data->m_smooth_lighting) {
LightPair lights[6][4];
Expand All @@ -496,7 +500,7 @@ void MapblockMeshGenerator::drawSolidNode()
if (face == 0 && cur_node.f->drawtype == NDT_LIQUID) {
for (size_t i = 0; i < 4; ++i) {
if (top_corner_waving & (1 << i)) {
vertices[i].Pos.Y += BS * liquid_y_offset_allow_wave;
vertices[i].Pos.Y += BS * cur_liquid.y_offset_allow_wave;
}
}
}
Expand Down Expand Up @@ -580,6 +584,8 @@ void MapblockMeshGenerator::prepareLiquidNodeDrawing()
if (f2.solidness > 1)
cur_liquid.draw_bottom = false;
}
cur_liquid.y_offset_allow_wave = enable_waving_water && cur_node.f->waving == 3 ?
-0.002f : 0.0f;

if (data->m_smooth_lighting)
return; // don't need to pre-compute anything in this case
Expand Down Expand Up @@ -733,14 +739,14 @@ void MapblockMeshGenerator::drawLiquidSides()
pos.Z = (base.Z - 0.5f) * BS;
if (vertex.v) {
pos.Y = (neighbor.is_same_liquid ?
cur_liquid.corner_levels[base.Z][base.X] + liquid_y_offset_allow_wave :
cur_liquid.corner_levels[base.Z][base.X] + cur_liquid.y_offset_allow_wave :
-0.5f)
* BS;
} else if (cur_liquid.top_is_same_liquid) {
pos.Y = 0.5f * BS;
} else {
pos.Y = (cur_liquid.corner_levels[base.Z][base.X]
+ liquid_y_offset_allow_wave) * BS;
+ cur_liquid.y_offset_allow_wave) * BS;
v += 0.5f - cur_liquid.corner_levels[base.Z][base.X];
}

Expand Down Expand Up @@ -788,7 +794,7 @@ void MapblockMeshGenerator::drawLiquidTop()

// FIXME: don't allow wave if a neighbor on vertex side has no top
vertices[i].Pos.Y += (cur_liquid.corner_levels[w][u]
+ liquid_y_offset_allow_wave) * BS;
+ cur_liquid.y_offset_allow_wave) * BS;
if (data->m_smooth_lighting)
vertices[i].Color = blendLightColor(vertices[i].Pos);
vertices[i].Pos += cur_node.origin;
Expand Down
14 changes: 8 additions & 6 deletions src/client/content_mapblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,8 @@ class MapblockMeshGenerator
const v3s16 blockpos_nodes;

// options
const bool smooth_liquids = false;
// Liquid vertices do not wave if their y pos is exactly on (at most 0.001 above
// (in node length)) the node border. If you want them to wave anyways, add this
// offset (in node length).
// This is 0 if waving liquids are off, -0.002f otherwise.
const f32 liquid_y_offset_allow_wave;
const bool smooth_liquids;
const bool enable_waving_water;

// current node
struct {
Expand Down Expand Up @@ -122,6 +118,12 @@ class MapblockMeshGenerator
video::SColor color_top;
NeighborData neighbors[3][3];
f32 corner_levels[2][2];
// Liquid vertices do not wave if their y pos is exactly on (at most 0.001
// above (in node length)) the node border. If you want them to wave
// anyways, add this offset (in node length).
// This is 0 if not a waving liquid, or if waving liquids are off,
// -0.002f otherwise.
f32 y_offset_allow_wave = 0.0f;
};
LiquidData cur_liquid;

Expand Down

0 comments on commit d22639c

Please sign in to comment.