Spotlight illuminates black textured Material

Hi,

I have a model that consists of different meshes and thus has different materials for each of them. The interesting part for my question is the mesh for the casing of the machine model with another mesh kind of on top of it. Because of the other mesh the casing mesh has a shadow drawn in its texture at the spot below that mesh. So the albedo texture of my PBRMaterial makes up the shadow.
Now I want to illuminate part of the front of the casing with a purple spotlight. However the reflection of that spotlight finds its way to the technically shady area of the casing:
[Babylon Lighting - Album on Imgur] (imgur, since I could only add one media file as a new user)

I tried adding the mesh on top to cast shadows but to no avail. The only thing that really worked like how I intended it to be, was turning the F0 Factor all the way down for the material of the casing. Then the black parts of the texture are not reflecting the spotlight. However this also dims the reflection of other parts of the casing, so I’m wondering if that is really the way to do it.

My question is: What are even the correct settings (or even textures?) to use to not have black parts of the texture return light, because I don’t think it is the F0 Factor if that also dims light reflection at other places.

Welcome aboard!

That should work, but you must flag the other mesh with receiveShadows = true. If it still does not work, you should setup a repro in the Playground so that we can help more.

I would gladly post my repro, but the model is copyrighted.

I’m trying to do the shadow like this:

var topShadow = new BABYLON.ShadowGenerator(1024, spotLight2);
topShadow.useBlurExponentialShadowMap = true;
topShadow.useKernelBlur = true;
topShadow.blurKernel = 1;

let casing = scene.getMeshByName("casing");
casing.receiveShadows = true;
topShadow.getShadowMap().renderList.push(scene.getMeshByName("topMesh"));

but that has no effect whatsoever.

So after some trying around I managed to get a satisfying result by adding the albedo texture as a lightmap (turned to shadowmap). If it was optimized to be a shadowmap it would certainly have the effect I wanted. In retrospect it makes sense to also use a lightmap, why should the albedo texture hinder a light from applying to it…

Shadows are very sensitive to the values of the parameters you give. Try to use the inspector to modify them and see if that helps.

It’s the object above the texture that should cast shadows and thus blacken the object.

1 Like

Hi again,

you’re right! It does actually work very well with shadows, no need for a lightmap! I just had to swap from Spotlights to Pointlights. Spotlights did no shadows at all, while Pointlights cast them as expected.

Actually… it doesn’t really work :sweat_smile:

I think it goes wrong when the casing mesh has to cast a shadow on itself. But the shadow also behaves weird when I just add the top mesh. Im left with the whole mesh being regarded as shaded, so no light reflection anywhere anymore. That’s why it looked okay in the beginning to me, as I just focused on the part that was usually falsely illuminated :yum:

Does this issue ring any bell? Otherwise I could try to show the current problem with images again if that helps.

Well,

I did the google and found that I had to adjust the shadow generator value Bias and Depth Scale. In fact you had already told me the answer! :sweat_smile:
https://doc.babylonjs.com/divingDeeper/lights/shadows#self-shadow

Thank you!

Glad you made it working!

However, if at all possible, you should avoid using a shadow caster with a point light because it is the light that incurs the most penalty performance as it needs to generate 6 shadow maps. You should make it work with a spot light (which generates a single shadow map). Your problems were most probably the tweaking of bias / depth scale, or maybe try to use another filtering method than blur exponential.