Glow Layer Shader Include

I’m trying to make a custom PBR shader for a project I’m working on because I don’t know how to append to Babylon’s PBR shaders, but how would I use Babylon’s glow layer in the shader to implement emissive maps.

(this isn’t needed at the moment but how would I also implement shadows?)

this is the playground I’m working in: https://playground.babylonjs.com/#H7SXJ7#20

1 Like

You can use the customEmissiveTextureSelector of the glow layer to change the emissive texture on a per mesh basis:

Implementing shadows in a custom shader material would be a bit involved, you would need to reimplement a lot of things done in the current pbr material (you can have a look to the shader code in https://github.com/BabylonJS/Babylon.js/tree/master/src/Shaders/ShadersInclude).

But:

You can use a PBRCustomMaterial to leverage the existing PBR material and add custom code inside of it, or for even more freedom you can use the NME to create your material.

[EDIT]
Regarding shadows, I forgot you can use the new (in 4.2 ) ShadowDepthWrapper class to quickly support shadows in custom shaders!

[/EDIT]

2 Likes

Thanks for replying, I had no idea ShadowDepthWrapper or PBRCustomMaterial existed it would have saved me a lot of time! And the NME is very useful but the exported shader code doesn’t look so pretty so it’s hard to manage without going back to the editor every time.

As for the emissive map I was asking how to include the mesh that has the ShaderMaterial to the glow layer’s pass, and identifying the emissive map, but the scene isn’t even setup for that yet I was just asking ahead.

Hey, NME is mostly expected to work directly like this:
https://doc.babylonjs.com/how_to/node_material#loading-from-a-snippet-unique-url