-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API Audit: Shadertools.getUniforms() prevUniforms behavior is unclear #2138
Comments
Totally agree that this API must be firmed up and documented.
|
Do we have any examples where the
Seems to be intended in the past: #379
There are a couple other examples, however I agree it isn't widespread, and pulling in the dependent module explictly doesn't seem bad to me and gives the flexibility to pass different values in the props. I do wonder if it would be best to remove the |
Without checking. I would have thought that they are always used by the global As for using them as inputs to recalculate new uniforms from partial props, I think this was done in the post process effects, one of lighting parameter modules most likely. |
Side track: Exploring symmetry with the actual shader code... For shader code I have been going in the direction of exposing any module values via APIs instead of having dependent modules "rake" into the modules internal uniforms, which by definition are internal (the entire purpose of getUniforms is to map long-lived stable public props to internal uniforms that can change freely as the module's implementation is refactored). So in this case we would have perhaps Then a question is whether having a symmetric API also on the JS side makes sense, or if in JS it is OK to access the uniforms. |
Having just ported the shadow module which requires 3 uniforms from I don't find the pattern of invoking |
OK... this means that the shader module "props abstraction" is only partial. It may protect simpler apps from uniform changes, but will still require any dependent modules (possibly defined in applications) to be modified when shader module uniforms change. It also seems a little messy to have to pass around all the props for multiple modules so that one module can call getUniforms on other modules. An alternative that the module provides an API for JS, similar to an API for shaders, but that is a little more involved.
Should we recommend using the global function like |
Note: The above are just considerations, I am fine with the direction you are proposing. |
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 toprevUniforms
:luma.gl/modules/shadertools/src/lib/shader-assembly/assemble-shaders.ts
Lines 435 to 440 in f63579c
Cached mode
In
ShaderInputs
,getUniforms
is invoked only on the modules present in thesetProps
call, without computing dependencies, and hereprevUniforms
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
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()
The text was updated successfully, but these errors were encountered: