I want to use GlowLayer effect for a few meshes in my project. However, the glow effect is not blocked by other meshes.
When I turn on the GlowLayer effect on the DefaultRenderingPipeline, everything seems just fine. But I have emissive materials which don’t want to be glowed.
Is there a problem with my settings?
Try to call glowLayer.addExcludedMesh for the meshes that should be occluders, or glowLayer.addIncludedOnlyMesh only for the meshes that should glow if the former does not work.
I’ve tried both glowLayer.addExcludedMesh and glowLayer.addIncludedOnlyMesh. The occlusion problem was still there.
Then I looked up into the GlowLayer source code. It was as below.
/**
* Determine if a given mesh will be used in the glow layer
* @param mesh The mesh to test
* @returns true if the mesh will be highlighted by the current glow layer
*/
public hasMesh(mesh: AbstractMesh): boolean {
if (!super.hasMesh(mesh)) {
return false;
}
// Included Mesh
if (this._includedOnlyMeshes.length) {
return this._includedOnlyMeshes.indexOf(mesh.uniqueId) !== -1;
}
// Excluded Mesh
if (this._excludedMeshes.length) {
return this._excludedMeshes.indexOf(mesh.uniqueId) === -1;
}
return true;
}
So glowLayer.addExcludedMesh and glowLayer.addIncludedOnlyMesh works in the same way. If I choose some certain meshes to return ‘true’ for the ‘hasMesh’ function. And the rest meshes will return ‘false’ which the GlowLayer will do nothing about these meshes. And the occlusion problem will be caused from here, right?
It seems the only way to deal with the occlusion problem is returning ‘true’ for all meshes. But this is not what I want. Do you have any other idea?
What i did in this case was to specify customEmissiveColorSelector and customEmissiveTextureSelector for the GlowLayer instance. For every mesh which should not glow you need to return black as the emissive color. For the others you return the emissive color of the material.
I am not able to overcome the occlusion issue using the customEmissiveColorSelector and customEmissiveTextureSelector fix suggested by Kesshi. Or I’m doing it wrong. So i set up this playground with what I think reproduces the issue. The emissive color of the occluding mesh is set to black as suggested. Here is the playground example : https://playground.babylonjs.com/#DQLZMD#1
And even if this worked as intended how can one have mesh objects in a scene that have baked lighting on the material yet still occlude glow layer mesh objects if their emissive color must be 0,0,0,0?
I have an actual project where this is the case. Lots of lighting baked into the scenes mesh objects so I dont have to have dynamic lighting for that. But then the material must have an emissive strength of 1 in Blender to correspond to the baked lighting when exporting to .glb.
Must I choose between using baked lighting on assets and having glow layer effects? Or I can try to compensate for the lack of emissive light on the material using a hemispheric light but that leads to some color profile issues where the colors mat and it seems overexposed.
So really hoping there is a way to have both. Since glow layers dont provide actual illumination it is a nice combo to use with baked assets to save on performance In my opinion.
Ok yes if you only use the glow layer in its simplest form the cube occludes the sphere. But this means no emissive light strength on any other mesh in the scene right?
Like I originally described the actual project I am working on has a room with lighting baked in to the PBSDF material. So to see that color data there must be some emissive strength on that emissive texture. Otherwise I would have to compensate with a hemispheric light. And while it doesnt cost a lot performance wise the colors become matted and overexposed this way.
But if the glow layer doesnt occlude unless its just on for all emissive strength sources in the scene it does seem like I have to choose. Baked lighting or glow layer. I dont have a playground example to show but this youtube video " 06. Baked Lighting with Blender in BabylonJS" https://www.youtube.com/watch?v=jfWCLGREFt4&t=1606s
shows the same principle. The PBSDFmat takes both the base color and the emissive color and the emissive strength is set to 1.
Now what I am trying to understand is if I can use a glow layer in a scene where such materials exist without the whole scene glowing. addIncludedOnlyMesh doesnt do much if it doesnt respect it. Was therefore hoping for a way to use customEmissiveColorSelector or setMaterialForRendering or any of the other tricks I’ve tried to get around it without breaking occlusion.