home/ atoms/ glsl-standard-uniforms

The Book of Shaders defines three standard uniforms: u_resolution, u_mouse, and u_time

The Book of Shaders live editor and its examples rely on a standard set of uniforms injected by the environment: u_resolution (a vec2 with canvas width and height in pixels), u_mouse (a vec2 with the current mouse position), and u_time (a float with elapsed seconds, enabling animation). These uniforms bridge the JavaScript host environment to the GLSL shader, providing the context a fragment shader needs to produce varied output. Any shader built against this convention will work in the thebookofshaders.com editor, Shadertoy (with minor renaming: iResolution, iMouse, iTime), and most livecoding shader environments. Knowing this convention is the prerequisite for writing any interactive or animated fragment shader.

Examples

Use u_time to animate: float brightness = abs(sin(u_time)); — the sine oscillates the brightness over time. Use u_mouse to make a colour respond to cursor position: vec2 mouse = u_mouse.xy/u_resolution.xy;

Assessment

Name the three standard uniforms from the Book of Shaders template, state the GLSL type of each, and explain what value each holds at runtime.

“uniform vec2 u resolution;”
corpus · the-book-of-shaders-live-glsl-editor · chunk 1