Shadow generator on complex mesh

Hi folks,

I’m having a bit of a hard time applying a shadow generator to my scene. The issue I believe is complex meshes that I have. It’s really hard to determine if I have to granularly apply it to each mesh or if the root should be fine.

Here’s a repro I put together: https://playground.babylonjs.com/#DT7AQC#16

Lines 114-120 demo a green shadow cast. I’ve added the character as a caster and produced the shadow generator however I’m not seeing anything visible. I can see it effect other parts of the mesh. I suppose my curiosity is more about how do I appropriately solve the problem of casting the shadow on the ground mesh? We want a bit of shadow to help with visualising the character touching the ground, a shadow would be a nice way of helping with that.

Thanks,

David

You should have your light follow the character so that the frustum of the light is as tight as possible all the time. You can visualize this frustum thanks to the “Display frustum” setting in the inspector when you browse the directional light. You will see something like:

This frustum should always encompass the area where the shadow must be cast. You can change the size of this frustum thanks to the orthoLeft/Right/Top/Bottom/shadowMinZ/shadowMaxZ properties of the light:

https://playground.babylonjs.com/#DT7AQC#17

@Evgeni_Popov oh wow! That’s fantastic! I’m recognising how incredibly powerful Babylon is. This is my second project with it, first time building a whole environment and I’m starting to play with all the toys that come with it. My ONLY complaint is …holy cow…there’s SO many options. I would have never known how to set the ortho values and calibrate to get just right.

I can’t always depend on this forum (as amazing as you guys are). At some point I need to be able to just set my sights on solving a problem and going for it. I wonder if the docs and explanatory tutorials in Babylon need to be improved? I’m a core team member at SolidJS (www.solidjs.com) and we’re having a similar struggle with our tutorials and docs.

Babylon has this VAST breadth of options there must be an easier way to help people through the complex. That actually begs the question, are there Babylon course and certifications yet?

Sorry for the rant. This just got me super stoked.

2 Likes

This is always the problem I guess. We are pouring a lot of energy on our docs and youtube channels (there are books as well and even a new one coming soon…cc @PirateJc)

1 Like

In fact I did not use those properties at first, I just setup the shadow generator. But I got:

The frustum is automatically computed based on the shadow caster because dirLight.autoUpdateExtends is true by default. As you can see, it’s too thin, there are artifacts (that we can’t see very well in the screenshot but they are clearly visible when animated) because the shadow goes outside the box. So, I disabled autoUpdateExtends and updated the frustum by hand.

There are some explanations about shadows with directional light in the doc:

I’m going to update it as this part is not true anymore:

You can set this property to `false`, but there's currently no clean way 
to update the ortho left/right/top/bottom values manually because those 
properties are private (probably something to work on).

[…] PR to update the doc:

2 Likes

Thanks for the feedback @dbase. We hear ya! With a mature platform like Babylon, teaching and learning is a very difficult thing to master. The hard part is that everyone comes to Babylon with different experiences and skill levels. In addition to that, everyone has different specific interests in what they want to learn. So teaching and documentation is something we have to chip away at over time. We put a lot of energy into helping people learn through our documentation, forum, tutorials, and more, but the truth is that it’s a scale problem.

If you have specific ideas on how things could/can be better we definitely want to hear it though!

Thanks again for the feedback!

Thanks folks, I suppose that was less useful feedback and more of a rant from fellow community managers. The additional info here is amazing and it’s great to see educational content and material created around the library. Certainly appreciate the effort poured into Babylon =)