GPUParticleSystem leaves instance attribute divisors bound → following post-process renders black

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.vertexAttribDivisor for one frame: GPU particles set divisor 1 on locations 0–4, 7 → post-process chain draws → only afterwards does SpriteRenderer.render() call unbindInstanceAttributes().
  • 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

I will look at this, thanks for reporting!

You have a minor comment :slight_smile:

Thanks! The review comment is addressed in the PR: the cleanup now runs once in render() after both MULTIPLYADD passes, and the test covers the shared custom effect case.

One more finding while verifying it: the default-VAO fallback is not limited to define changes. A MULTIPLYADD GPU system always draws its MULTIPLY pass through the default VAO, because the render VAO is recorded with the ADD pass effect. So any GPU particle system with BLENDMODE_MULTIPLYADD triggers the black post-process on its own (confirmed with a WebGL2 trace on 9.29). The fix covers that case as well. Details are in the PR.

Merged, thank you for submitting the fix!