-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebGLLights state and its hashing produce unintended material reinitialization #14121
Comments
When would that happen? 2 different WebGLRenderers rendering the same scene? |
not quite, it depends on three.js/src/renderers/webgl/WebGLRenderStates.js Lines 71 to 86 in bd63a6c
|
lets say you want to render the same scene from 2 points of view. A simple example would be Mirror class. But there are a lot of other examples where having multiple cameras could be useful. Scene ID makes me skeptical also, the fact that scene ID is the same means very little for the content of that scene between frames, or indeed having two scenes that use the same materials and lighting setup. |
This is the use case in #14477. In that case, the work-around is to clone the material, and not share it: var mesh1 = new THREE.Mesh( geometry, material );
scene1.add( mesh1 );
var mesh2 = new THREE.Mesh( geometry, material.clone() );
scene2.add( mesh2 ); This is either a limitation or a bug. If we consider this a limitation, we should document both the limitation and the work-around somewhere. I'm thinking it would be preferable to consider this a bug. |
Avoiding calls of I personally consider this issue as a limitation of |
BTW: The root cause of the issue is the fact that it's possible to perform nested render calls via hooks like |
@Mugen87 |
I suggest you do a PR that demonstrates a concrete improvement. Make sure to check all examples that utilize |
Do I understand correctly that this applies to a simple CubeCamera-setting as well, i.e. in a scene with only light-based material and a cube-camera (jsFiddle): This won't cause light state changes (and calls to
But this does:
because of CubeCamera rendering 6 different PerspectiveCameras? However, this is not the case for ArrayCamera. Are ArrayCameras exempt because their cameras are assumed to be
and thus are less susceptible to missing light updates? I think I still have troubles understanding why |
The problem is that each camera has a different view matrix and thus affecting light computations. |
Exactly. So the light calculations in the THREE.ArrayCamera are actually wrong? Cause there are no calls to |
Any chances to demonstrate this with a fiddle?
No, the renderer updates the render state's light setup here for all subcamera. three.js/src/renderers/WebGLRenderer.js Line 1441 in 92ad8c5
|
Thanks for taking a look at this. I ran the THREE.js ArrayCamera example and my performance log doesn't show repeated calls to |
Can you please show the code or call stack that triggers |
The CubeCamera from above exhibits this. Call stack is Rendering to vs. rendering to |
See #19673. |
Technically, comparing That said, there is still room for performance improvements for @mrdoob Have you ever considered to derive |
This would be awesome if Devil is probably in the details, e.g. I wonder if this is the reason why |
Yeah, the problem is you still want a specific view frustum culling per sub camera. On the other hand, other tasks are redundant like updating the world matrices of the scene graph or recomputing shadow maps per sub camera. |
Anyway, I have the feeling this discussion went a bit off-topic. Besides, the implementation of I actually like the idea of making |
The renderer has changed at various places since this issue was originally reported. The performance of Overall I think it's best to close the issue and open a new one if there are still performance issues. |
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
The way
hash
is built, it includes unique reference toWebGLLights
instance:three.js/src/renderers/webgl/WebGLLights.js
Line 319 in efeb95f
constructor:
three.js/src/renderers/webgl/WebGLLights.js
Lines 103 to 111 in efeb95f
this means that if you have 2 instances of
WebGLLights
and they are identical, except forid
- 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:
id
fromhash
calculationnumber
is IEEE 64-bit Float) instead of using a stringhash
(as long as that makes sense).The text was updated successfully, but these errors were encountered: