Hello everyone!
I’d like to add some global post-effect (e.g. raising all the vertices by some Y value) implemented via vertex shader. I modify the transformVS by adding an uniform and performing simple Y-shift:
pc.shaderChunks.transformVS = `
uniform float shiftY; //uniform definition
.......
vec4 posW = dModelMatrix * vec4(localPos, 1.0);
posW = posW + vec4(0.0, shiftY, 0.0, 0.0); //uniform usage
`
In order to pass a new shiftY
value to the shader, I have to go through the scene hierarchy recursively and set the shiftY value to each material on the scene using setParameter
, e.g.
const applyShaderValue = (entity) => {
entity.model.meshInstances.forEach(mi => {
mi.material.setParameter('shiftY', 2.5); // pass the new uniform value
});
entity.children.forEach(applyShaderValue); //recursive call
}
This is quite heavy task, especially when there are a lot of entities on the scene.
I wonder if there is a way to set the ‘global’ shiftY
value somewhere (e.g. apply it once for the whole scene), instead of setting it for each entity’s material individually?