From d22639cfc309f70f3c1d829a76dbaacaac18905c Mon Sep 17 00:00:00 2001 From: Desour Date: Fri, 15 Nov 2024 19:06:37 +0100 Subject: [PATCH] per-node waving check --- client/shaders/nodes_shader/opengl_vertex.glsl | 2 +- src/client/content_mapblock.cpp | 18 ++++++++++++------ src/client/content_mapblock.h | 14 ++++++++------ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/client/shaders/nodes_shader/opengl_vertex.glsl b/client/shaders/nodes_shader/opengl_vertex.glsl index 016d8743130ad..8455e312f02fc 100644 --- a/client/shaders/nodes_shader/opengl_vertex.glsl +++ b/client/shaders/nodes_shader/opengl_vertex.glsl @@ -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 diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp index 1c2b555f11f4b..76a3e0411b03f 100644 --- a/src/client/content_mapblock.cpp +++ b/src/client/content_mapblock.cpp @@ -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")) { } @@ -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]; @@ -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; } } } @@ -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 @@ -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]; } @@ -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; diff --git a/src/client/content_mapblock.h b/src/client/content_mapblock.h index 6c3ce3db4bad7..e1ca188fc450b 100644 --- a/src/client/content_mapblock.h +++ b/src/client/content_mapblock.h @@ -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 { @@ -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;