lovr.graphics.newComputeShader

Creates a new compute Shader, used for running generic compute operations on the GPU.

shader = lovr.graphics.newComputeShader(source, options)

Arguments

NameTypeDefaultDescription
sourcestringThe code or filename of the compute shader.
optionstable{}Optional settings for the Shader.
.flagstable{}A table of key-value options passed to the Shader.

Returns

NameTypeDescription
shaderShaderThe new compute Shader.

Notes

Compute shaders are not supported on all hardware, use lovr.graphics.getFeatures to check if they're available on the current system.

The source code for a compute shader needs to implement the void compute(); GLSL function. This function doesn't return anything, but the compute shader is able to write data out to Textures or ShaderBlocks.

The GLSL version used for compute shaders is GLSL 430.

Currently, up to 32 shader flags are supported.

Example

function lovr.load()
  computer = lovr.graphics.newComputeShader([[
    layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

    void compute() {
      // compute things!?
    }
  ]])

  -- Run the shader 4 times
  local width, height, depth = 4, 1, 1

  -- Dispatch the compute operation
  lovr.graphics.compute(computer, width, height, depth)
end

See also