Shader:send

Updates a uniform variable in the Shader.

Shader:send(uniform, value)

Arguments

NameTypeDescription
uniformstringThe name of the uniform to update.
value*The new value of the uniform.

Returns

Nothing

Notes

The shader does not need to be active to update its uniforms.

The following type combinations are supported:

Uniform type LÖVR type
float number
int number
vec2 { x, y }
vec3 { x, y, z } or vec3
vec4 { x, y, z, w }
ivec2 { x, y }
ivec3 { x, y, z }
ivec4 { x, y, z, w }
mat2 { x, ... }
mat3 { x, ... }
mat4 { x, ... } or mat4
sampler Texture
image Texture

Uniform arrays can be wrapped in tables or passed as multiple arguments.

Textures must match the type of sampler or image they are being sent to.

The following sampler (and image) types are currently supported:

An error is thrown if the uniform does not exist or is not used in the shader. The Shader:hasUniform function can be used to check if a uniform variable exists.

Blobs can be used to pass arbitrary binary data to Shader variables.

Example

Updating a vec3 uniform:

function lovr.load()
  shader = lovr.graphics.newShader [[
    uniform vec3 offset;
    vec4 position(mat4 projection, mat4 transform, vec4 vertex) {
      vertex.xyz += offset;
      return projection * transform * vertex;
    }
  ]]

  shader:send('offset', { .3, .7, 0 })
end

See also