# Shadow and light problem

**URL:** <https://forum.babylonjs.com/t/shadow-and-light-problem/6068>\
**Category:** Questions\
**Created:** [October 2, 2019, 1:03pm UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068 "2019-10-02T13:03:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomas\_e](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thomas_e/32/4760_2.png) [@thomas\_e](https://forum.babylonjs.com/u/thomas_e)\
**Post date:** [October 2, 2019, 1:03pm UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/1 "2019-10-02T13:03:45Z")

</div>

Hello,

I made a simple box on a plane and one light.  
When i add the shadow, it’s not good.

See it here :  
[https://playground.babylonjs.com/#SU7C7U](https://playground.babylonjs.com/#SU7C7U)

I don’t know why and how i can do. I tried every shadowType from [Shadows - Babylon.js Documentation](https://doc.babylonjs.com/babylon101/shadows)

Thank you for your help

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 2, 2019, 1:28pm UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/2 "2019-10-02T13:28:38Z")

</div>

You have a lot of parameters to tweak shadows to your own needs: [https://playground.babylonjs.com/#SU7C7U#5](https://playground.babylonjs.com/#SU7C7U#5)

Basically here I reduce the depth visible by the light to gain precision. I also transform a cubeMap (default for point shadows) to a 2d map by forcing a direction on the light. Finally I tweak the bias parameter to ensure it is adapted to our use case.

---

<div class="post-metadata">

**Author:** ![thomas\_e](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thomas_e/32/4760_2.png) [@thomas\_e](https://forum.babylonjs.com/u/thomas_e)\
**Post date:** [October 2, 2019, 1:35pm UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/3 "2019-10-02T13:35:36Z")

</div>

Oh ok thanks a lot!

So i always need a direction for a pointlight (when i want shadows)?

And if i move around my light ? i need to animate the direction too i imagine ?  
It’s look pretty complex to use but ok

Thank you for your response

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 2, 2019, 1:36pm UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/4 "2019-10-02T13:36:13Z")

</div>

You do not need to but it is way more efficient 🙂

---

<div class="post-metadata">

**Author:** ![thomas\_e](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thomas_e/32/4760_2.png) [@thomas\_e](https://forum.babylonjs.com/u/thomas_e)\
**Post date:** [October 2, 2019, 1:42pm UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/5 "2019-10-02T13:42:55Z")

</div>

I have an other problem now xD

I have imported a 3D object (gltf) but it’s render all black and can’t render the shadow when i try to.  
I do the same stuff as my cube…

How to get a good shadow from a imported object ?

My reference is too have something like this : [Bakkie - 3D model by BrandonDiehl (@BrandonDiehl) - Sketchfab](https://sketchfab.com/3d-models/bakkie-2d32c6f37a554607b5f553913f2b5831)

---

<div class="post-metadata">

**Author:** ![thomas\_e](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thomas_e/32/4760_2.png) [@thomas\_e](https://forum.babylonjs.com/u/thomas_e)\
**Post date:** [October 2, 2019, 2:00pm UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/6 "2019-10-02T14:00:38Z")

</div>

I have this now : [https://playground.babylonjs.com/#SU7C7U#7](https://playground.babylonjs.com/#SU7C7U#7)

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 2, 2019, 2:08pm UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/7 "2019-10-02T14:08:08Z")

</div>

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/6/60b800c0dae194836c6b553c1af794bd55e0f98e.png)

Looks like we can not access the asset.

---

<div class="post-metadata">

**Author:** ![thomas\_e](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thomas_e/32/4760_2.png) [@thomas\_e](https://forum.babylonjs.com/u/thomas_e)\
**Post date:** [October 2, 2019, 2:09pm UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/8 "2019-10-02T14:09:14Z")

</div>

Ok! i found now!

[https://playground.babylonjs.com/#SU7C7U#8](https://playground.babylonjs.com/#SU7C7U#8)

I change all my order, i understand now how to do it and it’s more clean like that.

Thank you sebavan 🙂

(yes the 3d object is in local)

---

<div class="post-metadata">

**Author:** ![thomas\_e](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thomas_e/32/4760_2.png) [@thomas\_e](https://forum.babylonjs.com/u/thomas_e)\
**Post date:** [October 2, 2019, 4:10pm UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/9 "2019-10-02T16:10:08Z")

</div>

Sorry to re-open this tread but i still have the problem with my imported object, i have the shadow but the material is all black when i just have the pointlight. It’s work when adding a HemisphericLight but it’s ugly.

[https://playground.babylonjs.com/#SU7C7U#9](https://playground.babylonjs.com/#SU7C7U#9)

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 2, 2019, 6:11pm UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/10 "2019-10-02T18:11:25Z")

</div>

you need an envirionment texture for your pbr materials to work: [https://playground.babylonjs.com/#SU7C7U#11](https://playground.babylonjs.com/#SU7C7U#11)

---

<div class="post-metadata">

**Author:** ![thomas\_e](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thomas_e/32/4760_2.png) [@thomas\_e](https://forum.babylonjs.com/u/thomas_e)\
**Post date:** [October 3, 2019, 8:22am UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/11 "2019-10-03T08:22:00Z")

</div>

Thanks, but why my imported model is not affect by my light ? (like my cube)

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 3, 2019, 8:35am UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/12 "2019-10-03T08:35:43Z")

</div>

Because it uses a standardMaterial which is no subject to environment lighting whereas the PbrMaterial is subject to it. Finally the intensity falloff is faster for gltf falloff than standard so the light point does not affect it much

---

<div class="post-metadata">

**Author:** ![thomas\_e](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thomas_e/32/4760_2.png) [@thomas\_e](https://forum.babylonjs.com/u/thomas_e)\
**Post date:** [October 3, 2019, 8:58am UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/13 "2019-10-03T08:58:33Z")

</div>

Hmmm ok… thank you

I do not find it very easy to use. We can never have a 3D object with the same light as a cube or a sphere finally

---

<div class="post-metadata">

**Author:** ![thomas\_e](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thomas_e/32/4760_2.png) [@thomas\_e](https://forum.babylonjs.com/u/thomas_e)\
**Post date:** [October 3, 2019, 9:52am UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/14 "2019-10-03T09:52:01Z")

</div>

When i use a PBRtexture for the cube it show an error :

_Cannot read property ‘environmentBRDFTexture’ of undefined_

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 3, 2019, 11:21am UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/15 "2019-10-03T11:21:56Z")

</div>

Do you have a repro on the playground ?

Also it is not that hard as you can simulate the standard falloff in pbr materials and /or also use pbr materials for cube or sphere. It is your choice to pick the material type you need depending on the use case and art direction you want.

---

<div class="post-metadata">

**Author:** ![thomas\_e](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thomas_e/32/4760_2.png) [@thomas\_e](https://forum.babylonjs.com/u/thomas_e)\
**Post date:** [October 3, 2019, 12:15pm UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/16 "2019-10-03T12:15:40Z")

</div>

I try to apply PBRmaterial to the cube but it’s show the same error

[https://playground.babylonjs.com/#SU7C7U#13](https://playground.babylonjs.com/#SU7C7U#13)

---

<div class="post-metadata">

**Author:** ![thomas\_e](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/thomas_e/32/4760_2.png) [@thomas\_e](https://forum.babylonjs.com/u/thomas_e)\
**Post date:** [October 3, 2019, 12:25pm UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/17 "2019-10-03T12:25:45Z")

</div>

and also i try to have the same orange from my StandardMaterial to the GTLF 3D object but when i change to the same rgb color from the orange cube to the gtlf with texteditor in “baseColorFactor” with same values is show a brown color instead ( i tried with different metallicFactor and roughnessFactor).

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 3, 2019, 2:32pm UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/18 "2019-10-03T14:32:00Z")

</div>

Your scene is undefined as not global or passed in the pbr constructor:  
[https://playground.babylonjs.com/#SU7C7U#15](https://playground.babylonjs.com/#SU7C7U#15)

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 3, 2019, 2:34pm UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/19 "2019-10-03T14:34:56Z")

</div>

About the color it is because pbr and standard have different reaction to lights which is the main point of having two different type of equations. The pbr is meant to be closer from what nature does hence the need of an environment. The setup is therefore different and trying to map one and the other is not as simple as placing the difffuse color in the albedo one.

Ping @PatrickRyan and @bghgary as I know they worked a lot on those conversion.

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [October 3, 2019, 4:28pm UTC](https://forum.babylonjs.com/t/shadow-and-light-problem/6068/20 "2019-10-03T16:28:11Z")

</div>

The diffuseColor used in StandardMaterial is also in a different color space (gamma) than the albedoColor of PBRMaterial (baseColorFactor in glTF) which is in linear color space.
