There is a condition if ( v.needsUpdate !== false )
in WebGLUniforms.upload
. The only case when this is set to false I have found is in markUniformsLightsNeedsUpdate
. Could this handling be extended to other values which are often shared between materials, like envMaps and perhaps other uniforms as well, or is there some reason why this is done only for lights?
This needs to be tested but I could imagine the needsUpdate
flag isn’t require anymore. It comes from a time before uniform caching has been implemented. With a caching system in place, redundant uniform updates shouldn’t happen anymore even without separate update flags.
Understood. It is a kind of pity, trough - needsUpdate looks more elegant and more efficient, as for the caching you need to perform a comparison, which is unfortunately most expensive for a cache hit - you need to compare all array items to verify they really match.
I have made a few cursory experiments to check what obstacles are there to implement needsUpdate
for Uniforms
. One difficult part are textures - on the WebGL side they do not map do any gl.uniform
call, but to gl.bindTexture
, which is not remembered for a program like uniforms are.
Another issue are uniforms bound to matrices (e.g. directionalShadowMatrix
), which sometimes point to mutating data - matrices change somewhere and no corresponding uniform.value = x
is made.
I am not sure how difficult will solving those problem be, and I did not try to measure if there is any performance gain yet.