Shadow and light problem

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

I don’t know why and how i can do. I tried every shadowType from Shadows - Babylon.js Documentation

Thank you for your help

You have a lot of parameters to tweak shadows to your own needs: 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.

1 Like

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

You do not need to but it is way more efficient :slight_smile:

1 Like

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

I have this now : https://playground.babylonjs.com/#SU7C7U#7

Looks like we can not access the asset.

Ok! i found now!

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

(yes the 3d object is in local)

1 Like

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

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

1 Like

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

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

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

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

Cannot read property ‘environmentBRDFTexture’ of undefined

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.

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

https://playground.babylonjs.com/#SU7C7U#13

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

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

1 Like

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.

1 Like

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.

3 Likes