Are there any known issues with BabylonJS where some meshes and particle systems that are visible in the real-time view on the canvas are then not visible from the image file generated using CreateScreenshotUsingRenderTarget() as viewed from the exact same camera? I’m currently seeing such issues in a scene that I’m working on.
I can create a PG if necessary but I wanted to check for known issues first. Any help would be greatly appreciated.
For particle systems, you have to pass true for the 9th parameter of CreateScreenshotUsingRenderTarget (false by default) for them to be rendered in the screenshot.
Regarding meshes, they should all be rendered in the screenshot if they are rendered in the scene.
Thank you for your advice. I tried the suggestion but this actually didn’t have any effect on my renders. I also tried playing with the minZ and maxZ values of the camera but those only fixed the problem for one or two meshes and particle systems.
I did find a workaround though at the following link where a similar problem was observed with the canvas rendering:
Setting all meshes in my scene so their alwaysSelectAsActiveMesh property was set to true fixed the problem with the snapshots. This corrected the problems with both the meshes and particle systems.
I’m curious why this worked as the problem only existed with the image snapshots, not the renders to the canvas. I assume the clipping plane behavior is somehow different between the canvas render vs. the snapshot to a render target.
The scene I was working on was rather complex and used some custom models so I couldn’t replicate it entirely in the playground. However, the playground I created has a simpler scene that appears to exhibit the same behavior as the particle systems. Even with the 9th parameter of CreateScreenshotUsingRenderTarget() set to true, the snapshot generated by clicking the button in the UI does not render the particles.
Not sure if it matters but I’m using Firefox 72.0.2 (64-bit) on Mint Linux 19.1.
Note: This playground does not show the additional issue I was experiencing with certain meshes being visible in the canvas render but not the screen capture. I can add that to the playground at a later time.
My bad, the 9th parameter is for rendering sprites…
Particle systems are rendered by default by CreateScreenshotUsingRenderTarget but for some reasons you have to use a mesh emitter for the particle systems to be taken into account in the RenderTargetTexture:
for (var particleIndex = 0; particleIndex < scene.particleSystems.length; particleIndex++) {
var particleSystem = scene.particleSystems[particleIndex];
let emitter: any = particleSystem.emitter;
if (!particleSystem.isStarted() || !emitter || !emitter.position || !emitter.isEnabled()) {
continue;
}
if (currentRenderList.indexOf(emitter) >= 0) {
this._renderingManager.dispatchParticles(particleSystem);
}
}
An emitter that is a Vector3 won’t work, you will take the continue path and won’t end up in the dispatchParticles call.
[Edit] The particles also won’t be visible if the emitter mesh is frustum culled because it is off screen. You can do mesh.alwaysSelectAsActiveMesh = true; to avoid that.