The second light in scene breaks the first light's specular

PG: https://playground.babylonjs.com/#MIR9SK#3.

The playground works fine without light2, but after creating it, the first light showed specular, though with a black specular color.
It seems the define SPECULARTERM should be splitted to each light?

Hum? May be the wrong PG here. I can see only one light.
Though, the title of your post kind of reminds me of something. Could it be related to this:

As far as I know specular is essentially achieved through the material and not the light source. Although this also depends on the type of material, where you have more latitude using a PBR material. May be try explain a bit more, add the correct PG and next I believe @Evgeni_Popov or @sebavan should be able to give you the correct feedback. But I don’t think this is ‘a bug’… rather a feature request, that might be a bit complex to implement (though I could be wrong?… as often :grin: :rofl:)

1 Like

Thanks for the related topic and the explaination, but I still believe there is a bug here.

In the topic, the reason why changing the light’s specular color will not work is it will not trigger define is dirty, the define SPECULARTERM is set when creating the scene, and there is always specular part calculated. If I set light’s specular color to black at first, the white component on the cube will disapper.

Setting specular color to black at first: https://playground.babylonjs.com/#MIR9SK#3.
Setting specular color to black later: https://playground.babylonjs.com/#MIR9SK#4.

And for the ‘bug’ I found:

First let’s imagine there is one light in the scene.

This image shows there is diffuse part and specular part when diffuse is set to black, because the specular part will use light’s diffuse color to calculate, both diffuse part and specular part is black.

Then I reset the diffuse color and set specular color to black, there is no specular part, so the white component on the cube disappeared.

Now let’s introduce the second light with default white specular and keeping the black specular of the first light.

The white component on the cube appeared because the specular part existed again.

That’s because of this line:

The define SPECULARTERM is set to true by the second light, so even setting the first light’s specular color to black will not work.

So if this should be set on the material side, then the define SPECULARTERM should not be influenced by the black specular, otherwise it should be splitted to each light in my opinion.

Thanks for the explanations and PGs. Makes it a lot clearer.
With this, let’s call back cc @Evgeni_Popov @sebavan see what can be done?…
Meanwhile, have a great day :sunglasses:

This is by design: the activation/deactivation of the specular lighting calculation is done at material level. As soon as you have at least one light with a non-black specular color, the specular calculation is activated in the shader (PrepareDefinesForLight, where the line you highlighted comes from, is called in a loop for each light in the scene). When specular lighting is enabled, if you don’t want a light to generate specular lighting, you must set the specular color of that light to black. This will not remove the specular calculation from the shader, but as the color is black, it will have no effect on the final color.

1 Like

However in this PG I don’t want light to generate specular color, but the white component is still there with light’s black specular. I mean the specular calculation is not aware of the specular color once it is activated.

Ah, I hadn’t noticed you were using PBR materials!

These materials are physically-based, so you’re very limited in what you can do with specular color.

If you have a single light with black specular color, the specular lighting calculation is skipped in the shader, which is why you don’t have specular reflection in this case. As soon as you have at least one light with a specular color, the specular lighting calculation is activated in the shader, for all lights. And since the specular lighting calculation only takes into account the diffuse color of the light (the specular color of light doesn’t exist in PBR), you see a reflection.

2 Likes