/rumbo/koch/ init checkpoint 0 checkpoint 1 checkpoint 2
xxxxxxxxxx
1
// Author: Sol Sarratea @solquemal
2
// Title: Curva de Koch - 0
3
// Repaso sobre clase anterior
4
5
#ifdef GL_ES
6
  precision mediump float;
7
#endif
8
9
uniform float u_time;
10
uniform vec2  u_resolution;
11
#define PI 3.1415926538
12
13
vec2 uv(){
14
   /* Devuelve las posiciones del canvas en rango [-1.,1.]x[-1.,1.] */
15
   vec2 pos = gl_FragCoord.xy/u_resolution; 
16
   pos = pos *2.-1.;
17
   return pos;
18
}
19
20
float sdBox( in vec2 p, in vec2 b ){
21
    vec2 d = abs(p)-b;
22
    return length(max(d,0.0)) + min(max(d.x,d.y),0.0);
23
}
24
25
vec2 rotate(vec2 pos,float a){
26
    return pos * mat2(cos(a),sin(a),-sin(a),cos(a));
27
}
28
29
30
void main () {
31
    vec2 pos = uv(); vec3 color;
32
33
    /////////////////////////////////////
34
    //Aplicamos transformaciones lineales
35
36
    pos.x = abs(pos.x);
37
    pos -= vec2(0.5,0.);
38
    pos *= 1.008;
39
40
    
41
    color.r = (1.-step(0.009,distance(pos.x,0.)))
42
        *float(pos.y > 0. && pos.y<0.53);
43
    color.b = (1.-step(0.009,distance(pos.y,0.)))
44
        *float(pos.x > 0. && pos.x<0.53);
45
    
46
    float box =  smoothstep(.0,.01,sdBox(pos, vec2(.3)));
47
    
48
    color += box;
49
    
50
    gl_FragColor = vec4(color,1.);
51
}
52
53
54