Plus d'information sur la carte de réference rapide WebGL
La variable gl_FragColor (sortie par défaut)
Se nomme fragColor en ShaderToy
void main()
{
// définir la couleur sous la forme RGBA (0.0 - 1.0)
fragColor = vec4(0.0,0.5,0.5,1.0);
}
ShaderToy contient des variables uniform
uniform vec3 iResolution; // viewport resolution (in pixels)
uniform vec4 iMouse; // mouse pixel coords. xy: current, zw: click
uniform float iTime; // shader playback time (in seconds)
Une entrée par défaut
vec2 fragCoord; // les coordonnées en nb de pixels depuis l'origine (special ShaderToy)
vec4 gl_FragCoord; // les coordonnées en nb de pixels depuis l'origine (en GLSL classique)
void main()
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord/iResolution.xy;
fragColor = vec4(uv,0.0,1.0);
}
Rajouter le temps
void main()
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord/iResolution.xy;
vec3 col = 0.5 + 0.5*cos(iTime+uv.xyx+vec3(0,2,4));
// Output to screen
fragColor = vec4(col,1.0);
}
Afficher des lignes horizontales
void main()
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord/iResolution.xy;
vec3 col = vec3(sign(cos(uv.y*80.0)));
// Output to screen
fragColor = vec4(col,1.0);
}
La fonction step : Noir ou blanc
void main()
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord/iResolution.xy;
vec3 col = vec3(step(0.2,uv.x));
// Output to screen
fragColor = vec4(col,1.0);
}
La fonction step
void main()
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord/iResolution.xy;
vec3 col = vec3(step(0.7,uv.x));
// Output to screen
fragColor = vec4(col,1.0);
}
La fonction smoothstep
void main()
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord/iResolution.xy;
vec3 col = vec3(smoothstep(0.2,0.6,uv.x));
// Output to screen
fragColor = vec4(col,1.0);
}
Un rectangle en une position donnée
void main()
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord/iResolution.xy;
vec2 size = vec2(0.4,0.15);
vec2 center = vec2(0.4,0.6);
uv = uv -center;
vec2 box = step(-size*0.5,uv);
box *= step(-size*0.5,-uv);
vec3 col = vec3(0.4,0.4,box.x*box.y*0.8);
// Output to screen
fragColor = vec4(col,1.0);
}
Pour mieux visualiser
void main()
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord/iResolution.xy;
vec2 size = vec2(0.4,0.15);
vec2 center = vec2(0.4,0.6);
uv = uv -center;
vec2 box = step(-size*0.5,uv);
box *= step(-size*0.5,-uv);
vec3 col = vec3(box.x,box.y,0.0);
// Output to screen
fragColor = vec4(col,1.0);
}