Skip to content

Commit 514da92

Browse files
authored
Merge pull request #455 from flipcomputing/claude/fix-glow-rendering-order-GUYnZ
Refactor glow layer management to use exclusion instead of inclusion
2 parents 29910b9 + 2fb7fd7 commit 514da92

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

api/material.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,12 @@ export const flockMaterial = {
142142
},
143143
glow(meshName, { color } = {}) {
144144
if (flock.materialsDebug) console.log(`Making ${meshName} glow`);
145-
// Ensure the glow layer is initialised and only affects explicitly
146-
// included meshes.
147145
if (!flock.glowLayer) {
148146
flock.glowLayer = new flock.BABYLON.GlowLayer("glowLayer", flock.scene);
149147
flock.glowLayer.intensity = 0.5;
148+
if (flock.sky) {
149+
flock.glowLayer.addExcludedMesh(flock.sky);
150+
}
150151
}
151152

152153
return new Promise((resolve) => {
@@ -166,10 +167,6 @@ export const flockMaterial = {
166167
m.metadata = m.metadata || {};
167168
m.metadata.glow = true;
168169

169-
if (flock.glowLayer) {
170-
flock.glowLayer.addIncludedOnlyMesh(m);
171-
}
172-
173170
if (m.material) {
174171
const currentMat = m.material;
175172
const color = glowColor
@@ -280,13 +277,10 @@ export const flockMaterial = {
280277
targetMesh.metadata.glow = false;
281278

282279
if (flock.glowLayer) {
283-
flock.glowLayer.removeIncludedOnlyMesh(targetMesh);
284-
285-
const hasIncludedMeshes =
286-
flock.glowLayer.includedOnlyMeshes &&
287-
flock.glowLayer.includedOnlyMeshes.length > 0;
288-
289-
if (!hasIncludedMeshes) {
280+
const anyGlowing = flock.scene.meshes.some(
281+
(m) => m !== targetMesh && m.metadata?.glow,
282+
);
283+
if (!anyGlowing) {
290284
flock.glowLayer.dispose();
291285
flock.glowLayer = null;
292286
}

api/scene.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export const flockScene = {
6060
if (color && color instanceof flock.BABYLON.Material) {
6161
const skySphere = createSkySphere();
6262
flock.sky = skySphere;
63+
if (flock.glowLayer) flock.glowLayer.addExcludedMesh(flock.sky);
6364

6465
const isShader = typeof color.setFloat === "function";
6566
const tex =
@@ -90,6 +91,7 @@ export const flockScene = {
9091
if (Array.isArray(color) && color.length >= 2) {
9192
const skySphere = createSkySphere();
9293
flock.sky = skySphere;
94+
if (flock.glowLayer) flock.glowLayer.addExcludedMesh(flock.sky);
9395

9496
if (color.length === 2) {
9597
const mat = new flock.GradientMaterial("skyGradient", flock.scene);
@@ -128,6 +130,7 @@ export const flockScene = {
128130
);
129131
const skySphere = createSkySphere();
130132
flock.sky = skySphere;
133+
if (flock.glowLayer) flock.glowLayer.addExcludedMesh(flock.sky);
131134

132135
const skyMat = new flock.BABYLON.StandardMaterial(
133136
"skyMaterial",

0 commit comments

Comments
 (0)