Shaders for Games (GLSL) Lesson 9 of 20
Following the mouse
u_mouse turns a shader into something you can touch — an input that follows the pointer.
Two things feed a shader from the outside: time and the mouse. You have used u_time to make things move on their own. u_mouse is the other input — the pointer’s position over the canvas, in pixels. Divide it by u_resolution and you get a 0-to-1 point, exactly like st. That one uniform is all it takes to make a shader interactive.
Move your pointer over the preview below and the glow follows it. That is the whole idea: feed u_mouse into a position, a color, an angle — anything — and the shader responds to the person using it. Spotlights, ripples, brush cursors and hover highlights all start here.
Tip Because it responds to YOUR pointer in the moment, there is nothing fixed to grade here — this one is yours to play with. Try feeding u_mouse into the color instead of a position, or make the circle you drew earlier chase the cursor.
Quick check
What does u_mouse give a shader?