Material shines through when zooming out (three.js r78)

人走茶凉 提交于 2019-12-03 16:25:13
Wilt

This problem is caused by a faulty configuration that severely limits the depth buffer precision.
On OpenGL.org it is described as follows:

You may have configured your zNear and zFar clipping planes in a way that severely limits your depth buffer precision. Generally, this is caused by a zNear clipping plane value that's too close to 0.0. As the zNear clipping plane is set increasingly closer to 0.0, the effective precision of the depth buffer decreases dramatically. Moving the zFar clipping plane further away from the eye always has a negative impact on depth buffer precision, but it's not one as dramatic as moving the zNear clipping plane.

True, since in the example the near clipping plane value was set to 1.
So far I know two solutions to this problem.


1) Simply increase the camera near value:

// camera
camera = new THREE.PerspectiveCamera(
    45, window.innerWidth / window.innerHeight, 
    500, // <-- Increased near from 1 to 500
    150000
);

This solution is demonstrated in this fiddle


2) Configure the WebGL renderer to use a logarithmic depth buffer:

// renderer
renderer = new THREE.WebGLRenderer({
    antialias: true,
    logarithmicDepthBuffer: true // <-- Set render to use logarithmic depth buffer
});

This solution is demonstrated in this fiddle


Please post another answer in case you know any other solutions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!