How to change the shadows generated from a dissolve?

in threejs i was able to change the depthmaterial on each mesh to discard the same way the dissolve runs and i would get the shadow to reflect what was going on the mesh.

https://www.babylonjs-playground.com/#I669IL

how can i get the shadows to dissolve in babylon since it doesn’t have the depthmaterial that threejs has?

1 Like

what does the depth material do?

Maybe this helps?
https://www.babylonjs-playground.com/#CJWDJR#1

You need to provide your own shadow material to the shadow generator to account for the specificities of your custom material:

https://www.babylonjs-playground.com/#I669IL#6

I have simply copied the standard shadow map vertex and fragment shaders used by the shadow generator and added the check to discard the fragment based on the noise value.

It’s a bit complicated, maybe we should think of a better way to handle this…

Note that I have disabled back face culling on the sphere, as it’s probably what you want for the shadow to be correct.

You can get some more info here: Mesh with custom shader material does not cast shadow

1 Like

yes thats what i am going for. :smiley:
but it looks like its doing it on the entire scene instead of each observable.
i added a box
https://www.babylonjs-playground.com/#I669IL#4
i updated the effect values per object and now its doing what i expect. it was holding onto the effect values per observable.
https://www.babylonjs-playground.com/#I669IL#5
and yeah, id agree this is a very weird way of doing it.

@Evgeni_Popov now the problem i see is if i want different shader effects for different shadows.
would i just have this giant shadow shader that i need to reset values on every observable. it doesnt look like i can quite make this dynamic per shadow very easily, i tried updating the shadowGenerator.customShaderOptions after each observable but it didnt do anything.:thinking:

1 Like

Yes it’s the problem, as I said I think we need to think about this and see if we can come up with a better solution…

As an aside, how would you have used the depth material in threejs to achieve this effect? I looked at the doc of this class and could not see how it could make it worked.

[…] Ok, it is not through the MeshDepthMaterial class (what I was looking at) but by setting the customDepthMaterial / customDistanceMaterial properties it seems.

1 Like

yeah sorry, its the customDepthMaterial that i was using.
thanks for your help again! and thanks for looking into it!

We are checking with @Evgeni_Popov how we could make this one happen as I love the idea of being also able to use it with Node Material :wink:

3 Likes

Agree!

1 Like

That’s a lot easier now with the new ShadowDepthWrapper (documentation coming soon):

https://www.babylonjs-playground.com/#I669IL#7

2 Likes

I love what you did!

1 Like

Sorry for the late response! We are about ready to deploy our project so i was finally able to test this out.

I love the new implementation, its so much easier!
But…
I am seeing significantly slower speeds when initializing objects using it compared to the work around.
I am also seeing the shadow generated flicker when resizing the screen and running engine.resize()
I will see if i can get tests in a playground to validate these issues when i get a chance…

again thank you! cannot wait to start using 4.2!