Jump to content

Shadows, Directional Light and all that jazz


Recommended Posts

Hi guys,

I am trying to understand the fundamental concepts of direction light and the shadow generator, and how to combine them both.

I am playing with the shadows demo from the playground - 

  • I have removed light2 (well, commented it :) )
  • I have added another sphere to show me the direction's position (the new sphere's position is light.direction)

Light direction is -1, -2, -1 . So far so good. Example here - http://playground.babylonjs.com/#XOOY7 , and everything is working fine.


Now I do the following - I change the light's direction to -1,-1,-1. I wouldn't have expected Any major difference (shadow should move a bit, it should still be generated for the entire object).

What happens is this - http://playground.babylonjs.com/#XOOY7#1 . Part of the shadow is simply cut out (Lower right corner, in case you haven't changed the camera perspective). 

Ok, I then decided to keep on experimenting. I have changed the direction to -1, -20, -1 . Once again, I have expected that there won't be a major difference in the shadow (I have just moved the light's y a few units (well, 18 :) ) down. This is how it looks like - http://playground.babylonjs.com/#XOOY7#2

This time, the upper left corner is somehow filtered out.


I have continued to change the direction property a few more time, but the only time a real full shadow appeared was when it was -1, -2, -1. I have also played with the light's position, it was still very hard to get the shadows working with different configuration.


I do believe my major misunderstanding is about the direction property of the directional light. The direction is the point to which the light source is directed to. Light is emitted from  everywhere, which means that technically objects should be lit from the bottom as well. The position property of the light is just for the shadow generation. Otherwise it is not really used (I hope I got that right).

What am I missing? Why is the shadow not working correctly?

Link to comment
Share on other sites

I have to admit that shadow maps are not clear enough. Your assumption is right for lighting. But for shadows, I need to create a shadow map and to do so I need a position (the point of view of the light).


So for shadows, you have to consider that I'm taking a snapshot of the scene from the position of the light. This snapshot uses the direction to know where to look

Link to comment
Share on other sites

Wouldn't it be possible to check inside the directional light script, if any object is outside of the shadowMap so if any object is not inside the 'view field' of the directional light "Camera" and then Log at least a warning to the console?

I think it would help people who are new to the field...

Link to comment
Share on other sites

  • 2 years later...

@Deltakosh it seems moving the light up high will cause the shadows to look more blurry. it can be seen in https://www.babylonjs-playground.com/?15 if you adjust the y value of the light1 position to 400 you will see the shadows change. 

how do we cast a shadow from a directional light onto every object in the scene without losing shadow quality?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...