-
Začínáme
void mainImage(out vec4 fragColor, in vec2 fragCoord){
fragColor = vec4(1.0,1.0,0.0,1.0); //za dvema lomitky je komentar, tady se nastavuje zluta barva pixelu
}
-
Obarvení podle pozice
void mainImage( out vec4 fragColor, in vec2 fragCoord){
fragColor= vec4(1.0,1.0,0.0,1.0);
float fx = fragCoord.x; //souradnice x fragmentu
float fy = fragCoord.y; //souradnice y fragmentu
if (fy < 100.0)
fragColor= vec4(0.0,0.0,0.0,1.0);
}
-
Odstín podle pozice
void mainImage( out vec4 fragColor, in vec2 fragCoord){
vec2 texc = fragCoord.xy / iResolution.xy;
fragColor = vec4(texc.x,texc.y,0.0,1.0);
}
-
Barva z textury, nutno nastavit iChannel0
void mainImage( out vec4 fragColor, in vec2 fragCoord){
vec2 texc = fragCoord.xy / iResolution.xy;
vec3 color = texture(iChannel0,texc).rgb; //barva z textury
fragColor = vec4(color,1.0); //barva pixelu RGBA
}
-
Kruh
void mainImage( out vec4 fragColor, in vec2 fragCoord){
vec2 texc = fragCoord.xy / iResolution.xy;
vec3 color = texture(iChannel0, texc).rgb;
fragColor = vec4(color,1.0);
vec2 f = fragCoord.xy; //souradnice xy pixelu
vec2 s = vec2(300.0,150); //souradnice xy stredu
float r = 50.0; //polomer
if (length(f-s) < r)
fragColor = vec4(1.0,1.0,0.0,1.0);
}
-
Kruh na pozici myši
void mainImage( out vec4 fragColor, in vec2 fragCoord){
vec2 texc = fragCoord.xy / iResolution.xy;
vec3 color = texture(iChannel0, texc).rgb;
fragColor = vec4(color,1.0);
vec2 f = fragCoord.xy; //souradnice xy pixelu
vec2 s = iMouse.xy; //souradnice xy stredu podle mysi
float r = 50.0; //polomer
if (length(f - s) < r)
fragColor= vec4(1.0,1.0,0.0,1.0);
}
-
Čtverec
void mainImage(out vec4 fragColor, in vec2 fragCoord){
vec2 texc = fragCoord.xy / iResolution.xy;
vec3 color = texture(iChannel0, texc).rgb;
fragColor = vec4(color,1.0);
vec2 f = fragCoord.xy; //souradnice xy pixelu
vec2 s = iMouse.xy; //souradnice xy stredu podle mysi
float r = 50.0; //polomer
if (max(abs(f.x-s.x),abs(f.y-s.y)) < r)
fragColor= vec4(1.0,1.0,0.0,1.0);
}
-
Pohyb obrazu na pozadí
void mainImage(out vec4 fragColor, in vec2 fragCoord){
vec2 texc = fragCoord.xy / iResolution.xy;
texc.x = texc.x + 0.1*iTime; //prepocet souradnice x
vec3 color = texture(iChannel0, texc).rgb;
fragColor = vec4(color,1.0);
vec2 f = fragCoord.xy; //souradnice xy pixelu
vec2 s = iMouse.xy; //souradnice xy stredu podle mysi
float r = 50.0; //polomer
if (length(f-s) < r)
fragColor = vec4(1.0,1.0,0.0,1.0);
}
-
Zašumění obrazu, nutno nastavit šumovou texturu na iChannel1
void mainImage(out vec4 fragColor, in vec2 fragCoord){
vec2 texc = fragCoord.xy / iResolution.xy;
texc = texc + 0.03*texture(iChannel1,texc + 0.1*iTime).xy;
//prepocet souradnice na zaklade sumove textury, polohy a casu
vec3 color = texture(iChannel0, texc).rgb;
fragColor = vec4(color,1.0);
vec2 f = fragCoord.xy; //souradnice xy pixelu
vec2 s = iMouse.xy; //souradnice xy stredu podle mysi
float r = 50.0; //polomer
if (length(f-s) < r)
fragColor = vec4(1.0,1.0,0.0,1.0);
}
-
Kombinace efektů
void mainImage(out vec4 fragColor, in vec2 fragCoord){
vec2 texc = fragCoord.xy / iResolution.xy;
vec2 texc2 = texc + 0.03*texture(iChannel1,texc + 0.1*iTime).xy;
vec3 color = texture(iChannel0, texc2).rgb;
fragColor = vec4(color,1.0);
vec2 f = fragCoord.xy; //souradnice xy pixelu
vec2 s = iMouse.xy; //souradnice xy stredu podle mysi
float r = iResolution.x / 5.0; //polomer kruhu
if (abs(length(f-s) - r) < 2.0)
fragColor = vec4(0.0,0.0,0.0,1.0); //hranice kruznice
if (length(f-s) < r) //vypln kruhu
fragColor = vec4(texture(iChannel0, texc).rgb,1.0);
}
-
Efekt zakřiveni lupy
void mainImage(out vec4 fragColor, in vec2 fragCoord){
vec2 texc = fragCoord.xy / iResolution.xy;
vec2 texc2 = texc + 0.03*texture(iChannel1,texc + 0.1*iTime).xy;
vec3 color = texture(iChannel0, texc2).rgb;
fragColor = vec4(color,1.0);
vec2 f = fragCoord.xy; //souradnice xy pixelu
vec2 s = iMouse.xy; //souradnice xy stredu podle mysi
float r = iResolution.x / 5.0; //polomer kruhu
float l = length(f - s); //vzdalenost od stredu
if (abs(l-r) < 2.0)
fragColor = vec4(.0,.0,.0,1.0); //hranice kruznice
if (l < r){ //vypln kruhu
vec2 d = (f - s) * pow(l/r,1.5) * r/l; //efekt zakriveni cocky
vec2 a = (s+d/3.0) / iResolution.xy; //zvetseni
fragColor = vec4(texture(iChannel0, a).rgb,1.0);
}
}