ShaderModule
Quick answer
ShaderModule is a plain object type in v9, not a constructible class. It bundles name, optional vs and fs fragments, uniformTypes and inject hooks, which shadertools concatenates when assembling shader sources. Pass modules to Model or Shader to reuse lighting, picking and projection code.
type ShaderModule = { name, vs?, fs?, uniformTypes?, inject? }
Key points
- Fields include name, vs, fs, uniformTypes and inject.
- Modules are assembled before createShader and never compiled directly.
- inject prepends declarations or wraps main with extra logic.
Example
const waveModule = {
name: 'wave',
fs: `
float wave(float x, float freq) {
return sin(x * freq) * 0.5 + 0.5;
}
`,
inject: {
'fs:#main-end': 'fragColor.rgb *= wave(vUV.x, 6.0);'
}
};const model = new Model(device, {
vs: vsSource,
fs: fsSource,
modules: [waveModule],
attributes: { positions: positions },
bufferLayout: [
{ name: 'positions', stepMode: 'vertex', format: 'float32x3' }
],
vertexCount: 3,
topology: 'triangle-list'
});
Notes
- Calling new ShaderModule() fails because modules are object literals.
- Two modules declaring the same uniform with different types break shader inputs.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). ShaderModule. https://www.jingweizhi.com/en/lumagl/api/shader-module.html (accessed 2026-11-03).