I’m trying to cast shadows for instance geometry, using a custom depth material. I expected the cubes on the right in this example to produce shadows on the white plane below (and hopefully on each other), but they don’t.
Can someone take pity on me and show me what I’m missing? Thanks in advance!
Oh, if I add “depthPacking = RGBADepthPacking” to the InstancesDepthMaterial, I do get shadows … but the shadows are identical per instance.
MeshDepthMaterial like all other built-in materials does not support instanced rendering. There is an example that shows how you can modify
MeshLambertMaterial so it can be used with
InstancedBufferGeometry plus shadow support. I hope you can use this code for your own project.
This could also be of some use:
Thank you for your reply and for the references. I have read through them both in the last few days.
I made some progress on this issue last night. I was applying instancing in the vertex shader too late here. I should have been overriding <begin_vertex> and updating the transformed vec3 earlier, so that the instance position is also reflected in worldPosition. That was preventing the shadow.
I love the examples as a show-case, but as documentation or implementation exemplars, they aren’t great. You have to sift out the extraneous ‘we did this to make it pretty’ details and of course, extending shaders is not Three’s strong suit. Anyway, I’ll try to share some more tutorial-friendly examples once I’ve ironed out my shadow issue.