Setting shader module uniforms from a layer #5462
-
Hello and thank you for the amazing work you are doing here! You can find more details below, but here's the gist of my questions: I've written a small shader module that I want to reuse in a few layers which extend the Bitmap layer. The shader module has a couple of uniforms that I would like to modify in each layer, without duplicating all the uniforms in each layer's shader. super.draw({
uniforms: {
...uniforms,
module_uniform1: this.props.param1,
module_uniform2: this.props.param2,
}); and this: super.draw({
moduleParameters: {
...moduleParameters,
module_uniform1: this.props.param1,
module_uniform2: this.props.param2,
}
}); with no success. Then I've tried overriding After I tried all this and also stumbled upon something in the Luma.gl documentation saying that the shader module uniforms should be treated as implementation details, I've changed strategy. I've defined a struct with all the parameters I need in the module shader and then just use it as an uniform in each layer shader, so I don't need to repeat all the different uniforms for each layer. struct Decoder
{
vec3 param1;
float param2;
[...]
};
vec3 foo(Decoder) {
[...]
} In a layer's shader: uniform Decoder decoder;
void main(void) {
vec3 bar = foo(decoder);
[...]
} But now I can't manage to set the struct uniform from the layer's draw method. I've tried these two methods so far: super.draw({
uniforms: {
...uniforms,
// METHOD 1
"decoder.param1": this.props.param1,
"decoder.param2": this.props.param2,
// METHOD 2
param1: this.props.param1,
param2: this.props.param2,
},
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
|
Beta Was this translation helpful? Give feedback.
setModuleParameters
is called automatically before each redraw with the layer's props. The easiest way to update uniforms is to implement your logic in the shader module'sgetUniforms
callback. You can find several examples in the@deck.gl/extensions
source, e.g. https://github.com/visgl/deck.gl/blob/master/modules/extensions/src/data-filter/shader-module.js#L66