From 2fb7fd74e7cb0971f219d6a49c9d6f80694d6eb8 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Mar 2026 13:20:45 +0000 Subject: [PATCH] Fix glow layer rendering order by using emissive mode with sky exclusion Replace addIncludedOnlyMesh() approach with all-meshes emissive mode to restore correct depth-based rendering. Exclude the sky sphere explicitly via addExcludedMesh() to prevent it from being affected by the glow layer. Also update setSky() to register new sky spheres with any active glow layer, and fix clearEffects() to scan scene metadata instead of the now- unused includedOnlyMeshes list when deciding whether to dispose the layer. https://claude.ai/code/session_01XjT3aKdwLYiYfEiYRWwt26 --- api/material.js | 20 +++++++------------- api/scene.js | 3 +++ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/api/material.js b/api/material.js index aaa1d4a29..766d38989 100644 --- a/api/material.js +++ b/api/material.js @@ -142,11 +142,12 @@ export const flockMaterial = { }, glow(meshName, { color } = {}) { if (flock.materialsDebug) console.log(`Making ${meshName} glow`); - // Ensure the glow layer is initialised and only affects explicitly - // included meshes. if (!flock.glowLayer) { flock.glowLayer = new flock.BABYLON.GlowLayer("glowLayer", flock.scene); flock.glowLayer.intensity = 0.5; + if (flock.sky) { + flock.glowLayer.addExcludedMesh(flock.sky); + } } return new Promise((resolve) => { @@ -166,10 +167,6 @@ export const flockMaterial = { m.metadata = m.metadata || {}; m.metadata.glow = true; - if (flock.glowLayer) { - flock.glowLayer.addIncludedOnlyMesh(m); - } - if (m.material) { const currentMat = m.material; const color = glowColor @@ -280,13 +277,10 @@ export const flockMaterial = { targetMesh.metadata.glow = false; if (flock.glowLayer) { - flock.glowLayer.removeIncludedOnlyMesh(targetMesh); - - const hasIncludedMeshes = - flock.glowLayer.includedOnlyMeshes && - flock.glowLayer.includedOnlyMeshes.length > 0; - - if (!hasIncludedMeshes) { + const anyGlowing = flock.scene.meshes.some( + (m) => m !== targetMesh && m.metadata?.glow, + ); + if (!anyGlowing) { flock.glowLayer.dispose(); flock.glowLayer = null; } diff --git a/api/scene.js b/api/scene.js index f5097120c..f77f1aa7b 100644 --- a/api/scene.js +++ b/api/scene.js @@ -60,6 +60,7 @@ export const flockScene = { if (color && color instanceof flock.BABYLON.Material) { const skySphere = createSkySphere(); flock.sky = skySphere; + if (flock.glowLayer) flock.glowLayer.addExcludedMesh(flock.sky); const isShader = typeof color.setFloat === "function"; const tex = @@ -90,6 +91,7 @@ export const flockScene = { if (Array.isArray(color) && color.length >= 2) { const skySphere = createSkySphere(); flock.sky = skySphere; + if (flock.glowLayer) flock.glowLayer.addExcludedMesh(flock.sky); if (color.length === 2) { const mat = new flock.GradientMaterial("skyGradient", flock.scene); @@ -128,6 +130,7 @@ export const flockScene = { ); const skySphere = createSkySphere(); flock.sky = skySphere; + if (flock.glowLayer) flock.glowLayer.addExcludedMesh(flock.sky); const skyMat = new flock.BABYLON.StandardMaterial( "skyMaterial",