2.5 KiB
ShaderLayout
The luma.gl v9 API is currently in public review.
Shader code contains declarations of attributes, uniform blocks, samplers etc in the GLSL or WGSL code, that collectively define the layout of data that needs to be bound before the shader can execute on the GPU.
Since the actual binding of data is performed on the CPU, a certain amount of metadata is needed in JavaScript to describe the layout of any specific shaders.
luma.gl defines the ShaderLayout type to collect a description of a (pair of) shaders. A ShaderLayout
is required when creating a RenderPipeline or ComputePipeline.
Note: ShaderLayouts can be created manually (by reading the shader code),
or be automatically generated by parsing shader source code or using e.g. the WebGL program introspection APIs.
type ShaderLayout = {
attributes: [
instancePositions: {location: 0, format: 'float32x2', stepMode: 'instance'},
instanceVelocities: {location: 1, format: 'float32x2', stepMode: 'instance'},
vertexPositions: {location: 2, format: 'float32x2', stepMode: 'vertex'}
],
bindings: {[bindingName: string]: BindingLayout};
projectionUniforms: {location: 0, type: 'uniforms'},
textureSampler: {location: 1, type: 'sampler'},
texture: {location: 2, type: 'texture'}
}
}
type AttributeLayout =
{name: , location: number, format: VertexFormat, stepMode: 'vertex' | 'instance'}
type BindingLayout =
{type: 'uniform', location: number} |
{type: 'sampler', location: number} |
{type: 'texture', location: number}
Usage
const shaderLayout: ShaderLayout = {
attributes:
'instancePositions': {location: 0, format: 'float32x2', stepMode: 'instance'},
'instanceVelocities': {location: 1, format: 'float32x2', stepMode: 'instance'},
'vertexPositions': {location: 2, format: 'float32x2', stepMode: 'vertex'}
},
bindings: {
'uniforms': {location: 0, type: 'uniforms'},
'sampler': {location: 1, type: 'sampler'},
'texture': {location: 2, type: 'texture'}
}
}
Fields
attributes
attributes:
instancePositions: {location: 0, format: 'float32x2', stepMode: 'instance'},
instanceVelocities: {location: 1, format: 'float32x2', stepMode: 'instance'},
vertexPositions: {location: 2, format: 'float32x2', stepMode: 'vertex'}
}
bindings
bindings?: {
projectionUniforms: {location: 0, type: 'uniforms'},
textureSampler: {location: 1, type: 'sampler'},
texture: {location: 2, type: 'texture'}
}