I noticed that the Occlusion Query doesn’t work when the mesh is added for reflections.
Press key to add/remove reflection:
https://playground.babylonjs.com/#QDAZ80#653
When both grounds are occluded, so should the sphere.
The sphere should be occluded together with the mesh it reflects with.
Yes, it’s a limitation of our occlusion query system, it only works for a single rendering of a mesh.
When reflection is added for the mesh, there’s a second rendering (for the mirror texture), which breaks occlusion query.
The occlusion query system is designed for single-pass-per-frame rendering, unfortunately.
1 Like
@Evgeni_Popov
Ok thanks, but wouldn’t it be normal and doable to disable rendering to texture, if the parent reflective mesh is not rendered (aka occluded)?
If I manually disable/enable isVisible the reflective mesh, it instantly stops/resumes rendering to texture. The same behaviour should be when isOccluded. (Skip rendering the mesh and its render texture)
There’s a customIsReady function on RenderTargetTexture. You could use it on the mirror texture to check if the sphere is occluded, and return false in that case, to bypass rendering the sphere into the mirror, like in this PG:
It doesn’t work, however, because occlusion queries are asynchronous, and the occlusion status will be updated only on the next frame (or even later, possibly). It means the mirrored sphere will have undergone the occlusion test too, canceling the one currently in flight.
This PR adds a new occlusionForRenderPassId property, which allows you to perform the occlusion test for a specific render pass, but the result is tested for all passes. In your PG, by setting it to camera.renderPassId, the test will be performed only by the main rendering of the sphere:
(will only work once the PR is merged)
1 Like