/clases/fund2/ sintaxis checkpoint 0 checkpoint 1 checkpoint 2 bonus
xxxxxxxxxx
 
1
// Author: Sol Sarratea @solquemal
2
// Title: Fundamentales - Figura simple
3
4
precision mediump float;
5
uniform float u_time;
6
uniform vec2 u_resolution;
7
vec2 uv(){
8
    /* Devuelve las posiciones del canvas en rango [-1.,1.]x[-1.,1.] */
9
    vec2 pos = gl_FragCoord.xy/u_resolution; 
10
    pos.x *= u_resolution.y/u_resolution.x;
11
    pos = pos *2.-1.;
12
    return pos;
13
}
14
15
vec2 uvN(){
16
    /* Devuelve las posiciones del canvas en rango [0.,1.]x[0.,1.] */
17
    vec2 pos = gl_FragCoord.xy/u_resolution; 
18
    pos.x *= u_resolution.y/u_resolution.x;  
19
    return pos;
20
}
21
22
float sdSegment( in vec2 p, in vec2 a, in vec2 b )
23
{
24
    vec2 pa = p-a, ba = b-a;
25
    float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
26
    return length( pa - ba*h );
27
}
28
29
float verEjes(vec2 pos,float verX, float verY){
30
    float ejes; 
31
    ejes += (1.-step(0.009, distance(pos.x,0.)))*verY;
32
    ejes += (1.-step(0.009, distance(pos.y,0.)))*verX;
33
    return ejes;
34
}
35
36
float verDistAlOrigen(vec2 pos, float radio){
37
    float d = sdSegment(pos, vec2(0.), radio*vec2(-cos(u_time), -sin(u_time)));
38
    d = smoothstep(0.01,0.009,d);
39
    return d;
40
}
41
42
float verDistAlEjeY(vec2 pos, float radio){
43
    float d = sdSegment(pos, vec2(0.), radio*vec2(cos(u_time), 0.));
44
    d = smoothstep(0.01,0.009,d);
45
    return d;
46
}
47
48
float verDistAlEjeX(vec2 pos, float radio){
49
    float d = sdSegment(pos, vec2(0.), radio*vec2(0., sin(u_time)));
50
    d = smoothstep(0.01,0.009,d);
51
    return d;
52
}
53
54
float caminoCirculo(float radio){
55
    float d = smoothstep(0.02,0.,length(uv())-radio);
56
    d -=smoothstep(0.,-0.02,length(uv())-radio);
57
    return d;
58
}
59
60
void main() {
61
    vec2 pos = uv(); vec3 color; float circulo;
62
63
    float punto = smoothstep(0.5,0.49, length(pos));
64
    color += punto;
65
    gl_FragColor = vec4(color, 1.); 
66
67
}
68
69