The Book of Shaders
primitives (called uniform)
uniform types
- float
- vec2
- vec3
- vec4
- mat2
- mat3
- mat4
- sampler2D
- samplerCube.
accelerated (GPU powered) functions
sin(), cos(), tan(), asin(), acos(), atan(), pow(), exp(), log(), sqrt(), abs(), sign(), floor(), ceil(), fract(), mod(), min(), max() and clamp().
special glsl functions
step() // 0 if less than 0.5, else 1
smoothstep() // like step, but smooth over x
#ifdef GL_ES
precision mediump float;
#endif
uniform float u_time;
uniform vec2 u_mouse;
uniform vec2 u_resolution;
void main() {
// slow
//gl_FragColor = vec4(abs(sin(u_time / 20.)),0.0,0.0,1.0);
// fast
//gl_FragColor = vec4(abs(sin(u_time * 72.784)),0.0,0.0,1.0);
//interesting
gl_FragColor = vec4(abs(sin(u_time * 0.1784)), clamp(u_mouse.y / u_resolution.y, 0., 1.),abs(sin(u_time * 0.3784 + 0.9)),1.0);
}
Fragment shader
two globals variables in fragment shaders (.frag)
- one input ONLY
- gl_FragCoord
- one output ONLY
- gl_FragColor