[InstancedUniformsMesh] Does .setUniformAt() erase material.onBeforeCompile?
See original GitHub issueI created a ShaderMaterial
with some custom Matrix4
uniforms, to rotate geometry on the vertex shader. This works when used on InstancedMesh
and even InstancedUniformsMesh
.
But once I invoke .setUniformAt()
to bind per-instance uniforms, those material-bound uniforms no longer work-- those rotation matrices no longer rotate anything, which leads me to suspect that they fell back to identity matrices (mat4(1.0)
) when the shader couldn’t access the uniform anymore.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
[Enhancement] onBeforeCompile may break material's .clone ...
onBeforeCompile seems to be ignored when cloning materials: ... document that .clone() is non deterministic, it's going to be a different ...
Read more >InstancedUniformsMesh - Troika JS
When you call setUniformAt , the geometry and the material's shaders will be automatically upgraded behind the scenes to turn that uniform ...
Read more >Material#onBeforeCompile – three.js docs
Sets the alpha value to be used when running an alpha test. The material will not be rendered if the opacity is lower...
Read more >three.js - Applying two different fragment shaders to two ...
My goal is to give each mesh a material with a unique custom fragment shader using onBeforeCompile. Each mesh has the same type...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was also able to sidestep it by calling
onBeforeCompile
aftersetUniformAt
, but agree that fixing this would better match expectations and get the small perf boost.Aha! Yup, I see the problem. When the set of instanced uniforms changes, I currently create a new derived material instance. That will carry over any
onBeforeCompile
from the base material, but not any that was assigned to the previous derived material.In your testcase, if you assign
material.onBeforeCompile
instead ofcube.material.onBeforeCompile
, it’ll work.But, I should be able to reuse the derived material when the instanced uniforms change rather than instantiating a new one, which would fix the unexpected behavior in addition to being slightly more performant.