Transparent background surface
Hey guys,
I am trying to set up a multi layered custom map in unity and so far Mapbox is working great. The issue I'm currently running into is this: I need to set the tile texture to have a transparent background. This would make the roads or buildings stand out separate, without the normal filler green or whichever color background. Then I would be able to add my own textures underneath and change them dynamically during gameplay without disturbing the roads.
I am currently working with a flat terrain and no 3d buildings, so it is just the one material that would need to be adjusted. I have attempted to remove the colored background from my custom style on the MapBox style editor, but this only sends the background as white instead of transparent. Is this something that MapBox supports? Or is there a known way to remove the background once it is unity side?
Thanks
Hi @ztdraper,
Just to clarify, please let me know if I am not correct here - you are attempting to define this custom style with a transparent background in Mapbox studio, and then referencing this style in the MapId property of the Image section of AbstractMap?
Hey @greglemonmapbox,
Yes, you are correct. I apologize for not updating my inquiry previously.
My current workaround is a custom shader that removes a specific color from the texture. In this case, I have used a bright red for the background, which is then removed on Unity's end. This solution works pretty well, but there is some bleed over that occurs when other pixels are within a certain threshold of the target color, leading to some holes in roads or other structures.
If there is a preferable option, I would still be interested in hearing about it.
Thank you
Suggested workaround is below. Unfortunately, as far as I know, Mapbox studio does not return the alpha channel of a style, but we can use a Mapbox specific shader that supports color-based transparency as a workaround. This workaround assumes that you are using "TerrainMaterial" as the Base Material in the Terrain section of Abstract Map.
- Change the shader of the TerrainMaterial to "Mapbox/RasterWithTransparency"
- Press the play button.
- Find an area of the map where the color you wish to make transparent is visible.
- With the TerrainMaterial selected in the project window, use the color picker to select the background color you wish to make transparent. This will not change the look of the tile background, but will capture the color. In the "Presets" window at the bottom of the Color window, click on the small box - a pop up tool should say "Add New Preset". See image below for more details.
- Now that the color to be made transparent has been selected and stored as a preset, press stop. With the TerrainMaterial selected, set the "Color" RBG to the preset color you just selected, and the alpha value to zero (0).
- Press play. The map should load, and the color you selected should be transparent.
Saving color as preset:

Map with background color keyed out, revealing background below:

Please let me know if this does not work.
Hello @greglemonmapbox,
I just tried your workaround but as soon as I set the Alpha value to 0 in the TerrainMaterial options my whole map becomes invisible.
Is there any solution to this?
Thank you.