137 lines
3.6 KiB
GLSL
137 lines
3.6 KiB
GLSL
/*@~@~@ |C|A|K|E|F|O|O|T| <presented by> 💫dank.game💫
|
|
|~)~)~)
|
|
|\~*~*| Licensed under the zlib and CC-BY licenses. Source is available at
|
|
|\\~*~|
|
|
,~|#\\~*|~, <https://open.shampoo.ooo/shampoo/cakefoot>
|
|
: \\@\\~| :
|
|
: \\#\\| : Created with open SPACE🪐BOX engine for cross-platform, PC, web and mobile games
|
|
: \\@\' :
|
|
: \\/ : <https://open.shampoo.ooo/shampoo/spacebox>
|
|
`~ ~ ~`~ ~'
|
|
|
|
The contents of this file must be appended to a file which forward declares a bg function and defines a main function.
|
|
See shaders/shader.frag.
|
|
|
|
This is a modification of "EarthBound Coffee Break" by @MakiXx on ShaderToy:
|
|
|
|
https://www.shadertoy.com/view/WlScWh
|
|
|
|
*/
|
|
|
|
/*!
|
|
* https://gist.github.com/patriciogonzalezvivo/670c22f3966e662d2f83
|
|
*/
|
|
float random(float n) { return fract(sin(n) * 43758.5453123); }
|
|
|
|
/*!
|
|
* https://gist.github.com/patriciogonzalezvivo/670c22f3966e662d2f83
|
|
*/
|
|
float noise(float p)
|
|
{
|
|
float fl = floor(p);
|
|
float fc = fract(p);
|
|
return mix(random(fl), random(fl + 1.0), fc);
|
|
}
|
|
|
|
float random2d(in vec2 st) {
|
|
// return fract(sin(dot(st.xy, vec2(12.9898,78.233))) * 43758.5453123);
|
|
return fract(sin(dot(st.xy, vec2(-0.5, 2.0))));
|
|
}
|
|
|
|
float noise2d(in vec2 st) {
|
|
vec2 i = floor(st);
|
|
vec2 f = fract(st);
|
|
|
|
// Four corners in 2D of a tile
|
|
float a = random2d(i);
|
|
float b = random2d(i + vec2(1.0, 0.0));
|
|
float c = random2d(i + vec2(0.0, 1.0));
|
|
float d = random2d(i + vec2(1.0, 1.0));
|
|
// float _d = dot(i.x, i.y);
|
|
// float a = _d;
|
|
// float b = _d + 1.0;
|
|
// float c = _d + 1.0;
|
|
// float d = _d + 2.0;
|
|
|
|
// Smooth Interpolation
|
|
|
|
// Cubic Hermine Curve. Same as SmoothStep()
|
|
vec2 u = f*f*(3.0-2.0*f);
|
|
// vec2 u = smoothstep(0.,1.,f);
|
|
|
|
// Mix 4 corners percentages
|
|
return mix(a, b, u.x) +
|
|
(c - a)* u.y * (1.0 - u.x) +
|
|
(d - b) * u.x * u.y;
|
|
}
|
|
|
|
/*!
|
|
* Modified from the original, which is Copyright (c) 2020 Maki. All rights reserved.
|
|
* https://www.shadertoy.com/view/WlScWh
|
|
*/
|
|
vec2 wobbly(vec2 uv, float speed, float repetition, float amount, float offset)
|
|
{
|
|
return vec2(
|
|
uv.x,
|
|
uv.y + sin(uv.y * repetition + (time+offset) * speed) / amount
|
|
);
|
|
}
|
|
|
|
/*!
|
|
* Modified from the original, which is Copyright (c) 2020 Maki. All rights reserved.
|
|
* https://www.shadertoy.com/view/WlScWh
|
|
*/
|
|
float bubbles(vec2 uv, float offset, float direction)
|
|
{
|
|
uv *= bg_control_2;
|
|
uv = wobbly(uv, 0.8, bg_control_1 * bg_control_2, 0.2 * bg_control_2, offset);
|
|
uv.x -= time * 0.3 * direction;
|
|
uv.y -= time * 0.8;
|
|
|
|
vec2 F = vec2(noise2d(uv) * bg_control_4, 0.0);
|
|
|
|
float edge = 0.33;
|
|
|
|
float final = 1.0 - step(edge, F.x);
|
|
|
|
float size = bg_control_3;
|
|
final -= 1.0 - step(edge - size, F.x);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
size += 0.03;
|
|
final += 1.0 - step(edge - size, F.x);
|
|
|
|
size += bg_control_3;
|
|
final -= 1.0 - step(edge - size, F.x);
|
|
}
|
|
|
|
return final;
|
|
}
|
|
|
|
#define colorBg vec4(0.1, 0.1, 0.1, 1.0)
|
|
|
|
/*!
|
|
* Modified from the original, which is Copyright (c) 2020 Maki. All rights reserved.
|
|
* https://www.shadertoy.com/view/WlScWh
|
|
*/
|
|
vec4 bg()
|
|
{
|
|
vec2 uv = gl_FragCoord.xy / resolution;
|
|
|
|
float blueBubbles = bubbles(uv, 11512.11, 1.0);
|
|
float blueCombined = clamp(blueBubbles, 0.0, 1.0);
|
|
|
|
float greenBubbles = bubbles(uv, 82351.93, -1.0);
|
|
float greenCombined = clamp(greenBubbles, 0.0, 1.0);
|
|
|
|
return mix(
|
|
mix(
|
|
colorBg, // a
|
|
bg_color_1, // b
|
|
blueCombined // alpha
|
|
), // a
|
|
bg_color_2, // b
|
|
greenCombined // alpha
|
|
);
|
|
}
|