Lighting not working as expected

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:


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

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.

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 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 :sunglasses:

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

1 Like

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

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. :slight_smile:

2 Likes

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

Something like this?

3 Likes

Yeah his problem is just shared normals.

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

Thank you so much looks exactly how i wanted it to look now :pray:. 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 :sunglasses:

2 Likes

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.

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

1 Like

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