问题描述
我正在尝试将两个不同的场景和摄像机叠加在一起,就像 HUD 一样.两者都在单独时正确渲染.这也按预期工作,因此您可以在帮助场景下看到主场景:
I'm trying to render two different scenes and cameras on top of each other, like a HUD. Both render correctly when alone. Also this works as intended, so you can see mainscene under the helpscene:
renderer.render(mainscene, maincamera);
renderer.render(helpscene, helpcamera);
我在使用EffectComposer渲染主场景时,根本看不到helpscene,只能看到composer渲染的结果:
When I'm using EffectComposer to render the main scene, I can not see helpscene at all, I only see the results of composer rendering:
renderTargetParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBAFormat, stencilBuffer: false };
renderTarget = new THREE.WebGLRenderTarget( width, height, renderTargetParameters );
composer = new THREE.EffectComposer(renderer, renderTarget);
---- cut out for brevity ---
composer.render(delta);
renderer.render(helpscene, helpcamera); // has no effect whatsoever on the screen, why?
这里发生了什么?同样,如果我评论任何渲染调用,它们都可以正常工作.但是两者都启用了,我只看到作曲家场景/渲染.我希望帮助场景覆盖(或至少覆盖)之前渲染的任何内容.
What is happening here? Again if I comment either render call out, they work correctly. But both enabled, I only see the composer scene/rendering. I would expect the helpscene to overlay (or at least overwrite) whatever is rendered before that.
我在renderer.render(helpscene, helpcamera);
之前有相当复杂的代码,它可能会根据不同的设置采用各种不同的渲染路径并使用或不使用效果器.但我希望帮助场景始终采用没有效果或任何东西的简单路线,这就是为什么我使用单独的渲染调用而不是将其合并为效果器通道.
I have quite complex code before renderer.render(helpscene, helpcamera);
, it might take various different render paths and use effectcomposer or not based on different settings. But I want the helpscene to always take the simple route with no effects or anything, that's why I'm using a separate render call and not incorporating it as an effectcomposer pass.
事实证明这是因为一些有趣的深度缓冲区业务(?).如果我将 material.depthTest = false 设置为辅助场景中的所有内容,它将正确显示.看起来深度被某些作曲家传递或作曲家本身设置为零或非常低,而且出乎意料的是,它将具有隐藏后续渲染调用渲染的任何内容的效果.
Turns out it is because some funny business with depth buffers (?). If I set material.depthTest = false to everything in the helper scene, it will show kind of correctly. It looks like the depth is set to zero or very low by some composer pass or by the composer itself, and rather unexpectedly, it will have the effect of hiding anything rendered with subsequent render calls.
因为我现在只在辅助场景中使用 LineMaterial,但我预计在使用 depthTest = false 解决方法时会出现一些问题(稍后可能会有一些真正的阴影对象,这需要深度测试与同一辅助场景中的其他对象相对).
Because I'm only using LineMaterial in the helper scene it will do for now, but I expect some problems further down the road with the depthTest = false workaround (might have some real shaded objects there later, which would need depth test against other objects inside the same helper scene).
所以我想真正的问题是:如何在 EffectComposer 之后重置深度缓冲区(或其他东西),以便进一步的渲染调用不受它的影响?我也可以做辅助场景渲染作为最后一个composer pass,没有太大区别.
So I guess the REAL QUESTION IS: how do I reset the depth buffers (or something) after EffectComposer, so that further render calls are not affected by it? I can also do the helper scene rendering as the last composer pass, does not make much difference.
我可能应该提到,我的一个作曲家设置主 RenderPass 作为纹理渲染到为此目的创建的透视相机附近的扭曲平面几何体(如在许多后处理示例中发现的正交相机和四边形设置,但具有扭曲).其他设置有一个带有实际场景相机的正常"RenderPass,我希望深度信息是这样的,无论如何我应该看到辅助场景(这可能是一些严重的问题****ed英语,对不起,这里的非母语人士,我想不出更好的词).我对这两种选择都遇到了同样的问题.
I should maybe mention that one of my composer setups main RenderPass renders as a texture to a distorted plane geometry near a perspective camera created for that purpose (like the ortographic camera & quad setup found in many postprocessing examples, but with distortion). Other setup has a "normal" RenderPass with the actual scene camera, where I would expect the depth information to be such that I should see the helper scene anyway (that's probably some seriously f****ed up english, sorry, non-native speaker here and I could not come up with better words). I am having the same problem with both alternatives.
推荐答案
...并回答我自己.找到真正的原因后,其实很简单.
...and answering my self. After finding the real cause, it's quite simple.
renderer.clear(false, true, false);
将清除深度缓冲区,以便叠加渲染按预期工作:)
renderer.clear(false, true, false);
will clear the depth buffers so the overlay render works as expected :)
这篇关于重置由 EffectComposer 破坏的深度缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!