Masking Terrain as per meshes

So I have a road mesh that I spawn at runtime on the terrain. Sometimes the mesh goes inside the terrain. Is there a way to mask out the terrain such that the whole mesh is visible? Tried Cartographic Polygon tool, doesn’t look nice.

I had my own implmentation of Tile Streaming earlier and there I was using Virtual Textures. I could simply draw the road mesh in Virtual Texture and then use this Runtime VT Sample in the material of the terrain to mask out using the opacity in the result node of material.

From other posts I came to know that Cesium is using a StaticMeshComponent for each tile. I wonder if I could possibly do something similar with the tileset? Where is the material of that tile actually set?

I’m not sure, maybe! The full source code for Cesium for Unreal is available on GitHub, so please take a look and let us know how it goes:

Cesium for Unreal has a “raster overlay” system, which allows truly massive textures (petabytes!) to be draped over a terrain or 3D Tiles surface in a tiled manner and used as input to an Unreal Material. We support a few texture sources out of the box, such as Cesium ion, Bing Maps, TMS, and WMS. But you can add custom ones by deriving a new class from CesiumRasterOverlay.

The default materials are found here:

They’re material instances built on materials layers, so they’re designed to be extended and customized.

Let us know how you go.

Hi Kevin, thanks for the detailed reply. I was trying out using the post process to make this happen.

Something like this. So the cube you see is below the plane but we can still see it.

But while using the cesium terrain I can’t replicate the same effect.

It looks like this, all the setup is the same.

This is the material.

And the settings to write into custom depth pass are below. This is the cube rendering settings.
custom depth rendering settings

Can you please help me understand how I can achieve the same effect using the Cesium terrain?

I’m afraid I don’t know. The Cesium tiles are just static meshes in the end, so I’m not aware of anything unusual they might be doing that would affect this. But also, I’ve not done anything myself with custom depth or post processing, so I’m not familiar with the gotchas that might exist there.

One simple thing to try is to switch the Cesium3DTileset material to be the same one that is used in your test cube, and see if that fixes it. If so, it’ll likely be something in the default Cesium material causing a problem. If not, I guess it would be something in the static mesh construction.