Background
The ShaderUniforms.getUniforms() function has a parameter, prevUniforms which is seemingly used differently depending on the context. Either it is passed the populated uniforms obtained from dependent modules (dependent mode), or it is passed the currently set uniforms (cached mode).
Dependent mode
In assembleGetUniforms, getUniforms is invoked on modules in dependency order, passing the already obtained uniforms to prevUniforms:
|
for (const module of modules) { |
|
// `modules` is already sorted by dependency level. This guarantees that |
|
// modules have access to the uniforms that are generated by their dependencies. |
|
const moduleUniforms = module.getUniforms?.(opts, uniforms); |
|
Object.assign(uniforms, moduleUniforms); |
|
} |
Cached mode
In ShaderInputs, getUniforms is invoked only on the modules present in the setProps call, without computing dependencies, and here prevUniforms contains just the value of the currently set uniforms for the module in question:
|
const oldUniforms = this.moduleUniforms[moduleName]; |
|
const oldBindings = this.moduleBindings[moduleName]; |
|
let uniformsAndBindings = module.getUniforms?.(moduleProps, this.moduleUniforms[moduleName]); |
Expected behavior
The behavior should be consistent and better documented.
@ibgreen could you confirm what your intent here was with the API? The Dependent mode seems like the more logical design, as it would easily allow modules to obtain uniforms from their dependencies (as for example we could do here: https://github.com/visgl/deck.gl/blob/5ce18d5c04ec015b3fc558402cbd3e6287196c9c/modules/extensions/src/terrain/shader-module.ts#L118)
To obtain the currently set values, we already have ShaderInputs.getUniformValues()
Background
The
ShaderUniforms.getUniforms()function has a parameter,prevUniformswhich is seemingly used differently depending on the context. Either it is passed the populated uniforms obtained from dependent modules (dependent mode), or it is passed the currently set uniforms (cached mode).Dependent mode
In
assembleGetUniforms,getUniformsis invoked on modules in dependency order, passing the already obtained uniforms toprevUniforms:luma.gl/modules/shadertools/src/lib/shader-assembly/assemble-shaders.ts
Lines 435 to 440 in f63579c
Cached mode
In
ShaderInputs,getUniformsis invoked only on the modules present in thesetPropscall, without computing dependencies, and hereprevUniformscontains just the value of the currently set uniforms for the module in question:luma.gl/modules/engine/src/shader-inputs.ts
Lines 112 to 114 in f63579c
Expected behavior
The behavior should be consistent and better documented.
@ibgreen could you confirm what your intent here was with the API? The Dependent mode seems like the more logical design, as it would easily allow modules to obtain uniforms from their dependencies (as for example we could do here: https://github.com/visgl/deck.gl/blob/5ce18d5c04ec015b3fc558402cbd3e6287196c9c/modules/extensions/src/terrain/shader-module.ts#L118)
To obtain the currently set values, we already have
ShaderInputs.getUniformValues()