Three.js object self shadow itself depending on geometry

有些话、适合烂在心里 提交于 2019-12-01 20:29:47

ie. Actually it is a very simple setup. The THREE.Object3D has two attributes castShadow and receiveShadow You can achieve the effect you are looking for (ie. self-shadowing) by setting both to true

actually you need:

renderer.shadowMapEnabled = true;
light.castShadow = true;
object.castShadow = true;
object.receiveShadow = true;

i know its a little counter-intuitive that both the light and the mesh have the same attribute "castShadow", but that's how it works.

also remember to check the near, far, and size of the shadow camera of your light if the shadow doesn't appear or appears incorrectly.

here is an example i made: http://shahar.thenachts.com/threejs/examples/selfShadow.html

it takes some time to load the model (the model is the floor and walls) and it's textures, so be patient.

to see the code, right click anywhere and choose "inspect element".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!