Bird

GIF

550 views
A bird made with code.
Uploaded on Tue Jul 17 2018

Raw gif (gif) - Video (mp4) - Video (ogv) - Preview (png)
language: shader_webgl2

#version 300 es
precision highp float;

#define PI 3.14159265359
#define PI2 6.28318530718

in vec2 UV;
uniform float time;
out vec4 out_color;
uniform float ratio;

vec4 bird(vec2 p, float t, float div){
	vec4 col = vec4(1.0);
    
	
	float f = 1.0;
    
    p.y += 0.5 * pow(abs(p.x), 1.2) * cos(-abs(p.x) * 3.0 + t * PI2);
    p.y *= 1.0 + 4.5 * abs(p.x);
    
    if(p.y < 0.1){    
        if(p.y > 0.05){
            
            f *= 1.0 - 3.0 * abs(p.x);
            f *= 80.0;
            f = clamp(f, 0.0, 1.0);
            
            f *= abs(p.y - 0.1)/0.01 * div;
            f *= abs(p.y - 0.05)/0.03 * div;
            
    		col.rgb = f * vec3(0.0) + (1.0 - f) * col.rgb;
    		col.a = f;
        } else {
        	col.a = 0.0;
        }
    } else {
    	col.a = 0.0;
    }
    
    col.a = clamp(col.a, 0.0, 1.0);
    
    return col;
}


void main(void){
	float x = UV.x * ratio - 0.5;
	float y = UV.y - 0.5;
	vec2 p = vec2(x, y);
	
	vec4 col = vec4(1.0);
	
    float front_bird_offset = 0.03 * cos(time * PI2 + 1.6);
    
    col.rg *= 0.7;
    col.r *= 1.0 - 1.5 * p.y;
    
    col.rgb += vec3(1.0, 0.3, 0.5) * clamp(1.0 - 100.0 * pow(length(p), 3.0), 0.0, 1.0);
    
    p.y += front_bird_offset;
    vec4 birdimg = bird(p, time, 1.0);
    p.y -= front_bird_offset;
    
    col = birdimg * birdimg.a + (1.0 - birdimg.a) * col;
    
    y += 0.1;
    p *= 2.0;
    p = 4.0 * (mod(p, vec2(0.2, 0.14)) - 0.1);
    
    birdimg = bird(p, time + x + cos(y * 1.0), 0.6);
    p.y += 0.3;
    p.x += 0.1 * cos(p.y * 2.0);
    birdimg += bird(p, time + x + cos(y * 1.0), 0.6);
    
    birdimg.a *= 1.0 - 4.0 * y - 4.0 * abs(x);
    birdimg.a = clamp(birdimg.a, 0.0, 1.0);
    
    col = birdimg * birdimg.a + (1.0 - birdimg.a) * col;
    
    col.a = 1.0;
    
    out_color = col;
}


Please sign in to comment