-
Notifications
You must be signed in to change notification settings - Fork 2.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
Objects in custom layer flicker when using atmosphere sky layer #10372
Comments
I'm still working on exactly why, but adding |
The fundamental problem is that OpenGL/WebGL is extremely stateful, and each library manages state in its own way, so that getting different WebGL libraries to play well together in the same context is a somewhat common problem. I'm not certain what (Additionally, mrdoob/three.js#21281 and mrdoob/three.js#21295 squashed a few more unaccounted for pieces of state, so that it looks like r126 is the first version of Three.js for which A fixed example: https://codepen.io/rsreusser/pen/ExNooXE Thus, there are two solutions to this problem, I think:
(different layer orders might be able to work around the problem, but that might be unnecessarily fragile.) |
@rreusser Nice find. The place we set front face: mapbox-gl-js/src/render/draw_sky.js Line 115 in 63f39e5
Code resetting state before custom layer rendering mapbox-gl-js/src/render/painter.js Line 758 in 63f39e5
seems to be resulting with Line 292 in 63f39e5
and your analysis shows that there it is needed to call setDefault also for Context.cullFaceSide and Context.frontFace (in addition to disabling cull face). mapbox-gl-js/src/gl/context.js Lines 247 to 255 in 63f39e5
Didn't run the code to verify it. |
Thanks for the additional sleuthing @astojilj! It sounds like it would benefit from a small change on the Mapbox side, though does that still leave room for problems? Here is what Three.js is doing to manage culling: My concern is that setting a more common default may reduce the likelihood of problems in common scenarios, but that if you rendered a custom layer with front face culling twice in Three.js, setting this default before a custom layer would confuse Three.js as it would still expect front face culling to be active on the second call. (unless resetState() is called in Three.js) It seems like adding setDefault for culling before custom layers is probably appropriate so that custom layers are predictable, but that |
The idea is to reset GL state to default before passing control over to custom layer, regardless the engine used by custom layer. Note that Three.js is just one of the approaches that could be used to render custom layer: similar code we have in gl-native that can use e.g. plain OpenGL, Metal, SceneKit to render custom layer. We cannot make any assumptions on state of custom layer code but to set GL state to default: |
Got it, thanks. That makes sense. I submitted #10412 which addresses this. I did some equivocating in that ticket since if external libraries maintain their own concept of state, they may or may not expect things to be in a default state, but if the guiding principle here is that Mapbox ought to hand off in a default state, then that seems very clear and still beneficial for consistency. |
When I add a custom layer to show 3D models using three.js and a sky layer with
'sky-type': 'atmosphere'
to the map, 3D objects flicker when callingsetPaintProperty('sky', 'sky-atmosphere-sun', ...)
. This only happens when the horizon is invisible.See my CodePen below to reproduce the problem.
mapbox-gl-js version: v2.1.1
three.js version: any
browser: Chrome, Safari, Firefox and Edge
Link to Demonstration
https://codepen.io/nagixx/pen/yLVJEqr
Expected Behavior
3D models don't flicker.
The text was updated successfully, but these errors were encountered: