-
Notifications
You must be signed in to change notification settings - Fork 223
API Audit: Shadertools.getUniforms() prevUniforms behavior is unclear #2138
Description
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:
luma.gl/modules/shadertools/src/lib/shader-assembly/assemble-shaders.ts
Lines 435 to 440 in f63579c
| 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:
luma.gl/modules/engine/src/shader-inputs.ts
Lines 112 to 114 in f63579c
| 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()