OpenGL Shading Language - Water Mites Beta





#define PERIOD 2.
#define REPETITIONS 2

uniform float time;
uniform vec2 resolution;
uniform vec2 mouse;
uniform vec3 spectrum;

const float PI = 3.1415926535;


float box(in vec2 _st, in vec2 _size){
    _size = vec2(0.5) - _size*0.5;
    vec2 uv = smoothstep(_size,
                        _size+vec2(0.001),
                        _st);
    uv *= smoothstep(_size,
                    _size+vec2(0.001),
                    vec2(1.0)-_st);
    return uv.x*uv.y;
}

float cross(in vec2 _st, float _size){
    return  box(_st, vec2(_size,_size/4.)) +
            box(_st, vec2(_size/4.,_size));
}

vec3 shadeBlob(vec2 p, float index, float value, float scale)
{
    float screenRatio = resolution.x / resolution.y;
    vec2 pc = vec2(0.1 + (screenRatio - 0.2) * value, index);
 
    float d = length(pc - p) / 0.015*scale/0.3;
 
    return vec3(3. * vec3(0.2, 0.5, 0.7) / (max(d * d, 1.)));
}

float step_interp(float x) {
    return step(0.5, x);
}

float linear_interp(float x) {
    float c = clamp(x, 0., 1.);
 
    return c;
}

float cosine_interp(float x) {
    float c = clamp(x, 0., 1.);
 
    return 0.5 * (1. - cos(PI * c));
}

float smoothstep_interp(float x) {
//    return smoothstep(0., 1., x);

    float c = clamp(x, 0., 1.);
 
    return c * c * (3. - 2. * c);
}

float quintic_interp(float x) {
    float c = clamp(x, 0., 1.);
 
    return c * c * c * ((6. * c - 15.) * c + 10.);
}

void main(void)
{
    vec2 p = gl_FragCoord.xy / resolution.yy;
    vec2 q = gl_FragCoord.xy / resolution.yy;
 
    vec3 spec = .1+spectrum;
 
    vec2 translate = vec2(cos(time),sin(time));
    vec2 translate2 = vec2(sin(time),cos(time));
    p += translate*0.35*sin(time);
    q += translate2*1.35*sin(time);
 
    float t = abs(2. * fract(time / PERIOD) - 1.);
 
 
    vec3 col = vec3(0.0 + 0.000 * mod(floor(p.x * 10.0) + floor(p.y * 10.0), 2.0));
    vec3 col2 = vec3(0.0 + 0.000 * mod(floor(q.y * 5.0) + floor(q.x * 5.0), 2.0));
 
 
    col += shadeBlob(p, 0.1, smoothstep_interp(t)*spec.x+0.5, spec.x/0.1);
    col2 += shadeBlob(q, 0.3+spec.z, linear_interp(t)*spec.y+0.5, spec.z);
    col += shadeBlob(p, 0.5+spec.x, cosine_interp(t)*spec.z+0.7, spec.z/0.3);
    col2 += shadeBlob(q, 0.7, smoothstep_interp(t)*spec.z+0.1, spec.x/0.6);
    col += shadeBlob(p, 0.9-spec.y, quintic_interp(t)*spec.z+0.3, spec.z/0.9);

 
    col = pow(col, vec3(0.45));
    col2 = pow(col2, vec3(0.45));
 
    gl_FragColor = vec4(col+col2, 1.0);
}

Categories: , , Share

Leave a Reply

Update cookies preferences