Shadows from GLTF models

Is there a problem with shadows being cast by animating GLTF models - or am I doing it wrong?
I copied the ShadowOnly material example settings from the PG (which uses the skull in a non-animated .babylon format) into my project but my model does not cast visible shadows. Unfortunately the model I’m using is licensed so I can’t easily test it in the playground (or maybe I can? I saw some docs about uploading to a git cdn but that felt like it might violate the model license terms).
I switched the shadowonly material for a standard mat and there were still no shadows.

Theory 1: in the past I’ve had similar problems with gltf file materials, and found myself recursing down the tree structure to add tags to every child - is that a known limitation/design feature of this data type? Is there a tag I should add to children to make this (animating) mesh cast shadows?

Another theory: the model is HUGE, I’m having to scale it to 0.006 to make it world-scale - could this cause problems for lighting/shadows?

I ran into this problem a while back - shadows act differently on PBR materials, so if you’re trying to cast shadows on a PBR mat, you’ll need to adjust lighting and/or materials differently (falloff, attenuation, intensity, etc.)

2 Likes

Also, stating the obvious, make sure you set mesh.receiveShadows = true on the appropriate meshes, and add shadow caster meshes to the shadow generator render list.

You can use the playground with some models available to try reproduce the issue. If it works on the playground, so it’s probably on your app.

But as supershwa said, here I get the same issue: shadows in PBR workflow are a lot attenuated by the scene environment lighting.

Thanks for the replies!
@Evgeni_Popov - which ones are the ‘appropriate’ meshes? I’m adding my top level gltf mesh to the shadow generator, do I need to recurse the children and add any child mesh type nodes too? I should really poke around in the source and see if it does that automatically - but if you happen to know off-hand that would save me some effort :wink: I’m definitely setting receive on the ground material.
@supershwa - can you remember what type of adjustments the PBR materials needed? Longer/shorter/higher/lower etc?

Thanks @Vinc3r I hadn’t seen that resource with the different models, that will be incredibly helpful for re-creating tests and checking if it is just the model type that is causing issues.

By the way here an example I made: https://www.babylonjs-playground.com/#G3GZA1#49

The shadow is visible here, but the scene baked-lighting is dark, and so the .env image , that’s probably why dyn-shadows are dark.

1 Like

If you use ShadowGenerator.addShadowCaster(mesh, includeDescendants), it automatically adds the descendants because the second parameter is true by default. If you push directly to ShadowGenerator.getShadowMap().renderList, then you need to push all descendant meshes yourself.

2 Likes

Awesome, that’s almost definitely what I was missing - I didn’t know about that function, all the playgrounds I’ve seen use the renderList addition.
I’ll ping back if that fixes it for future readers :smiley:

Yes that fixed it, thanks!
I’m now projecting directional light shadows onto a ShadowOnlyMaterial which gives me really nice looking shadows under the dancing golem.