Skip to content

Instantly share code, notes, and snippets.

@Air-Craft
Created July 31, 2013 12:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Air-Craft/6121403 to your computer and use it in GitHub Desktop.
Save Air-Craft/6121403 to your computer and use it in GitHub Desktop.
GLSL wave function give a 2D coordinate. Thanks: http://http.developer.nvidia.com/GPUGems/gpugems_ch02.html #wave #glsl #opengl #lib
#define VTXSIZE 0.80 // Amplitude
#define WAVESIZE 100.0 // Frequency
#define FACTOR 1.2
#define SPEED 2.0
#define OCTAVES 3
// Example of the same wave function used in the vertex engine
lowp float wave(lowp float x,
lowp float y,
lowp float timer)
{
lowp float z;
int octaves;
lowp float factor;
lowp float d;
z = 0.0;
octaves = OCTAVES;
factor = FACTOR;
d = sqrt(x * x + y * y);
do {
z -= factor * cos(timer * SPEED + (1.0/factor) * x * y * WAVESIZE);
factor = factor/2.0;
octaves--;
} while (octaves > 0);
return 2.0 * VTXSIZE * d * z;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment