This is an old revision of the document!
Shaders
A memo in GLSL programming.
Coding Shaders
Normalized input Coordinates
Generally the vec2 uv
is used to describe a normalized input coordinates by dividing the coordinate by the current resolution :
Different compilers use different syntax to describe the resolution.
vec2 uv = fragCoord.xy / iResolution.xy;
Origin
The origin (0.0 ; 0.0) of this normalized vector is the bottom left.
To move the origin to the center of the screen, remove 0.5 to both components :
uv -= 0.5;
Aspect Ratio
To correct the aspect ratio on non-square displays, we multiply one component (generally x
) by the Resolution's aspect ratio.
uv.x *= iResolution.x / iResolution.y;
Circle
To draw a circle, define a center point where the circle should be drawn and use a length function to calculate the length of the coordinates to this center.
One simple way is to compare the length to a value and draw a color if it's less and another if it's more :
float d = length(uv); float c = d; if (d < .3) c = 0.0 ; else c = 1.0; // Output to screen fragColor = vec4(vec3(c),1.0);
ISF
ISF stands for Interactive Shader Format and is a file format used to describe GLSL shaders for real-time image filtering and generation.
Ressources
Online Editors
Tools
* Graph Toy : Display math functions
* Color Palettes : Interactive Color Palettes
* Desmos : Great math tools