Search code examples
c#unity-game-engineshadermasking

Giving a Material two different colors using a png Mask


I am trying the put a logo onto my object. I have a png image I want to use as a mask and two colors, one for the logo and one for the background.

So far I have managed to create two Materials for the same submesh, with one being the transparent image and the other being the background: image image

The color of the logo isn't changable though, as it is the image that is being displayed. Is there a way to use the png as a mask, but change the color that is used? Will I need to write a shader, or have I missed something in the material inspector?

Thanks in advance :)


Solution

  • Using two materials for the same submesh is a terrible idea, it has very low performance, it is not like having two passes in the same shader. What you can do is creating a new shader that receives two textures:

    • One texture will have only 0 in the space for the logo and white in the other places
    • The other texture will be white in the logo and have 0 in the other pixels

    Then you will have two color properties:

    • One will multiply with your "background" texture
    • The other will multiply with your "Logo" texture

    Then Add both textures and assign them to the Albedo node.

    You can do the same using a blend mask:

    • You will have a mask Map (basically it`s the Alpha channel) and put 0 in all places but where the logo pixels are.
    • Also you will need 2 colors properties.

    Then use the blend node in the ShaderGraph to merge both textures. Using the Blend mask you don't need the other two textures, only the mask and you can create maps in the ShaderGraph with the color properties.