Computation
The Computation class is a high-level class in the luma.gl API. It brings together all GPU functionality needed to run GPU compute shaders, in a single, easy-to-use interface.
Computation manages the following responsibilities:
- bindings these can reference textures and uniform buffers
- shader module injection
- debugging - Detailed debug logging of draw calls
The Computation class integrates with
- The
@luma.gl/shadertoolsshader module system: seeShader Assembly.
Usage
import {Computation} from `@luma.gl/engine`;
One of the simplest way to provide attribute data is by using a Geometry object.
Create model object by passing shaders, uniforms, geometry and render it by passing updated uniforms.
import {Computation} from `@luma.gl/engine`;
// construct the model.
const model = new Computation(device, {
source: COMPUTE_SHADER,
bindings: {
uSampler: texture
},
})
Provide attribute data using Buffer
When using Buffer objects, data remains on GPU and same Buffer object can be shared between multiple models.
// construct the model.
const model = new Computation(device, {
source: COMPUTE_SHADER,
attributes: {
attributeName1: bufferObject,
attributeName2: device.createBuffer(new Float32Array(...))
},
uniforms: {uSampler: texture},
})
On each frame, call the model.draw() function after updating any uniforms (typically matrices).
model.setUniforms({
uPMatrix: currentProjectionMatrix,
uMVMatrix: current ComputationViewMatrix
});
model.draw();
Debug shader source (even when shader successful)
// construct the model.
const model = new Computation(device, {
source: COMPUTE_SHADER,
debugShaders: 'always'
});