felixmariotto / three-mesh-ui

⏹ Make VR user interfaces for Three.js
https://felixmariotto.github.io/three-mesh-ui/#basic_setup
MIT License
1.32k stars 141 forks source link

Depth rendering issue when using logarithmic depth buffer #212

Open nidin opened 2 years ago

nidin commented 2 years ago

Setting WebGLRenderer parameter logarithmicDepthBuffer : true causes depth rendering issues. Please see the screenshots.

logarithmicDepthBuffer : true logarithmicDepthBuffer : false
Screen Shot 2022-08-01 at 11 42 13 PM Screen Shot 2022-08-01 at 11 44 30 PM
swingingtom commented 2 years ago

hi @nidin, thanks for the report and sorry for the delay.

I was wondering if you could assist me on that issue? I never used logarithmicDepthBuffer and therefore I don't know how this work internally. Do you have some knowledge about that ?

What I can tell is, currently in v6.4.4 and above, ThreeMeshUI.Block automatically sets a renderOrder on its frame (background mesh) from its "ui depth" (number of ui parents a block have):

Whereas ThreeMeshUI.Text automatically sets a .renderOrder = Infinity;.

I could provide you some snippet to tweak the renderOrder property by is your issue the red background or the "9" ?

nidin commented 2 years ago

Hi Tom, Thanks for your reply. No worries about the delay. The issue is rendering order of the red block. I just created it to demonstrate the problem. All objects of ThreeMeshUI.Block is rendering behind the normal objects. I will try the renderOrder property and let you know the result. I don't know how logarithmicDepthBuffer works internally but I will investigate it.

tinotibaldo commented 1 year ago

@nidin I managed to fix this by including the

common logdepthbuf_pars_vertex logdepthbuf_vertex logdepthbuf_pars_fragment logdepthbuf_fragment

chunks on the Text shaders,

following these comments here https://github.com/mrdoob/three.js/issues/18800 and https://discourse.threejs.org/t/using-webglrenderer-with-logarithmicdepthbufferset-option-set-to-true-together-with-shadermaterial/5051

@swingingtom Do you think I should create a PR with these additional ones?

Cheerios

swingingtom commented 1 year ago

@tinotibaldo yes absolutely. Thanks!