Shadows on InstancedBufferGeometry mesh

I’m trying to make shadows work on InstancedBufferGeometry mesh. I created the mesh and applied extended standard material to it. I modified vertex shader to offset each instance of geometry by random vector. Unfortunately it did not work as I was expecting. Mesh receives same shadow for all geometry instances. Later I learned that I need to apply customDepthMaterial for shadows to work properly. So I crated new depth material that applies same vertex offsets as standard material. Sadly made no difference, all geometry instaces still receive same shadow.

Here’s my code:
You will notice that all grass blades darkens at the same time as shadow passes position of original geometry (0, 0, 0).

Relevant functions are:
setupGrass - creates InstancedBufferGeometry mesh
overrideVertexPosition - vertex shader modifications

Could anyone tell me what I’m missing for shadows to work? Thank you :slight_smile:

Nevermind, I found solution. Found topic where same issue was discussed MeshDepthMaterial & InstancedBufferGeometry - #5 by alecmce

I was too quick to create new topic. Sorry.

1 Like