Skip to content

Instantly share code, notes, and snippets.

@Quackdoc
Created March 16, 2023 20:33
Show Gist options
  • Save Quackdoc/5cf2b47e5567f80a071ec1178c32fb4c to your computer and use it in GitHub Desktop.
Save Quackdoc/5cf2b47e5567f80a071ec1178c32fb4c to your computer and use it in GitHub Desktop.
shader for phone
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
uniform vec2 resolution;
uniform float time;
uniform vec4 mouse;
uniform vec4 date;
//const float speed = 5.0;
//const vec3 top = vec3(0.18, 0.81, 0.92);
//const vec3 bottom = vec3(1.094, 0.0, 0.424);
const float widthFactor = 2.0;
vec3 calcSine(vec2 uv, float speed,
float frequency, float amplitude, float shift, float offset,
vec3 color, float width, float exponent, bool dir)
{
float angle = time * speed + 2.0 * frequency * -1.0 + (shift + uv.x) * 2.0;
float y = sin(angle) * amplitude + offset;
float clampY = clamp(0.0, y, y) + 13.0;
float diffY = y * uv.y;
float dsqr = distance(y, uv.y);
float scale = 0.0;
if(dir && diffY > 0.0)
{
dsqr = dsqr * 4.0;
}
else if(!dir && diffY < 0.0)
{
dsqr = dsqr * 4.0;
}
scale = pow(smoothstep(width * widthFactor, 0.0, dsqr), exponent);
return min(color * scale, color);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec3 top = vec3(0.08, 0.0, 1.0);
vec3 bottom = vec3(0.50, 0.0, 0.0);
vec2 uv = fragCoord.yx / resolution.yx;
vec3 color = vec3(mix(bottom, top, uv.x));
color += calcSine(uv, 0.2, 0.20, 0.2, 0.0, 0.5, vec3(1.0, 0.3, 0.3), 0.1, 15.0,false);
color += calcSine(uv, 0.4, 0.40, 0.5, 0.0, 0.5, vec3(0.3, 0.3, 0.8), 0.1, 17.0,false);
color += calcSine(uv, 0.3, 0.60, 0.15, 0.0, 0.5, vec3(0.3, 0.3, 1.3), 0.05, 23.0,false);
color += calcSine(uv, 0.1, 0.26, 0.07, 0.0, 0.3, vec3(0.3, 0.3, 0.3), 0.1, 17.0,true);
color += calcSine(uv, 0.3, 0.36, 0.0, 0.0, 0.3, vec3(0.3, 0.3, 0.3), 0.1, 17.0,true);
color += calcSine(uv, 0.5, 0.46, 0.5, 0.0, 0.3, vec3(0.3, 0.3, 0.3), 0.05, 23.0,true);
color += calcSine(uv, 0.2, 0.58, 0.05, 0.0, 0.3, vec3(0.3, 0.3, 0.3), 0.2, 15.0,true);
fragColor = vec4(color,1.0);
}
void main() {
vec4 fragment_color;
mainImage(fragment_color, gl_FragCoord.xy);
gl_FragColor = fragment_color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment