Height offset between land and water
Hello,
I'm going to explain in detail my problem. Sorry in advance for the amount of information provided in this issue.
What I want
As I said in the title, I would like to raise the height of the lands and leave the water at level 0. Eventually I would like animate the water with a low poly asset.
Here is an example of the result I'm trying to create:

I haven't found any tutorial or issue about this.
What I tried
Raise everything but the water
- In the
Featurecomponent I gave the same minimum height for all the layers available except the water one but some parts of the map remained at the level of water. There is actually no way to select "everything that is not water" and raise it up.
Lower the level of the water
- In the
Featurecomponent I attached a script to the water feature to lower itsyposition and so create an offset between the water and the lands. But the problem is that the map terrain is always visible so the water feature I created appeared underneath the map terrain. Here is a picture as an example:

Changing the map style
- On Mapbox Studio I've set my water color to purple (a color that I won't be using anywhere else on my map). And tried the solution described in the issue #596. The point here was to make the color in question transparent with Unity but my whole map ended up transparent instead.
Create a custom tileset
- I created different custom tilesets on Mapbox Studio from shapefiles I downloaded online containing the datasets I needed in order to retrieve them in Unity and lift their heights up. The problem was that none of them followed the coast line precisely enough. Here is a picture:
I tried a couple of other solutions but never got the result I wanted.
Thank you for your time and attention.
Hey @cha-hin,
I'm afraid there isn't an easy way to do this, mainly because there isn't a land layer which is exact opposite of water. Using elevation isn't reliable either as it's not that accurate everywhere.
I was able to do it in hexagon shot you posted above because it doesn't render the tile and I generated land where water is not, using hexes.
You can cut off water from tile rect and use that as land depending on your application but mesh modification/cutting will cost in performance.
Another idea might be a shader trick to make it look a few meters below the actual polygon surface I guess.
But all these ideas will probably have issues on natural shorelines right?
Thank you for your answer @brnkhy,
I will take your propositions into consideration and will see what I can do about that.
I actually had another question about water which is do you know how I can apply a low poly texture and animation on it? I tried a couple of different modifiers but couldn't get any satisfying result.
@cha-hin I haven't worked with water too much really. That shot above is using one huge water object since hexes are above it anyway. A shader manipulating vertex positions is the best shot I guess but I never tried it either.
@brnkhy If I manipulate the vertex positions with a shader, I’m scared about the visual conflict that might happen between the terrain background and the actual layer that’s being animated with the shader.
Conflict example (water):

As I said before I can't get rid of this terrain background because it covers the whole map and if I try to remove it I will end up with "holes" in my map. So whenever the water layer has a y position of 0, conflicts will be encountered between the water layer and the terrain background.
For example if I just want to change the color of the water and avoid the conflicts, the best I can end up with is this:

Indeed, I had to raise the height of the water layer up so that its roof is at a y position of 1. It is not what I wished to have, but that's okay for now.
What I actually would love to do is to add a sort of animated water texture that wouldn't change any vertex position so that I can avoid conflicts. If this is not possible, I will just go with a seamless water pattern.
@cha-hin I have a prototype mostly working based on the depth-buffer method described here. Steps:
- Create two water features and remember which you want to designate the upper (invisible) layer and which is the lower layer.
- Set the height of the upper layer to 1 and the height of the lower layer to -1.
- Create a shader
DepthMask.shaderwith the following code and set it to be the shader for the upper layer:
Shader "Masked/Mask" {
SubShader {
Tags {"Queue" = "Geometry+10" }
ColorMask 0
ZWrite On
Pass {}
}
}
- Create a MonoBehaviorModifier with the following script and attach it to both layers:
using UnityEngine;
[AddComponentMenu("Rendering/SetRenderQueue")]
public class SetRenderQueueLower : MonoBehaviour {
[SerializeField] protected int[] m_queues = new int[] {1999};
protected void Awake() {
Material[] materials = GetComponent<Renderer>().materials;
for (int i = 0; i < materials.Length && i < m_queues.Length; ++i) {
materials[i].renderQueue = m_queues[i];
}
}
}
You should see cutouts in the map which show your water beneath!

Note that depending on your shaders, you may need to tweak the value inside the script. Basically the upper layer should have a lower value than the image and the lower layer should have an even lower value than that. Speaking of-- @brnkhy Is there a way to pass variables to MonoBehaviorModifier scripts?
Some caveats:
- I noticed a little bit of flashing when moving around; I'm not sure how visible it really is though as I was just flying around in the Editor.
- Not sure how performant this is.
- It rendered buildings in the middle of water just fine, not sure how it plays with multiple overlapping features.
- There may be visible gaps between the lower layer and the image tile; the height can probably be tweaked to hide this though.
In summary, this seems to work but I'm not a Unity dev so if you figure out a good solution please share!
Hey @heath3n,
First, I would like to thank you for your answer.
I tried your solution and followed each step, but I don't see a visual difference on my map, did I do anything wrong?
I created two water features with the polygon Primitive Type, one has a height of -1 and the other a height of 1, then I attached the script you provided to both my layers.
By the way I'm using the standard shaders for my map.
@cha-hin My bad, I forgot a step. I've updated my comment; please try again. Also try using the "Color" option in the Mapbox feature instead of a shader at first, just to verify it works. I noticed when I switched to my water shader that it changed the render queue value so I had to tweak the value in the script.
If you're still having trouble I can upload a sample project when I'm on my lunch break.
@heath3n
So I tried your solution, and it finally worked. Thanks a lot!
I still have a couple of questions about the result please, as you can see here the side of each tile is also taking effect and is hiding parts of the water that shouldn't be hidden. I tried to set the Geometry type to Roof only on the upper water layer, but it didn't work, is there any way to avoid this?

By the way, on your screenshot, it looks like you have some sort of animated pattern, I'm curious to know how you managed to do this please.
Thank you.
@cha-hin I'm not really sure what's going on; it may just be that none of my water spanned multiple tiles so I never noticed this. I've since overwritten my test project while trying other things so can't be sure but I'm going to attempt to integrate it with my real project this weekend so will keep you posted.
As for the water shader, it's just some simple Voronoi noise with a time-variable offset. I'm using Amplify Shader Editor but the built-in Shader Graph has a node for it as well. The only reason I didn't use that is because when I tried to convert my project to LWRP/URP a few months ago I had some trouble.
@heath3n Alright, I will also try what I can by my side and keep you informed if I have any solution, thanks.
Hi @cha-hin, this looks great! Do you have an advice or any code snippet how you managed to have the streets extruded downwards into the land layer and how you managed to have the clean roads and extrusion at junctions/crossings? I'm trying to render roads cut into the land layer but can't manage to get it properly especially at junctions/crossings. Thank you!