Work princple of GlowLayer

Hi, these days I dive into BJS a bit deep fo figure out how glowlayer works, mainly I don’t understand why the engine can render meshes with only emission part and ignore the rest parts like diffuse color, where is the key part in the source code?
ohh the source code is too complex, i’m dead… :cold_face:

You can take a look at this shader : Babylon.js/glowMapGeneration.fragment.fx at master · BabylonJS/Babylon.js · GitHub
and this function:
Babylon.js/effectLayer.ts at a4774fb3dd67c2a97f2ceaf0265a2b2c4ef01cb7 · BabylonJS/Babylon.js · GitHub

1 Like

thanks, Cedric!

1 Like

I solved it!
the rendering process sequence are:

scene.render ->
-> processCameras
-> renderForCamera
-> sceneComponent.renderMainTexture (EffectComponent)
-> renderTexture.render
-> renderingManager.render
-> renderingGroup.render
-> use custom function to render // custom function = EffectLayer.mainTexture.renderFunction
-> render depth only objs & opaque objs & alphatest objs & transparent objs
-> while rendering opaque objs ->
-> bind obj’s geometry
-> upload necessary uniforms e.g. emissiveColor / emissiveTexture for the generated effect shader
-> gl.drawElement

and the shader is generated dynamatically according to what the effectlayer has.

through this analyzing I learnt huge new things from BJS, this is really an amazing framework ever, it considers so many things in detail! thanks so much BJS team! :sparkling_heart: :muscle: :muscle:


The only missing step in your great analysis is the blur of the texture holding the emissive parts giving the nice feeling of glow :slight_smile:

:grin: yes yes, that part I have already known, so I did not write it down.

1 Like