Part 0 - Hello, GPU
In ShaderToy, we write code for Fragment Shaders
.
A fragment shader is a small program that gets runs once per pixel to decide that pixel’s color — massively in parallel on the GPU.
For each pixel, the GPU asks the shader:
what color should I be?
The shader answers using math.
In ShaderToy the main function is called
mainImage
, and it receives an inputfragCoord
to indicate what current pixel coordinate in screen pixels (x,y) it’s going to color.The color should be written (assigned) to the
fragColor
variable.
Our first shader
- Click New at the top-right corner.
- Update the code to the following:
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
fragColor = vec4(1.0, 0.0, 0.0, 1.0); // solid red
}
To see your changes, press the little arrow in the lower-left corner, or press Alt+Enter
.
It should now look like this:
Very red, but not very exciting yet. Let’s keep going…