Coloring shadows

I’m not 100% sure but I think we haven’t exposed the param in shadowgenerators and csm to allow users to tint shadow colors yet ?

This is solely for artistic uses, not PBR and not high priority. I’ll eventually get around to submitting the PR myself, but figured it would be better to sound out first.

You can do shadow coloring with NME:


A wonderful addition to the doc page.

@PirateJC , want to add that to the docs?

Yes! Happy to add this! Just a heads up, it won’t be until after next week as we’re prepping for the final stages of the big release moment next week. :slight_smile:

1 Like

Well, it fits my needs. Not exactly user friendly tho. I was expecting something like:

obj.receiveShadows = true;
obj.material.shadowColor = new BABYLON.Color3.Blue();
obj.material.shadowColorStrength = 0.5;

I have static meshes that each receive shadows and can occlude each other. This is in tandem with the ground. Some have shaders, most don’t. Plus a number of dynamic agents. hmm…have to think of a workaround…

You could use a material plugin:

Doc: Material Plugins | Babylon.js Documentation


Awesome, where was this 4yrs ago ? Marking as solved, thanks ! :slight_smile:


So I finally found time to work on this and tried to port my custom material that uses a splatmap for the terrain. Starting from PG, how do I declare a texture for use in the plugin ?

What I did so far:

constructor(material, splatmap, scene){
  super(material, "ColoredShadow", 700, { "COLOREDSHADOWPLUGIN": false });
  this.stxt = new Texture(splatmap, scene);
  this.markAllAsDirty = material._dirtyCallbacks[Constants.MATERIAL_AllDirtyFlag];

and I added in

	return ['splatmap'];
bindForSubMesh(uniformBuffer, scene, engine, subMesh){
        if (this._isEnabled) {
            uniformBuffer.updateColor3("cshColor", this.color);
            uniformBuffer.updateFloat("cshStrength", this.strength);
            uniformBuffer.setTexture('splatmap', this.stxt);

getCustomCode has my ported codes. Console is throwing the usual stream of undeclared identifier errors for the fragment shader with 'stxt' : undeclared identifier. Guess I just need an example of use with textures to get going…pls help !?

You should add the declaration of the texture sampler at the CUSTOM_FRAGMENT_DEFINITIONS injection point (and/or CUSTOM_VERTEX_DEFINITIONS if you want to use the sampler in the vertex shader):


@Evgeni_Popov Yes, I got it! The PG is a life-saver. I’m guessing material plugin will supercede custom material in future, powerful stuff. Again, thanks a lot…I’m a happy dev today ! :man_dancing:

1 Like