Receiving shadows on emissive materials

Hello again!
I’ve been playing a bit around with scene optimizations and seeing how I can introduce minor shadows into unlit shadowbaked scenes. My goal is to have the shadowGenerator render once some specific shadows which will be cast from dynamically loaded objects whose positions are unknown initially.
So I stumpled upon that you can just choose to render the shadows once and have a great looking scene which also runs smooth as butter.

Now I’m currently stuck at the part where I tried to apply shadows generated from babylon onto unlit emissive materials. My findings so far is that I can use the lightmapTexture and assign the shadow map texture from the generator, however, I quickly figured out that the texture is made from the projection of the lightsource, so applying it directly will have distortions due to differences in the objects UV vs light projection.

Which brings me here :smiley: Does anyone have a genius way of implementing this, I’d love to hear it!

Thanks in advance

Our visuals wizard @PatrickRyan might have some idea?

@Jannick, the easiest way to accomplish this is to create a simple node material for your emissive color/texture and add in shadows from the standard lighting node:

You can see the effect in this example from one of our YouTube videos where we are casting shadows on a flat colored ground. The scene is constructed with a simple plane to “catch” the shadows that is assigned an unlit color which matches the clear color for the scene. That color then has the shadows multiplied onto it so that we can see the shadows in the scene.

In your original question, however, you mention “unlit emissive” materials. This technique will work fine with unlit materials, but if you mean truly emissive materials which are supposed to emit light and can be rendered using the glow layer, then you have a bit more work to do. You will also need to remove any emissive bits from the shadows by creating a mask for the emissive areas that may fall within a shadow and then removing those areas from the shadow map. This is because any emissive surface that is in shadow will not be darkened.

Think of a keyboard with backlit LED color. When the room lights are off (basically casting the whole thing in shadow) any non-emissive material like the key plastic or the case plastic will be dark while the rest of the materials (letters and numbers on the keys as well as the space between the keys projecting light) will be as bright as before.

Obviously in this case, you get into the act of balancing the brightness of the light cast on an object with the intensity of the emission from the object, but that is in dialing the settings of the lights in the scene and would need the same process as above.

I hope this helps answer the question, but let me know if you have others.


Thanks so much for the thorough walkthrough! I will try the node approach and if I’m successful I will come back with a working PG for anyone who’s interested!

Wish you an amazing day