Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

THREE.InstancedBufferGeometry and shadows

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.

like image 732
Arnaldof Avatar asked May 27 '26 10:05

Arnaldof


1 Answers

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,
        ....
    });
like image 83
Arnaldof Avatar answered May 30 '26 10:05

Arnaldof



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!