Files
minecraft-pt/shaders/Lib/IndividualFunctions/WavingPlants.glsl
T

39 lines
1.1 KiB
GLSL

#include "/Lib/Settings.glsl"
#include "/Lib/Utilities.glsl"
// MinecraftPT — Waving Plants
// Wind animation for grass, plants, leaves.
#ifndef WAVING_PLANTS_GLSL
#define WAVING_PLANTS_GLSL
void WavingPlants(inout vec4 worldPos, float lightLevel){
float time = frameTimeCounter * 0.05 * WAVING_SPEED;
// Wind direction
vec2 wind = vec2(0.5, 0.3) * sin(time) + vec2(0.2);
// Amplitude by plant type
float amplitude = GRASS_AMPLITUDE;
#ifdef IS_LEAVES
amplitude = LEAVES_AMPLITUDE;
#endif
float dist = length(worldPos.xyz - gbufferModelViewInverse[3].xyz);
float fade = 1.0 - saturate(dist / WAVING_RANGE);
vec3 vertexPos = worldPos.xyz;
// Vertex-based wave
vec3 offset = vec3(wind * sin(vertexPos.x * 0.3 + vertexPos.z * 0.2 + time * 2.0), 0.0);
offset *= vertexPos.y * amplitude * fade;
// Random per-vertex jitter (height-based)
float heightFactor = vertexPos.y;
float noise = sin(vertexPos.x * 12.9898 + vertexPos.z * 78.233 + time) * 0.5 + 0.5;
offset.x += noise * amplitude * 0.5 * heightFactor * fade;
offset.z += noise * amplitude * 0.3 * heightFactor * fade;
worldPos.xyz += offset;
}
#endif