This is a fragment shader written in GLSL (used in WebGL / Three.js / TouchDesigner-style pipelines).
This is the 3rd post in the GlSL learning series.
Let’s break it down simply.
const fshader = `
uniform vec3 u_color;
void main (void)
{
gl_FragColor = vec4(u_color, 1.0);
}
`
uniform vec3 u_color;This is a uniform variable.
uniform = value coming from JavaScript / TouchDesigner / host appvec3 = 3 numbers (R, G, B)u_color = the name of the variablematerial.uniforms.u_color.value = { r: 1, g: 0, b: 0 };
So you are passing a color like:
void main (void)This is the main function of the fragment shader.
So if your object has 100,000 pixels → this runs 100,000 times.
gl_FragColor = vec4(u_color, 1.0);This is the actual output color.
gl_FragColor = final pixel color (old WebGL 1 style)
vec4(...) = RGBA color
So:
vec4(u_color, 1.0)
means:
u_color (RGB)1.0 (fully opaque)It paints every pixel the exact same color.
So:
The entire object becomes a flat solid color.
No gradients, no lighting, no variation.
Think of it like:
CPU gives: “color = blue”
GPU does:
Result: solid blue shape
Because you can change color in real time without changing shader code:
Right now it's static. But you could do:
gl_FragColor = vec4(gl_FragCoord.xy / resolution.xy, 0.0, 1.0);
Now each pixel differs → gradient appears.
This shader:
u_color)