updateUniforms method
Optional helper method that updates uniforms on the shader.
It assumes a standardized set of initial uniforms:
- float
0: width - float
1: height - float
2: value - image sampler
0: image
For example, this could be defined in the fragment shader as:
uniform vec2 size; // float 0 and 1
uniform float value; // float 2
uniform sampler2D image; // image sampler 0
You can specify value to override the current animation value.
You can also pass additional uniforms via floats and images. These
will be set in the shader in the order they are passed. For example,
if you pass floats: [intensity], then the intensity value will be
assigned to float 3.
Implementation
void updateUniforms({
double? value,
List<double>? floats,
List<ui.Image>? images,
}) {
// floats:
int i = 0;
shader.setFloat(i, size.width);
shader.setFloat(++i, size.height);
shader.setFloat(++i, value ?? this.value);
floats?.forEach((o) => shader.setFloat(++i, o));
// images:
i = 0;
shader.setImageSampler(i, image);
images?.forEach((o) => shader.setImageSampler(++i, o));
}