如何修复 Three.js 中无缝对象之间的间隙?

发布于 2025-01-09 18:52:04 字数 1706 浏览 0 评论 0原文

我试图在 Three.JS 中实现彼此相邻的无缝对象,目前它在大多数设备/浏览器上运行良好,但在某些情况下我遇到了困难。例如,当将 MacOS 与最新版本的 Google Chrome(以及 Safari)一起使用时,对象渲染时会出现不应存在的像素化间隙。

所有 3D 对象、GLTF 模型(左)和 BoxGeometry(右)都会出现错误:

使用相同的 Mac 设备但使用 Firefox 时,一切都会按预期呈现:

尺寸恰好为 (1, 1, 1),并且应该彼此完全贴合。我还尝试将其放大到(1.05, 1.05, 1.05),但这并没有解决问题,事实上,当启用纹理时在 Z-fighting 中应用缩放结果时,情况只会变得更糟。

我目前正在使用 Three.JS 的 R137,并确保我的应用程序正确应用 window.devicePixelRatio,因此这也不应该成为问题 - 是否有任何我忘记的其他渲染器设置可以提供帮助解决这个渲染问题吗?

Android 和 Windows 设备的行为也可以正常工作。使用的 Android 设备的 devicePixelRatio 大于 2,一切看起来都很顺利。我怀疑这是我的 Mac GPU 的问题,因为它可以在 Firefox 中正确渲染;这可能是浏览器的错误,我们可以自己做些什么吗?

希望这不是重复的,我找不到任何解决方案/答案。

编辑:

我发现 EffectComposer(用于 FXAA)导致 Mac 设备上的 Google Chrome / Safari 出现这些问题。这很奇怪,因为它在所有其他设备上都可以正常工作。我目前仍在寻找解决此问题的方法。如果有人过去在使用 EffectComposer for Mac 时遇到问题并设法解决这些问题,请与我们分享您的解决方案。当用例如 Sepia 着色器替换 FXAA 着色器时,会出现相同的错误,传递哪些着色器似乎并不重要,从 EffectComposer 传递的任何内容都会导致此问题。

我做了一个小提琴: https://jsfiddle.net/ilanbentley/g3yxdvmh/3/ 请注意右侧 (EffectComposer) 的边缘有问题,而左侧 (渲染器) 看起来不错(对于 Mac)。

不知何故,下面的代码导致了这种错误行为:

    const renderPass = new RenderPass( scene, camera );
    fxaaPass = new ShaderPass( FXAAShader );
    composer2 = new EffectComposer( renderer );
    composer2.addPass( renderPass );
    composer2.addPass( fxaaPass );
   

在此处输入图像描述

I am trying to achieve seamless objects next to each other in Three.JS which currently works fine on most devices / browsers but in some cases i'm experiencing difficulties. For example while using MacOS with the latest version of Google Chrome (and also Safari) the objects render with pixelated gaps in between that should not be there.

Bug occurs with all 3D Objects, GLTF models (left) and BoxGeometry (right):
Gaps in between

While using the same Mac device but using Firefox everything renders as expected:
No gaps in between

Sizes are exactly (1, 1, 1) and should fit exactly next to each other. I've also tried to scale it up to (1.05, 1.05, 1.05) but this didn't fix the problem, in fact it only got worse as applying scaling results in Z-fighting when textures are enabled.

I'm currently using R137 of Three.JS and made sure my application correctly applies window.devicePixelRatio so that should not be the problem either - is there any other renderer setting that i'm forgetting which could help resolve this rendering issue?

The behaviour for Android and Windows devices also works correctly. The used Android device has a devicePixelRatio greater than 2 and everything looks smooth there. I doubt it's a problem with my Mac GPU as it renders correctly with Firefox; is this a bug of the browser maybe, and is there something we can do about it ourselves?

Hopefully this is not a duplicate, i couldn't find any solutions/answers to this.

EDIT:

I've found out that EffectComposer (for FXAA) are causing these problems for Google Chrome / Safari on Mac devices. Which is weird because it works completely fine on all other devices. I'm currently still looking for a way to fix this. If anyone had problems in the past with EffectComposer for Mac and managed to fix them please share your solution with us. When replacing FXAA shader with for example Sepia shader the same bugs occur, it doesn't seem to matter which shaders are being passed, anything pass from EffectComposer causes this.

I've made a fiddle: https://jsfiddle.net/ilanbentley/g3yxdvmh/3/
Note how the right side (EffectComposer) has buggy edges while the left side (Renderer) looks good (for Mac).

Somehow the code below is responsible for this buggy behaviour:

    const renderPass = new RenderPass( scene, camera );
    fxaaPass = new ShaderPass( FXAAShader );
    composer2 = new EffectComposer( renderer );
    composer2.addPass( renderPass );
    composer2.addPass( fxaaPass );
   

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文