Graphics / Reference / A solid-colour fragment shader
A solid-colour fragment shader
A fragment shader computes output values for generated fragments. The basic shader used here reads one uniform RGB colour and writes that same colour with alpha 1 to every processed fragment.
The solid-colour fragment shader is:
#version 330 core out vec4 FragColor; uniform vec3 uColor; void main() { FragColor = vec4(uColor,1.0); }
uColor is a three-component uniform containing red, green and blue values. Because it is uniform, every fragment processed by this shader during a draw receives the same RGB input unless the application changes uColor between draw calls.
FragColor is the shader's four-component output. vec4(uColor,1.0) copies the uniform RGB components and sets the alpha component to 1.0. This is the fragment shader's candidate output; later per-fragment tests or framebuffer operations can still determine whether and how that result contributes to the stored framebuffer image.
In the example rendering, the triangle draw sets uColor = (0.8,0.2,0.2), while the line draw changes uColor to approximately (0.95,0.9,0.2). The associated framebuffer figure shows the resulting red triangle and yellow diagonal line for the example's rendering state.
Builds on
Read
- Read the chapter: A solid-colour fragment shader