# Lighting not working as expected

**URL:** <https://forum.babylonjs.com/t/lighting-not-working-as-expected/33423>\
**Category:** Questions\
**Tags:** lighting, material\
**Created:** [August 27, 2022, 9:38am UTC](https://forum.babylonjs.com/t/lighting-not-working-as-expected/33423 "2022-08-27T09:38:20Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nico1](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nico1/32/26576_2.png) [@Nico1](https://forum.babylonjs.com/u/Nico1)\
**Post date:** [August 27, 2022, 9:38am UTC](https://forum.babylonjs.com/t/lighting-not-working-as-expected/33423/1 "2022-08-27T09:38:20Z")

</div>

I recently started learning BabylonJS and i wanted to create a Lego Building Software for myself. Everything works fine but i can’t get the lighting down.

It currently looks like this:

 ![Screenshot 2022-08-27 113453](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/2/7/273b31f325e1d4e5f529c9b1838db65271934f1e.png)  
It kind of resets the light for the second brick on top of the lower one. But i would like to have a global lighting, i dont know how to call it, like this:  
 ![Screenshot 2022-08-27 113607](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/4/c4bc947abe473ae51dcd350a1488e9289de59f23.png)  
I search for hours now to find something relating to this but i couldn’t find anything about it.

I currently have one hemispheric light and one directional light set up. The Bricks have a standard material. It just frustrates me because everything else works but i cant seem to get the lighting down

The current lighting i have: [https://playground.babylonjs.com/#WKR5BH#2](https://playground.babylonjs.com/#WKR5BH#2)

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [August 27, 2022, 10:05am UTC](https://forum.babylonjs.com/t/lighting-not-working-as-expected/33423/2 "2022-08-27T10:05:23Z")

</div>

Hi and welcome to the Forum,  
Lights can be complex to work. Among the different type of lights, the materials, the shadowing, the environment… there are loads of parameters that can affect how a scene is lit.  
Best for us to help you would be to have a PG example. If you haven’t learned about the playground yet, take a minute to check out [this part of the doc](https://doc.babylonjs.com/toolsAndResources/tools/playground).

Else, understand that light only adds to light. You are using two lights in your scene and one is an hemi. Lowering the light can be achieved by positioning the hemi much higher above the ground AND reducing its ‘intensity’ (to 0.5 or 0.3 for a start). Same with the directional light. The closer to the object, the stronger the light. Finally to get a more ‘global’ as you say light effect, a common technique is to use a 3 points lights (3 lights in a triangle above the scene each with an intensity of around 1/3 of the global lighting intensity you want). You should also check at all the [different types of light you can create](https://doc.babylonjs.com/divingDeeper/lights) and exercise yourself in the playground, playing with there parameters and position in the scene.  
Hope this helps for a start and you are welcome to return here anytime.  
Meanwhile, have a great day 🕶

Edit: A simple hemi light will probably achieve the result you shared in your screenshot

> **[Babylon.js Playground](https://playground.babylonjs.com/#9201YU)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![Nico1](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nico1/32/26576_2.png) [@Nico1](https://forum.babylonjs.com/u/Nico1)\
**Post date:** [August 27, 2022, 10:33am UTC](https://forum.babylonjs.com/t/lighting-not-working-as-expected/33423/3 "2022-08-27T10:33:40Z")

</div>

Thx for the advice i’ve updated my post with the playground. I tried the hemispheric light you suggested. In your playground it looks like how i want it but with the models it looks like this again:  
 ![Screenshot 2022-08-27 123304](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/8/e/8eb2b2b6d78a111cd61d78ebb4c11c97ede9137e.png)

---

<div class="post-metadata">

**Author:** ![Blake](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blake/32/21509_2.png) [@Blake](https://forum.babylonjs.com/u/Blake)\
**Post date:** [August 27, 2022, 11:35pm UTC](https://forum.babylonjs.com/t/lighting-not-working-as-expected/33423/4 "2022-08-27T23:35:24Z")

</div>

It looks like maybe you’ve merged the vertices of neighboring faces, causing each normal to be the average of the merged vertices. Can you try re-creating the mesh without merging vertices? In general each face should have unique vertices for the scene lighting to work properly, rather than using the same vertex for multiple faces. 🙂

 ![bad normals](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/0/b/0be0589d10a41e061e6d637fc08c43723e7c4f99.jpeg)

---

<div class="post-metadata">

**Author:** ![kvasss](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/kvasss/32/3774_2.png) [@kvasss](https://forum.babylonjs.com/u/kvasss)\
**Post date:** [August 28, 2022, 2:37am UTC](https://forum.babylonjs.com/t/lighting-not-working-as-expected/33423/6 "2022-08-28T02:37:16Z")

</div>

Hi it’s smoothing group problems.  
what application do you use to create the geometry?

> **[Smoothing group](https://en.m.wikipedia.org/wiki/Smoothing_group)**
>
> In 3D computer graphics, a smoothing group is a group of polygons in a polygon mesh which should appear to form a smooth surface. Smoothing groups are useful for describing shapes where some polygons are connected smoothly to their neighbors, and some are not. For example, in a mesh representing a cylinder, all of the polygons are smoothly connected except along the edges of the end caps. One could make a smoothing group containing all of the polygons in one end cap, another containing the By...

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [August 28, 2022, 3:27am UTC](https://forum.babylonjs.com/t/lighting-not-working-as-expected/33423/7 "2022-08-28T03:27:30Z")

</div>

> **[Babylon.js Playground](https://playground.babylonjs.com/#WKR5BH%235)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Something like this?

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [August 28, 2022, 4:41am UTC](https://forum.babylonjs.com/t/lighting-not-working-as-expected/33423/9 "2022-08-28T04:41:23Z")

</div>

Yeah his problem is just shared normals.

---

<div class="post-metadata">

**Author:** ![Nico1](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nico1/32/26576_2.png) [@Nico1](https://forum.babylonjs.com/u/Nico1)\
**Post date:** [August 28, 2022, 8:59am UTC](https://forum.babylonjs.com/t/lighting-not-working-as-expected/33423/10 "2022-08-28T08:59:51Z")

</div>

I didn’t create the model so i didn’t know about that, but i will try that looks promising.

---

<div class="post-metadata">

**Author:** ![Nico1](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nico1/32/26576_2.png) [@Nico1](https://forum.babylonjs.com/u/Nico1)\
**Post date:** [August 28, 2022, 9:06am UTC](https://forum.babylonjs.com/t/lighting-not-working-as-expected/33423/11 "2022-08-28T09:06:27Z")

</div>

Thank you so much looks exactly how i wanted it to look now 🙏. Is it smarter to fix the models or can i just use your function?

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [August 28, 2022, 1:11pm UTC](https://forum.babylonjs.com/t/lighting-not-working-as-expected/33423/12 "2022-08-28T13:11:41Z")

</div>

> [@Nico1](#):
>
> Is it smarter to fix the models or can i just use your function?

I cannot answer for @Pryme8 but in general the code that is shared here is sure open for you to use.  
And then, to answer your question, I believe it is always better to fix the source rather than applying tricks or further processing to it (personal opinion only).  
Have a great day and glad to see you found a solution for it 🕶

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [August 28, 2022, 2:16pm UTC](https://forum.babylonjs.com/t/lighting-not-working-as-expected/33423/13 "2022-08-28T14:16:59Z")

</div>

Its always best to have your assets come in prepped, but there is nothing stopping you from forcing the buffers to be what you want.

---

<div class="post-metadata">

**Author:** ![kvasss](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/kvasss/32/3774_2.png) [@kvasss](https://forum.babylonjs.com/u/kvasss)\
**Post date:** [August 28, 2022, 4:26pm UTC](https://forum.babylonjs.com/t/lighting-not-working-as-expected/33423/14 "2022-08-28T16:26:09Z")

</div>

There more realistic solution for your problem. Fixed sorce meshes with right smoothing groups in something like blender. [GitHub - kvasss/Smoothing-groups](https://github.com/kvasss/Smoothing-groups) [https://playground.babylonjs.com/#WKR5BH#6](https://playground.babylonjs.com/#WKR5BH#6)

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [August 30, 2022, 3:03am UTC](https://forum.babylonjs.com/t/lighting-not-working-as-expected/33423/15 "2022-08-30T03:03:26Z")

</div>

This is what we were saying about making sure they come in correctly. Thank you for posting an example!
