gunkiss/src/mvp.frag

79 lines
3.2 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 TRANSFORMATION_NONE 0
#define TRANSFORMATION_SQUIRCLE 1
in vec2 fragment_uv;
in vec3 ex_color;
in float x_center_proximity;
in vec3 original_coordinates;
in vec3 clip_coordinates;
uniform sampler2D pudding_texture;
uniform int uv_transformation = TRANSFORMATION_NONE;
uniform float coordinate_bound;
/* [-coordinate_bound, coordinate_bound] arbitrary box coordinates to [-1, 1] normalized coordinates */
vec2 normalize_coordinates(vec2 coordinates)
{
return coordinates / coordinate_bound;
}
/* [-1, 1] box coordinates to [0, 1] UV coordinates */
vec2 coordinates_to_uv(vec2 coordinates)
{
return (coordinates + 1) / 2;
}
/* coordinates in circle with radius <= 1 to box coordinates in [-1, 1] */
vec2 circle_to_box(vec2 circle)
{
float u = circle.x;
float v = circle.y;
float u_sq = pow(u, 2);
float v_sq = pow(v, 2);
float rt_2 = sqrt(2);
float x = .5 * sqrt(2 + 2 * u * rt_2 + u_sq - v_sq) - .5 * sqrt(2 - 2 * u * rt_2 + u_sq - v_sq);
float y = .5 * sqrt(2 + 2 * v * rt_2 - u_sq + v_sq) - .5 * sqrt(2 - 2 * v * rt_2 - u_sq + v_sq);
return vec2(x, y);
}
/* Apply color passed in from the vertex shader, compressing to one of 16 colors. Add retro effect
* by alternately darkening and lightening 2x2 pixel areas in a checker pattern. Add shadowing by
* brightening the color based on how near it is to the center in the X-dimension */
void retro()
{
vec3 shadowed = min(ex_color, 1.0);
float dx = abs(floor(gl_FragCoord[0]) - 480) / 480.0;
if (int(floor(gl_FragCoord[0] / 2) + floor(gl_FragCoord[1]) / 2) % 2 == 0)
{
gl_FragColor = vec4(shadowed * 1.2, 1);
}
else
{
gl_FragColor = vec4(shadowed * 0.7, 1);
}
gl_FragColor[0] = int(gl_FragColor[0] * 4) / 4.0;
gl_FragColor[1] = int(gl_FragColor[1] * 4) / 4.0;
gl_FragColor[2] = int(gl_FragColor[2] * 4) / 4.0;
gl_FragColor *= x_center_proximity;
}
void main()
{
vec2 uv = fragment_uv;
if (uv_transformation == TRANSFORMATION_SQUIRCLE)
{
vec2 normalized_circle_coordinates = normalize_coordinates(vec2(original_coordinates.x, original_coordinates.z));
uv = coordinates_to_uv(circle_to_box(normalized_circle_coordinates));
}
gl_FragColor = texture(pudding_texture, uv);
}