- Home /
Selectively drawing textures on a mesh to represent damage using a shader
I am working on a 2D tile based spaceship building game and I need to find the best way to model damage to the tiles. The ships are a basic procedural 3D mesh made up of quads of different basic shapes (slope, corner, flat, etc..) to allow semi-realistic lighting and shadows with the standard shader. It is textured using a single texture tile atlas material with all the different diffuse, normal, emissive, etc. maps. The tile graphic is picked by changing the vertices UV coordinates depending on tile type.
Now I need a way to simply model damage without having to draw a bunch of different damaged tiles for each bit of damage it can receive. I would like to use just one damaged tile texture and blend the two based on the health of the tile or have some kind of mask that would render one part of the texture transparent and display the damaged tile underneath. Here is a sample from my texture atlas for what I am trying to achieve:
The undamaged and damaged hull tiles: The effect I am trying to achieve:
Is this possible using a shader? Before I spend a significant amount of time learning CG I want to see if my line of thinking is correct. I would like to have a material with a custom modified standard shader that has a slot for a damage texture and damage normal map as well as a black and white damage mask/map texture that would tell the shader whether to draw the undamaged tile pixel, damaged tile pixel, or a transparent pixel. The mesh would store which damage mask uv to use in uv2 or uv3 or whichever uv set is available. This way the damage script in my game can select a damage graphic by just changing the uv2 for the damaged tile. Is this something that can be done in a unity shader or is they a better way of doing this?
Yep, sounds like a custom shader is the way to go. I'm not aware of any builtin features that would let you accomplish this effect on a 3d mesh, though it may be worth searching the web for existing solutions first.
Your answer
![](https://koobas.hobune.stream/wayback/20220612092734im_/https://answers.unity.com/themes/thub/images/avi.jpg)