Skip to content

Commit

Permalink
restore the waving of those stupid wannabe liquids
Browse files Browse the repository at this point in the history
this also fixes waterlilies being reflective like water
  • Loading branch information
Desour committed Nov 15, 2024
1 parent d22639c commit 83736b7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions client/shaders/nodes_shader/opengl_fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Does not include wannabe liquids
#if (MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_OPAQUE || MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_BASIC || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT)
#define MATERIAL_WAVING_LIQUID 1
#endif
Expand Down
16 changes: 12 additions & 4 deletions client/shaders/nodes_shader/opengl_vertex.glsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// OpenGL < 4.3 does not support continued preprocessor lines
#define IS_WAVING_ACTUAL_LIQUID (MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_OPAQUE || MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_BASIC)
#define IS_WAVING_WANNABE_LIQUID (MATERIAL_TYPE == TILE_MATERIAL_WAVING_WANNABELIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_WAVING_WANNABELIQUID_OPAQUE || MATERIAL_TYPE == TILE_MATERIAL_WAVING_WANNABELIQUID_BASIC)
#define IS_LIQUID_WAVING ((IS_WAVING_ACTUAL_LIQUID || IS_WAVING_WANNABE_LIQUID) && ENABLE_WAVING_WATER)

uniform mat4 mWorld;
// Color of the light emitted by the sun.
uniform vec3 dayLight;
Expand Down Expand Up @@ -108,8 +113,7 @@ float smoothTriangleWave(float x)
return smoothCurve(triangleWave(x)) * 2.0 - 1.0;
}

// OpenGL < 4.3 does not support continued preprocessor lines
#if (MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_OPAQUE || MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_BASIC) && ENABLE_WAVING_WATER
#if IS_LIQUID_WAVING

//
// Simple, fast noise function.
Expand Down Expand Up @@ -166,8 +170,7 @@ void main(void)
#endif

