58 lines
1.6 KiB
GLSL
58 lines
1.6 KiB
GLSL
#version 130
|
|
|
|
#define PI 3.1415926535897932384626433832795
|
|
#define AMPLITUDE 0.2
|
|
#define PERIOD .5
|
|
#define WAVELENGTH 2.5
|
|
#define EFFECT_NONE 0
|
|
#define EFFECT_SNAKE 1
|
|
#define EFFECT_WOBBLE 2
|
|
|
|
in vec3 in_position;
|
|
in vec3 in_color;
|
|
in vec2 vertex_uv;
|
|
uniform mat4 mvp;
|
|
uniform float time;
|
|
uniform int effect = EFFECT_NONE;
|
|
out vec3 ex_color;
|
|
out float x;
|
|
out vec2 uv;
|
|
|
|
/* Offset X-coordinate according to the time step and Y-coordinate to create a wobble effect when run on
|
|
* flattened coordinates (after projection matrix has been applied) */
|
|
void wobble()
|
|
{
|
|
gl_Position.x += sin(time * 10.0) * in_position.y / 2.0;
|
|
}
|
|
|
|
/* Contort the X-coordinate according the time step and Y-coordinate using the sine function. This contorts
|
|
* the model into a sine wave along the Y-axis. It also moves the sine wave along the Y-axis using the time
|
|
* step uniform. The shape can be edited by changing the defintions for amplitude (maximum distance from
|
|
* Y-axis), wavelength (length in GL model coordinates between peaks), and period (amount of time in
|
|
* seconds it takes to loop through one wavelength cycle). */
|
|
void snake()
|
|
{
|
|
gl_Position = vec4(
|
|
in_position.x + AMPLITUDE * sin(2.0 * PI / PERIOD * (time + in_position.y * PERIOD / WAVELENGTH)), in_position.yz, 1);
|
|
}
|
|
|
|
void main()
|
|
{
|
|
if (effect == EFFECT_SNAKE)
|
|
{
|
|
snake();
|
|
}
|
|
else
|
|
{
|
|
gl_Position = vec4(in_position, 1);
|
|
}
|
|
gl_Position = mvp * gl_Position;
|
|
ex_color = in_color;
|
|
x = 1.8 - abs(in_position[0]);
|
|
if (effect == EFFECT_WOBBLE)
|
|
{
|
|
wobble();
|
|
}
|
|
uv = vertex_uv;
|
|
}
|