I have been trying all day today to get sub meshes to be transparent using a multi material.
This is the Playground I have been messing with https://playground.babylonjs.com/#6H9YT3#7.
It’s quite complicated, but essentially
- My game is played on the surface of a planet.
- The map is projected onto the surface of a sphere (the planet).
- The map is divided into square tiles.
- To begin with the player can only see terrain nearby, they have to explore to see the rest of the map.
- There is a resource scanner that lets the player survey for hidden resources.
The way I implemented this was:
- Build two ground meshes that are very close together, one for the terrain and the other to display the state of that map tile. I called these meshes ‘terrain’ and ‘utility’ in the PG.
- Both meshes have one sub-mesh per map tile.
- Both meshes have a multi material assigned so that the map tiles can be assigned any of the possible materials through the sub mesh material index.
- Map tiles on the terrain mesh are initially set to the ‘unexplored’ material except for a small area near to the player. You can click on the ‘Explore’ button to set all of the map tiles into an explored state, in which case the sub meshes will be flipped to the relevant material index for the type of terrain.
- Map tiles on the utility mesh are used to overlay a map tile status. Map tiles that are out of the players field of view should have a ‘fog’ material that greys out the map tile. Tiles that are within the field of view should not be obscured, i.e. the utility layer should be fully transparent.
The problem I need help with is making the utility layer map tiles fully or partially transparent. I have tried many things, including a diffuse texture with transparent pixels and setting the useAlphaFromDiffuseTexture property to true, disposing of the sub meshes and recreating them when necessary etc.
At this point I have run out of ideas. Is it actually possible to make a sub-mesh transparent or translucent whilst the other sub-meshes of the same mesh are opaque?
Sorry for the long explanation, but the PG is quite complicated.