THREE.js数千个网格根据到焦点的距离调整不透明度

THREE.js数千个网格根据到焦点的距离调整不透明度,three.js,glsl,shader,Three.js,Glsl,Shader,我想根据网格与焦点的接近程度调整网格的不透明度。现在,我只是在网格中迭代,并根据它们到焦点的距离调整它们的不透明度 在伪代码中:: set_opacities: () -> for mesh in @group.children # we have the camera looking at this point "focus" # objects in the focal point should become opaque distance_to_focus

我想根据网格与焦点的接近程度调整网格的不透明度。现在,我只是在网格中迭代,并根据它们到焦点的距离调整它们的不透明度

在伪代码中::

set_opacities: () ->
  for mesh in @group.children
    # we have the camera looking at this point "focus"
    # objects in the focal point should become opaque
    distance_to_focus = mesh.position.distanceTo(focus)
    opacity = @options.delta / distance_to_focus
    mesh.material.opacity = opacity
对于少量的网格,这种方法可以很好地工作,但是当有几千个网格时,这种方法可能会非常昂贵。我还没有深入调查着色器。但是,我觉得是时候使用着色器来提高性能了。如何使用着色器根据网格到焦点的距离更改网格的不透明度?这个案例有三个内置的还是我自己写的

是否还有其他值得研究的策略?在这种情况下,合并网格并不理想,因为我不断地添加更多网格,所以我认为不断地重新计算整个几何体会很昂贵