Hi,
I would like to use a mask to cut holes in the Unity terrain, is it even possible and if yes, how to do it ?
The idea is to generate this kind of texture (image 1) with a script, and then to use this texture in the terrain shader in order to discard the pixels where there is roads (yellow and red lines).
This way I would be able to hide the terrain under my roads (just like image 2)
Roads are procedurally generated so the mask should be updated each time the road network is modified.
Because I want the road to be slightly lower than the terrain, and the sidewalk to be at the exact same level as the terrain (just like here in Cities Skylines). Also this would prevent the terrain from poking through roads in some cases when the terrain is not flat.
I already saw this video. I think I did the same thing as he did in the video but it did not work in my case. Idk why.
But I managed to generate by script the texture to use as a clipping mask in the terrain shader. Now I need to use this texture in the terrain shader in order to hide the terrain where there is red pixels. So I made this function in my terrain script :
My best guess is that you didn’t set the Tags correctly, but I could be wrong since I can’t see the whole script. I don’t know enough about HSLS to help you too much though, I would recommend using Unity’s built in Shader Graph tool to create this, as writing your own shader which is affected by lighting is a headache.
I believe looking through this video you can find all the things you need to make your own shader for this specific thing.
But now there’s still one problem : it seems like there is no texture filtering on the clipping mask so the shape of the hole is jagged :
instead the hole should be like this :