vec4 pos = inVertexPosition;
// OpenGL < 4.3 does not support continued preprocessor lines
#if (MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_OPAQUE || MATERIAL_TYPE == TILE_MATERIAL_WAVING_LIQUID_BASIC) && ENABLE_WAVING_WATER
#if IS_LIQUID_WAVING
// Generate waves with Perlin-type noise.
// The constants are calibrated such that they roughly
// correspond to the old sine waves.
Expand All @@ -177,11 +180,16 @@ void main(void)
wavePos.x /= WATER_WAVE_LENGTH * 3.0;
wavePos.z /= WATER_WAVE_LENGTH * 2.0;
wavePos.z += animationTimer * WATER_WAVE_SPEED * 10.0;
#if IS_WAVING_ACTUAL_LIQUID
// 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
// cur_liquid.y_offset_allow_wave in content_mapblock.h.
float nodecorner_height = fract(pos.y * (1.0 / BS) + 0.5 + 0.001);
#else
// Wannabe liquids (e.g. waterlilies) always wave the same
float nodecorner_height = 1.0f;
#endif
pos.y += (snoise(wavePos) - 1.0) * WATER_WAVE_HEIGHT * 5.0 * nodecorner_height;
#elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_LEAVES && ENABLE_WAVING_LEAVES
pos.x += disp_x;
Expand Down
6 changes: 6 additions & 0 deletions src/client/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,19 +515,22 @@ ShaderInfo ShaderSource::generateShader(const std::string &name,
case TILE_MATERIAL_OPAQUE:
case TILE_MATERIAL_LIQUID_OPAQUE:
case TILE_MATERIAL_WAVING_LIQUID_OPAQUE:
case TILE_MATERIAL_WAVING_WANNABELIQUID_OPAQUE:
shaderinfo.base_material = video::EMT_SOLID;
break;
case TILE_MATERIAL_ALPHA:
case TILE_MATERIAL_PLAIN_ALPHA:
case TILE_MATERIAL_LIQUID_TRANSPARENT:
case TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT:
case TILE_MATERIAL_WAVING_WANNABELIQUID_TRANSPARENT:
shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
break;
case TILE_MATERIAL_BASIC:
case TILE_MATERIAL_PLAIN:
case TILE_MATERIAL_WAVING_LEAVES:
case TILE_MATERIAL_WAVING_PLANTS:
case TILE_MATERIAL_WAVING_LIQUID_BASIC:
case TILE_MATERIAL_WAVING_WANNABELIQUID_BASIC:
shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
break;
}
Expand Down Expand Up @@ -649,6 +652,9 @@ ShaderInfo ShaderSource::generateShader(const std::string &name,
PROVIDE(TILE_MATERIAL_WAVING_LIQUID_BASIC);
PROVIDE(TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT);
PROVIDE(TILE_MATERIAL_WAVING_LIQUID_OPAQUE);
PROVIDE(TILE_MATERIAL_WAVING_WANNABELIQUID_BASIC);
PROVIDE(TILE_MATERIAL_WAVING_WANNABELIQUID_TRANSPARENT);
PROVIDE(TILE_MATERIAL_WAVING_WANNABELIQUID_OPAQUE);
PROVIDE(TILE_MATERIAL_PLAIN);
PROVIDE(TILE_MATERIAL_PLAIN_ALPHA);

Expand Down
3 changes: 3 additions & 0 deletions src/client/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ void TileLayer::applyMaterialOptions(video::SMaterial &material) const
case TILE_MATERIAL_OPAQUE:
case TILE_MATERIAL_LIQUID_OPAQUE:
case TILE_MATERIAL_WAVING_LIQUID_OPAQUE:
case TILE_MATERIAL_WAVING_WANNABELIQUID_OPAQUE:
material.MaterialType = video::EMT_SOLID;
break;
case TILE_MATERIAL_BASIC:
case TILE_MATERIAL_WAVING_LEAVES:
case TILE_MATERIAL_WAVING_PLANTS:
case TILE_MATERIAL_WAVING_LIQUID_BASIC:
case TILE_MATERIAL_WAVING_WANNABELIQUID_BASIC:
material.MaterialTypeParam = 0.5;
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
break;
case TILE_MATERIAL_ALPHA:
case TILE_MATERIAL_LIQUID_TRANSPARENT:
case TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT:
case TILE_MATERIAL_WAVING_WANNABELIQUID_TRANSPARENT:
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
break;
default:
Expand Down
3 changes: 3 additions & 0 deletions src/client/tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ enum MaterialType{
TILE_MATERIAL_WAVING_LIQUID_BASIC,
TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT,
TILE_MATERIAL_WAVING_LIQUID_OPAQUE,
TILE_MATERIAL_WAVING_WANNABELIQUID_BASIC,
TILE_MATERIAL_WAVING_WANNABELIQUID_TRANSPARENT,
TILE_MATERIAL_WAVING_WANNABELIQUID_OPAQUE,
TILE_MATERIAL_PLAIN,
TILE_MATERIAL_PLAIN_ALPHA
};
Expand Down
6 changes: 4 additions & 2 deletions src/nodedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,10 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
material_type = TILE_MATERIAL_WAVING_LEAVES;
} else if (waving == 3) {
material_type = alpha == ALPHAMODE_OPAQUE ?
TILE_MATERIAL_WAVING_LIQUID_OPAQUE : (alpha == ALPHAMODE_CLIP ?
TILE_MATERIAL_WAVING_LIQUID_BASIC : TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT);
TILE_MATERIAL_WAVING_WANNABELIQUID_OPAQUE :
(alpha == ALPHAMODE_CLIP ?
TILE_MATERIAL_WAVING_WANNABELIQUID_BASIC :
TILE_MATERIAL_WAVING_WANNABELIQUID_TRANSPARENT);
}
break;
case NDT_TORCHLIKE:
Expand Down

0 comments on commit 83736b7

Please sign in to comment.