75 lines
2.6 KiB
GLSL
75 lines
2.6 KiB
GLSL
#version 300 es
|
|
|
|
/* _______________ ,--------------------------------------------------------.
|
|
//`````````````\\ \ \
|
|
//~~~~~~~~~~~~~~~\\ \ by @ohsqueezy & @sleepin \
|
|
//=================\\ \ [ohsqueezy.itch.io] [sleepin.itch.io] \
|
|
// \\ \ \
|
|
// \\ \ zlib licensed code at [git.nugget.fun/nugget/gunkiss] \
|
|
// ☆ GUNKISS ☆ \\ \ \
|
|
//_________________________\\ `--------------------------------------------------------*/
|
|
|
|
/* The precision declaration is required by OpenGL ES */
|
|
precision mediump float;
|
|
|
|
#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 vertex_position;
|
|
in vec3 vertex_color;
|
|
in vec2 vertex_uv;
|
|
uniform mat4 mvp;
|
|
uniform float time;
|
|
uniform int effect;
|
|
out vec3 ex_color;
|
|
out float x_center_proximity;
|
|
out vec2 fragment_uv;
|
|
out vec3 original_coordinates;
|
|
out vec3 clip_coordinates;
|
|
|
|
/* 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) * vertex_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(
|
|
vertex_position.x + AMPLITUDE * sin(2.0 * PI / PERIOD * (time + vertex_position.y * PERIOD / WAVELENGTH)), vertex_position.yz, 1);
|
|
}
|
|
|
|
void main()
|
|
{
|
|
if (effect == EFFECT_SNAKE)
|
|
{
|
|
snake();
|
|
}
|
|
else
|
|
{
|
|
gl_Position = vec4(vertex_position, 1);
|
|
}
|
|
gl_Position = mvp * gl_Position;
|
|
if (effect == EFFECT_WOBBLE)
|
|
{
|
|
wobble();
|
|
}
|
|
/* passing to fragment program */
|
|
ex_color = vertex_color;
|
|
x_center_proximity = 1.8 - abs(vertex_position[0]);
|
|
fragment_uv = vertex_uv;
|
|
original_coordinates = vertex_position;
|
|
clip_coordinates = gl_Position.xyz;
|
|
}
|