Created
July 31, 2013 12:02
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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