Hi everybody!
When a GPUParticleSystem is the last instanced draw before the camera post-process chain, the post-process output can be fully transparent/black while the GUI on top still renders.
Repro: Babylon.js Playground (WebGL2) — fog is enabled after 30 frames → black. The toggles APPLY_WORKAROUND and ADD_CPU_PARTICLES both restore the image.
Cause: WebGL2ParticleSystem.bindDrawBuffers() uses the particle system’s own render VAO only if the current render effect is the one the VAO was recorded with (_renderVAOEffects[index] === effect). Once any render define changes after initialization (fog, clip planes, image processing, …), it permanently falls back to engine.bindBuffers() on the default VAO, which sets vertexAttribDivisor(loc, 1) for the instance attributes. GPUParticleSystem._render() only calls engine.unbindInstanceAttributes() when scene.forceWireframe is set, so the divisors stay at 1 until some other renderer (CPU ParticleSystem, SpriteRenderer, instanced Mesh) happens to reset them.
The PostProcessManager then draws its fullscreen quad with a non-instanced drawElements, but position (location 0) still has divisor 1 → all four vertices read instance 0 → degenerate triangles, zero fragments. The post-process output stays at its clear color (0,0,0,0). In practice this is intermittent, because any CPU particle system rendered after the GPU one resets the divisors.
Evidence (live app, WebGL2, Babylon 9.28.0; repro confirmed on 9.29.0):
- Disabling
scene.postProcessesEnabled→ scene visible. - Read back: post-process input has the correct image, its output is 100 %
(0,0,0,0). - During the post-process draw: GL state clean (no depth/scissor/stencil, color mask open, FBO complete, no GL error), but
gl.getVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_DIVISOR) === 1. - Hooking
gl.vertexAttribDivisorfor one frame: GPU particles set divisor 1 on locations 0–4, 7 → post-process chain draws → only afterwards doesSpriteRenderer.render()callunbindInstanceAttributes(). postProcessManager.onBeforeRenderObservable.add(() => engine.unbindInstanceAttributes())restores the image immediately.
Fix: call engine.unbindInstanceAttributes() unconditionally at the end of GPUParticleSystem._render(), like ThinParticleSystem, SpriteRenderer and Mesh already do. In the VAO path this is a no-op. PR: Fix GPUParticleSystem leaving instance attribute divisors bound by redstair · Pull Request #18975 · BabylonJS/Babylon.js · GitHub
Thank you very much for your time - you are awesome!
Klaus