01 Fragments and data
main: read inputs, compute, write outputs
Left: the original brightness. Right: after dimming. It runs line by line, like a C function.
OriginalDimmed
Final brightness01
01
Exercise
Drag the underlined numbers left and rightDrag numbers, or edit the code
uniform float uInput; // original brightnessuniform float uGain; // fraction keptvoid main() { float result = uInput * uGain; // = 0.48 vec3 color = vec3(result); gl_FragColor = vec4(color, 1.0);}
- read inputs
- multiply
- write output
uniformPassed in by JS, shared by every fragmentmainWhere each call starts running=Stores the right side in the left sideJS side
gl.uniform1f(uInput, 0.80)
gl.uniform1f(uGain, 0.60)A uniform is a value JS passes in; main reads inputs, computes and writes outputs, top to bottom like a C function.
Try it
- Press “Half”: what is the result?
- Drag uGain to 0 and the right side goes dark