71 lines
2.7 KiB
GLSL
71 lines
2.7 KiB
GLSL
/* _______________ +---------------------------------------------------------------------------------------+
|
|
//~~~~~~~~~~~~~\\ | a game by @ohsqueezy & @sleepin |
|
|
//```````````````\\ | [ohsqueezy.itch.io] [instagram.com/sleepin] |
|
|
//_0_0_0_0_0_0_0_0_\\ | |
|
|
//_/_/_/_/___\_\_\_\_\\ | with code licensed for copy, modification and redistribution [git.nugget.fun/pudding] |
|
|
//GGGUUUNNNKKKIIISSSSSS\\ | |
|
|
//_/__/__/__/_\__\__\__\_\\ | 😀 Thank you for choosing Puddendo for your business 😀 |
|
|
+---------------------------------------------------------------------------------------+ */
|
|
#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_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) * 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;
|
|
if (effect == EFFECT_WOBBLE)
|
|
{
|
|
wobble();
|
|
}
|
|
/* passing to fragment program */
|
|
ex_color = in_color;
|
|
x_center_proximity = 1.8 - abs(in_position[0]);
|
|
fragment_uv = vertex_uv;
|
|
original_coordinates = in_position;
|
|
clip_coordinates = gl_Position.xyz;
|
|
}
|