WebGLLights state and its hashing produce unintended material reinitialization
See original GitHub issueWebGLLights
is used to store lighting state.
WebGLLights.hash
property is used to determine whether or not a material needs to be re-built.
The way hash
is built, it includes unique reference to WebGLLights
instance:
https://github.com/mrdoob/three.js/blob/efeb95f10790ab4755171584139d5344177f2713/src/renderers/webgl/WebGLLights.js#L319
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
id
fromhash
calculation - use a fast hashing function to compute 64bit hash(javascript
number
is 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).
Issue Analytics
- State:
- Created 5 years ago
- Comments:21 (9 by maintainers)
Top Results From Across the Web
Cryptographic hash function - Wikipedia
A cryptographic hash function (CHF) is a hash algorithm that has special properties desirable for cryptography: the probability of a particular n ...
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
The renderer has changed at various places since this issue was originally reported. The performance of
initMaterial()
was improved via #19673, render states (and lists) are only created per scene now (#20422, #21254) and light uniforms can now be updated without triggeringinitMaterial()
viaWebGLLights.setupView()
.WebGLLights
also performs no string concatenation anymore (#14588) and simplified the usage of the internal hash (#16581).Overall I think it’s best to close the issue and open a new one if there are still performance issues.
Anyway, I have the feeling this discussion went a bit off-topic. Besides, the implementation of
WebGLLights
has slightly changed. It does not compare hashes anymore (materialProperties.lightsHash !== lights.state.hash
) but just a single version number.I actually like the idea of making
initMaterial()
faster when no shader compilation is required. Such optimizations might be valuable for #15047.