-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Description
WebGLLights is used to store lighting state.
WebGLLights.hash property is used to determine whether or not a material needs to be re-built.
three.js/src/renderers/WebGLRenderer.js
Lines 1479 to 1482 in bd63a6c
| } else if ( materialProperties.lightsHash !== lights.state.hash ) { | |
| properties.update( material, 'lightsHash', lights.state.hash ); | |
| programChange = false; |
The way hash is built, it includes unique reference to WebGLLights instance:
three.js/src/renderers/webgl/WebGLLights.js
Line 319 in efeb95f
| state.hash = state.id + ',' + directionalLength + ',' + pointLength + ',' + spotLength + ',' + rectAreaLength + ',' + hemiLength + ',' + shadows.length; |
constructor:
three.js/src/renderers/webgl/WebGLLights.js
Lines 103 to 111 in efeb95f
| var count = 0; | |
| function WebGLLights() { | |
| var cache = new UniformsCache(); | |
| var state = { | |
| id: count ++, |
this means that if you have 2 instances of WebGLLights and they are identical, except for id - you will end up rebuilding materials as you switch between these instances - inefficient.
Another problem with the current approach is that it is probabilistic, it's possible that hash remains the same even though lighting has changed.
I propose following:
- remove
idfromhashcalculation - use a fast hashing function to compute 64bit hash(javascript
numberis IEEE 64-bit Float) instead of using a string - pass more than just number of lights into the
hash(as long as that makes sense).