mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-08-03 15:27:13 -04:00
37 lines
1.4 KiB
GLSL
37 lines
1.4 KiB
GLSL
#version 120
|
|
|
|
#include "lib/nature/leaves.h.glsl"
|
|
|
|
uniform float osg_SimulationTime;
|
|
uniform float windSpeed;
|
|
|
|
vec4 transformLeafVertex(LeafParams params, vec4 position, vec4 color, vec3 normal)
|
|
{
|
|
// Default constants for leaf/tree animation fading from the Skyrim.ini
|
|
const float fLeafAnimDampenDistEnd = 4600.0;
|
|
const float fLeafAnimDampenDistStart = 3600.0;
|
|
|
|
float distance = length(gl_ModelViewMatrix * position);
|
|
|
|
float fade = 1.0
|
|
- clamp((distance - fLeafAnimDampenDistStart) / (fLeafAnimDampenDistEnd - fLeafAnimDampenDistStart), 0.0, 1.0);
|
|
|
|
float amplitude = color.a * params.mLeafAmplitude * fade;
|
|
|
|
if (amplitude <= 0.f)
|
|
return position;
|
|
|
|
float offset = params.mTimeOffset + position.x * 0.1 + position.y * 0.1;
|
|
float period = 0.5 * sin(0.15 * osg_SimulationTime * 6.136 + params.mTimeOffset) + 0.5;
|
|
float wind = sin(osg_SimulationTime * params.mLeafFrequency + offset) * params.mLeafAmplitude * windSpeed * period;
|
|
float spatialOffset = dot(position.xyz, vec3(1.0));
|
|
|
|
const vec2 axisFrequencyFactor = vec2(0.1, 0.25);
|
|
vec2 phase = fract(axisFrequencyFactor * (wind * params.mLeafFrequency * 10) + spatialOffset + 0.5);
|
|
vec2 leafMotion = smoothstep(0.0, 1.0, abs(2.0 * phase - 1.0));
|
|
float normalMultiplier = (leafMotion.x + 0.1 * leafMotion.y) * amplitude;
|
|
position.xyz += normal.xyz * normalMultiplier;
|
|
|
|
return position;
|
|
}
|