84 lines
3.1 KiB
GLSL
84 lines
3.1 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 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;
|
|
uniform float coordinate_bound;
|
|
out vec4 output_color;
|
|
|
|
/* [-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 (1.0 + coordinates) / 2.0;
|
|
}
|
|
|
|
/* 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.0);
|
|
float v_sq = pow(v, 2.0);
|
|
float rt_2 = sqrt(2.0);
|
|
float x = 0.5 * sqrt(2.0 + 2.0 * u * rt_2 + u_sq - v_sq) - 0.5 * sqrt(2.0 - 2.0 * u * rt_2 + u_sq - v_sq);
|
|
float y = 0.5 * sqrt(2.0 + 2.0 * v * rt_2 - u_sq + v_sq) - 0.5 * sqrt(2.0 - 2.0 * 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.0) / 480.0;
|
|
if (int(floor(gl_FragCoord[0] / 2.0) + floor(gl_FragCoord[1]) / 2.0) % 2 == 0)
|
|
{
|
|
output_color = vec4(shadowed * 1.2, 1);
|
|
}
|
|
else
|
|
{
|
|
output_color = vec4(shadowed * 0.7, 1);
|
|
}
|
|
output_color[0] = float(int(output_color[0] * 4.0)) / 4.0;
|
|
output_color[1] = float(int(output_color[1] * 4.0)) / 4.0;
|
|
output_color[2] = float(int(output_color[2] * 4.0)) / 4.0;
|
|
output_color *= 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));
|
|
}
|
|
output_color = texture(pudding_texture, uv);
|
|
}
|