A-Frame - 渲染到 RenderTarget 会导致屏幕闪烁(仅限 VR 模式)
我使用 Three.js 和 A-Frame 为 Conway 的 Game of Life 编写了一个自定义着色器,它在片段着色器中完成所有处理。它在桌面上的网络浏览器中完美运行。它似乎也适用于 Quest 浏览器,但进入 VR 模式时,整个屏幕开始在场景和黑屏之间闪烁。
我怀疑问题出在 RenderTarget 设置,或者我在渲染目标之间切换的方式,但我不确定。相关代码出现在 A-Frame 组件刻度函数中,该函数定期在两个渲染目标之间切换并返回主场景,如下所示:
this.el.sceneEl.renderer.setRenderTarget(this.renderTarget0);
this.el.sceneEl.renderer.render(this.rtScene0, this.rtCamera);
this.el.sceneEl.renderer.setRenderTarget(this.renderTarget1);
this.el.sceneEl.renderer.render(this.rtScene1, this.rtCamera);
this.el.sceneEl.renderer.setRenderTarget(null);
如果相关,我还禁用了 RenderTarget 对象上的深度缓冲区。完整代码可在 GitHub 上获取: https:// github.com/stemkoski/A-Frame-Examples/blob/master/conway-shader.html ,实时版本位于 https://stemkoski.github.io/A-Frame-Examples/conway-着色器.html。
我的问题是:在 A-Frame 中使用 RenderTargets 时,如何阻止屏幕在 VR 模式下闪烁?
I wrote a custom shader for Conway's Game of Life, using three.js and A-Frame, which does all processing in the fragment shader. It works perfectly in a web browser on desktop. It also appears to work in the Quest browser, but when entering VR mode, the entire screen begins to flicker between the scene and a black screen.
I suspect that the problem is with the RenderTarget settings, or the way in which I switch between render targets, but I am not sure. The relevant code occurs within an A-Frame component tick function, which periodically switches between two render targets and back to the main scene as follows:
this.el.sceneEl.renderer.setRenderTarget(this.renderTarget0);
this.el.sceneEl.renderer.render(this.rtScene0, this.rtCamera);
this.el.sceneEl.renderer.setRenderTarget(this.renderTarget1);
this.el.sceneEl.renderer.render(this.rtScene1, this.rtCamera);
this.el.sceneEl.renderer.setRenderTarget(null);
If it is relevant, I have also disabled the depth buffer on the RenderTarget objects. The full code is available on GitHub at https://github.com/stemkoski/A-Frame-Examples/blob/master/conway-shader.html and a live version is at https://stemkoski.github.io/A-Frame-Examples/conway-shader.html.
My question is: how can I stop the screen from flickering in VR mode, while using RenderTargets in A-Frame?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您关注 Marquizzo 引用的 Mugen87 评论(“这个想法是禁用 xr,执行渲染,然后再次启用 xr”)。 VR 中一切正常。要在 gpgpu 计算之前禁用 XR 和阴影贴图,请执行以下操作:
并在使用后重新激活它(如果在 VR 中):
工作 A-Frame 源代码:
https://glitch.com/edit/#!/experienced-political-share?path=index.html%3A204%3A12
演示:
https://experienced-political-share.glitch.me/
If you follow Mugen87 comment quoted by Marquizzo ( " The idea is to disable xr, perform the rendering and then enable xr again"). All is working fine in VR. To disable XR and shadow map before the gpgpu computation do:
And reactivate it after with (if in vr):
Working A-Frame source code :
https://glitch.com/edit/#!/experienced-political-share?path=index.html%3A204%3A12
Demo:
https://experienced-political-share.glitch.me/