Skip to content

Instantly share code, notes, and snippets.

@rayyee
Forked from prespondek/lmap_wave.vert
Last active August 29, 2015 14:20
Show Gist options
  • Save rayyee/a926f512e4f56d3f0f10 to your computer and use it in GitHub Desktop.
Save rayyee/a926f512e4f56d3f0f10 to your computer and use it in GitHub Desktop.
attribute vec4 a_position;
attribute vec3 a_normal;
attribute vec2 a_texCoord;
attribute vec2 a_texCoord1;
varying vec2 v_texture_coord;
varying vec2 v_texture_coord1;
// height of the wave in world units.
uniform float u_amplitude;
// lenght between crests of the wave in world units.
uniform float u_wavelenght;
// a value between 0 and 1. Usually just feed in cumulative delta time from your app.
// Scale this value to make the waves go slower or faster.
uniform float u_time;
void main(void)
{
// find the amplitude (between 0 and 1) of each vertex in the wave based on the wavelength.
// Adding in time value gives constant motion to the wave.
float factor = fract((a_position.y + (u_time * u_wavelenght)) / u_wavelenght);
// this offsets the wave to give you a scale between 0 and 1 and falling back to 0 again. Without it you will
// get a sawtooth wave rather than a nice up and down motion.
factor = abs((factor * 2.0) - 1.0);
// vertex gets moved along it's normal.
vec4 newPos = vec4(a_position.x + (a_normal.x * factor * u_amplitude),
a_position.y + (a_normal.y * factor * u_amplitude),
a_position.z + (a_normal.z * factor * u_amplitude),
a_position.a);
gl_Position = CC_MVPMatrix * newPos;
// values to be passed to fragment shader
v_texture_coord = a_texCoord;
v_texture_coord.y = (1.0 - v_texture_coord.y);
v_texture_coord1 = a_texCoord1;
v_texture_coord1.y = (1.0 - v_texture_coord1.y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment