Last active
November 29, 2021 14:11
-
-
Save solsarratea/4241067df034bfca1302ade87aa7270b to your computer and use it in GitHub Desktop.
LIVECODING AND CHILL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* LIVECODING AND CHILL : bu3namigue con Pablito Labarta y Sol Sarratea | |
Para aprender más sobre shaders: | |
- Book of Shaders https://thebookofshaders.com/ | |
- Curso introductorio https://curso.solquemal.com/ | |
- Shaders + Caos (curso en proceso) https://wikicaos.solquemal.com/ | |
El siguiente código corre en The Force, editor online de GLSL creado por Shawn Lawson | |
Link: https://shawnlawson.github.io/The_Force/ | |
Sol Sarratea | |
@solquemal | |
contact [a] solquemal.com | |
https://solquemal.com/ | |
*/ | |
void main () { | |
// "Por píxel: Entra posición sale color" | |
// [x,y] pos -> color = [r, g, b, a] | |
vec2 pos = uv();// pos [x, y] con rango [-1, 1]x[-1,1] | |
vec4 color; | |
// Transformaciones del espacio | |
//pos.x +=cos(time*0.1); | |
//pos.y = abs(pos.y); | |
//pos.y *=pos.x; | |
//pos.y =fract(pos.y/pos.x+time*0.1)*1.2; | |
//color.rb +=pos; | |
//color += fract(pos.x/pos.y*2.+time); | |
/* Visibilizamos el rango de las posiciones con los canales de color: | |
canal rojo: x | |
canal azul: y */ | |
//pos.x = abs(pos.x); | |
for (int i = 0; i < 64; i++) { | |
//Descomentar linea 41 y comentar linea 42 | |
//float a = PI/5.+time*0.2; //El angulo no depende de la iteracion | |
float a = PI/pow(0.99,float(i))+time*0.2; | |
//Dirección del espejo | |
vec2 dir = vec2(cos(a),sin(a)); // [1,0] | |
float dist = dot(pos,dir); | |
//Proyecto pixel caminando dirección opuesta al espejo 2 pasos | |
pos -= 2.*min(dist,0.)*dir; | |
//Rotacion | |
pos = rotate(vec2(0.),pos, PI/3.); | |
//Traslacion | |
pos.y -= 0.05; | |
//Escala | |
pos.y *= 1.0001; | |
//Agrego | |
color += smoothstep(0.01,0.0, distance(pos.y,0.))*.3; | |
color += smoothstep(0.001,0.0, distance(pos.y,.5))*.13; | |
color += smoothstep(0.01,0.0, distance(pos.y,0.25))*.13; | |
} | |
vec4 papel = texture2D(channel0, (pos/vec2(resolution.x/resolution.y,1.)+1.)*0.5); | |
/* Explicación de línea de arriba: | |
uvN = gl_FragCoord.xy/resolution => [x, y] con rango [-1, 1]x[-1,1] | |
uv = uvN *2. - 1; | |
(uv + 1)/2 = uvN | |
Acceso al código fuente de las funciones predeterminadas en The Force: | |
https://github.com/shawnlawson/The_Force/blob/gh-pages/shaders/header.frag | |
*/ | |
float sello = smoothstep(0.3,0.6,1.-length(pos)); | |
color += (papel-sello); | |
gl_FragColor = color; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kirigami Digital