Blender exporter shadows not working properly

one is with blur shadows and another one standard

please help (86.6 KB) blender and babylon files

Your problem is shadow acne.

You need to tweak the shadow bias value to remove the acne.

See some more explanations here: Shadows - Babylon.js Documentation

However, in your case, a simple fix (at least for the plane) is to remove the plane from the shadow caster list. (you can play around)

Your link has some problems, when changing the shadow filtering method I get errors in the console and I can’t enable/disable the shadows…

I don’t have those problems with the samples linked from the shadow doc, so I made a local PG with your asset (no problem either).

For reference, here the PG but it won’t work because it is looking for the asset locally on my computer. I can’t link to your live asset because of CORS problems.

To have good shadows, you need to tweak a number of parameters as described in the shadow doc. For shadow acne it is mainly bias (and normal bias), but you need to also tweak some other values to get the most of the shadows.

To demonstrate this, here’s your scene with the default values:

The colored box shows the light volume that will be used for shadow map rendering: the smaller the volume, the better the shadows, the gist is that all the shadow casters should be in the volume. As you can see, it is quite big in the picture (and it still goes far down).

Now let’s remove the plane from the shadow caster list as it can’t cast shadows on the cube:

Far better, no more acne on the plane as it is not a caster anymore, and the light volume is much smaller as it does not have to take into account the plane.

Still, the volume has too much extent:

I have updated the light.shadowMinZ (value = 3.5) and light.shadowMaxZ (value = 8) properties to tightly fit the cube.

Now that we have a good volume, we can tweak the shadow parameters to display good shadows (in the following pictures I have removed the volume gizmo and added an environment texture so that we can better distinguish the shadows from the cube).

In this one, I have simply set depthScale=5 and bias=0.1 in the shadow generator, the filtering method being the one you set in the asset (Blurred exponential).

Depending on the filtering method used, you may need different bias values. For eg, here’s a picture with filtering method = PCF:

As you can see at the left and right corners of the cube, there are some artifacts: the bias value (0.1) is too big and some shadows are lost.

Here’s the same picture but with bias = 0.01:

No more artifacts.

Hope that helps.

Babylon.js Playground (i created pg scene)

created light and shadow generator using script
babylon file objects shadows not working properly but created with script working
plane not added to shadow generator when i tried to add plane gone black like first shared screenshots

Please provide a PG that does not work instead, as I don’t know what to look for.

Also, you don’t need this code:

        engine.runRenderLoop(() => {

It’s already taken care by the Playground ecosystem.
im just looking for render shadows correctly

i dont why im getting black like this

im just want to create a big scene in blender and use in babylon to avoid hard code everything.
in blender i can choose which objects should cast shadows / visible / pickable.

If anyone has a perfect Babylon file with correct light n castshadows please share it will help to inspect

So it’s on the blender side: I don’t know if you are able to set the same parameters than the ones used in Babylon (shadowMinZ, shadowMaxZ, bias, …) and if yes, the exporter has to export them.

I think @JCPalmer will be able to shed some light about this as he is the master of Blender.

As for the problems when you add the plane, as explained you need to tweak the parameters:

It doesn’t exist.

Problem with shadows is that the setting is depending on your scene (the objects, the light).

It’s not a problem with Babylon itself, it’s a global problem inherent to shadow map technics. That’s why there’s the shadow doc in the first place.

sorry to say shadows are not perfect

ball shadow is perfect.
box shadow is not perfect dont know why.

light n shadow generator should work on all objects same right?

I changed the values of depthScale and blurKernel:

I think the box shadow is now perfect?

right but box gone black
check this

The createDefaultEnvironment call creates a plane at the exact same location than your existing plane, hence z-fighting.

Set only the scene.environmentTexture property instead:

sorry for troubleing you again
can you check this why floor has different shading (this one also has different shading)
box and plane assigned to same material

no lights no shadow generators coded only imported scene this kind of result i needed but missing something (plane has receive shadows) (without receive shadows)

issue solved its problem with instance materials.

thanks for jedi master

Your problem arises because the material is exported from Blender with the checkReadyOnlyOnce flag set to true. When set to false it does work:

I don’t know what is the setting on Blender side that leads to have checkReadyOnlyOnce = true in the export.

ohh i see