Sets the shader’s uniform (global) variables.
Shader programs run on the computer’s graphics processing unit (GPU). They live in part of the computer’s memory that’s completely separate from the sketch that runs them. Uniforms are global variables within a shader program. They provide a way to pass values from a sketch running on the CPU to a shader program running on the GPU.
The first parameter, uniformName
, is a string with the uniform’s name. For the shader above, uniformName
would be 'r'
.
The second parameter, data
, is the value that should be used to set the uniform. For example, calling myShader.setUniform('r', 0.5)
would set the r
uniform in the shader above to 0.5
. data should match the uniform’s type. Numbers, strings, booleans, arrays, and many types of images can all be passed to a shader with setUniform()
.
Examples
Syntax
setUniform(uniformName, data)
Parameters
name of the uniform. Must match the name used in the vertex and fragment shaders.
value to assign to the uniform. Must match the uniform’s data type.
Related References
copyToContext
Copies the shader from one drawing context to another.
inspectHooks
Logs the hooks available in this shader, and their current implementation.
modify
Returns a new shader, based on the original, but with custom snippets of shader code replacing default behaviour.
setUniform
Sets the shader’s uniform (global) variables.