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.)
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.
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 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.
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.
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
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.