Vertices Displacement DepthMap not updated

Hello Babylonians :slight_smile:

Another challenge for you :wink:

I have a ground that is meant to be the ocean. I create islands procedural. A CustomProceduralTexture is creating heightmaps automatically. These heightmap textures are then applied to planes. With the data from the heightmap the vertices are displaced.

Now I would like to display the depth of the water. It should change its color depending on the depth at this position. That works as you can see in this image with an added sphere.

I assume the water shader works as expected.

If I add the island
this.renderer.getDepthMap().renderList = [generatedTerrain];
the depth value seams to be zero = black.

The island mesh is deeper, it continues below the surface. This is how it looks like without water

And if I lower the island. The distance increases. The values grow bigger.
So for me, it seems the depth data in the system are still based on a flat plane.
Basically, before the vertice displacement kicks in.

Could this be a timing issue?
Should the depth map update itself if a shader is changing the mesh?

I will try to set up a playground. But maybe, for now, you guys/girls have some ideas to point me in the right direction.

Thanks for your help

Hey! That would require a repro in the Playground to help :slight_smile:

@Deltakosh
There you go :slight_smile:
Ok…not the cleanest nicest code. But I hope it shows what I mean.
The sphere is shown correctly. Or at least i assume thats how it should look like.

The “island” on the other hand is not shown. BUT I added it to the renderlist.

https://playground.babylonjs.com/#YY789P#18

Just to be sure, this is not what you wanted?:

renderer.getDepthMap().renderList = [island, sphere];

In the end only “island” matters. The sphere is just there to check if the water shader works.


That’s what I get if I add both to the renderlist.
It looks like the Depth is based on a flat plane.
It does not adjust when the shader changes the vertices.
Do I have to manually update the DepthMap if the island has been rendered?

The problem is that the depth renderer is using its own shader to render the objects in the depth map.

In the case of your island, the mesh is a simple plane and so it is what you get in the depth map: you would need to pass your own (vertex) shader to get the correct result, but the depth renderer does not support that.

I think we should add this possibility: what do you think @Deltakosh and @sebavan?

1 Like

It is a good idea we could add to our todo for sure (maybe @Martin_Schmidli wants to contribute to help?)

Oh cool, I thought I’m doing something completely wrong :wink:
I’m not a prof. developer… so I’m not sure how much I can help.
I guess I need to go through Babylon.js/depthRenderer.ts at master · BabylonJS/Babylon.js · GitHub
and understand how things work.