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