THREE.InstancedBufferGeometry and shadows

耗尽温柔 提交于 2019-12-10 21:55:59

问题


I'm playing with instances and is awesome.
Now I'm trying to make every instance cast shadows but no luck. I made a clone of Lambert material adding the instance handling for position, scale, etc and is working, but this is casting only one shadow: the one from the original geometry at position (0,0,0) (even if no instance is at that position).
Can someone point me where to look for make it work or is this a limitation of instances or material?
Thanks.


回答1:


I fixed this with info from this post: http://blog.edankwan.com/post/three-js-advanced-tips-shadow

EDIT:

I made a copy of THREE.ShaderLib.depthRGBA.vertexShader and added all attributes (translation, scale, rotation) and code that I have in the material that actually draws the instances (use THREE.ShaderChunk). THREE.ShaderLib.depthRGBA.fragmentShader stays the same.

Then I created a new THREE.ShaderMaterial with the new VS and FS created in previous step:

mesh.customDepthMaterial = new THREE.ShaderMaterial({
        vertexShader: <my DepthRGBA vertex shader here>,
        fragmentShader: THREE.ShaderLib.depthRGBA.fragmentShader,
        ....
    });


来源:https://stackoverflow.com/questions/34205069/three-instancedbuffergeometry-and-shadows

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