Lightmap dynamic color

Hi,

I feel like I’m missing something obvious, but, I want to apply a color to a lightmap. Basically the equivalent of material.emissiveColor

e.g. material.lightmapColor.

More details, we have a flat shaded mesh, and a lightmap texture with a gradient. I want to pulse the base material color and the highlights through a range of colors.

Ideas?

In case your lightmap is used as shadowmap, you can tweak the ambientColor (and not forget to tweak scene ambientColor too) https://www.babylonjs-playground.com/#4AJ16M#19 (l.56)

In case your using it not as shadowmap, could be great to have a playground example.

No, its not a shadow map, so I dont think this will work.

let me try
if you have any sample in PG share please or i wanna make some

Here is a base PG example with the lightmap loaded:

https://playground.babylonjs.com/#2KUVCG

thanks
https://playground.babylonjs.com/#2KUVCG#1

Awesome, looks great - but it can only be done with a custom shader?

what material type you use
if you use standardMaterial you can change that to Custom
https://playground.babylonjs.com/#2KUVCG#2

I don’t understand which result you want to get. On your example above, your lightmap is tinted, isn’t it? (here just the same but with the animation from nasimiasl code).

And by the way, it seems your talking about emissive texture, and not lightmap right? (anyway, it’s the same logic but using ambientColor)

I’ll try and explain it a little better:

example

A is the mesh with Standard Material and diffuse texture:

B is the lightmap:
When I apply the light map as either:

  1. emissiveTexture + useEmissiveAsIllumination
  2. lightMapTexture

It looks like d (c is just lighmap as emissive)

This is great, I and change the level to make a nice effect, but, I want to change the color of the lightmap. Just changing emissiveColor (in this case to Color3(1,0,0) ) gives me E.

Instead of just the lightmap changing color, the whole mesh gets changed. What I want to see is just the areas affected by the lightmap change color.

Here are the textures in a playground example:
https://playground.babylonjs.com/#XJANGB

OK I see. So you’re right, using StandardMaterial seems doesn’t allowing what’s you want, and so custom shader could be useful, as nasimiasl made.

But you can also use PBRMaterial, which looks like close to what you want:

https://playground.babylonjs.com/#XJANGB#1

But you maybe spot a bug, I’m not sure, but it seems strange to me that an emissiveTexture generate emissiveColor with black pixels (even multiplied by white emissiveColor) : https://playground.babylonjs.com/#XJANGB#2 (is it @Deltakosh we have to ping here? :slight_smile: ) I think here we should just have white & red emissiveColor where emissiveTexture is white isn’t it? (even in stable BJS version it acts the same, so maybe I miss something basic here :smiley: )

1 Like

Thanks, I suspected PBR was the way to go.

Maybe we need a material.lightmapColor ?

@Vinc3r what is the problem again? :slight_smile:

1 Like

Erf, actually no problem at all, I had a mistake on my standardMaterial playground example above, now fixed: https://playground.babylonjs.com/indexStable.html#XJANGB#5

emissive channel works exactly how it needs, both useEmissiveAsIllumination true or false ; all is well in the best of all worlds, sorry for the ping :smiley: I was just not getting why this doesn’t work with rjewson playground.

I was unsure hence my question :smiley: