Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice

Combine texture with texture already combained in alpha layer.

Discussion in 'Shaders' started by Darkness-Seeker, Nov 9, 2016.

  1. Darkness-Seeker

    Darkness-Seeker

    Joined:
    Jun 18, 2016
    Posts:
    11
    Hi

    Looking around the internet, I found this particular shader that I need to change a little to get it to work as I need, and I need a little help.

    Code (CSharp):
    1. Shader "Custom/Map Borders" ////////// Shader renamed
    2. {
    3.     Properties
    4.     {
    5.         _Color("Mask Color", Color) = (1, 1, 1, 1) ////////// _Color property added to this shader
    6.         _MainTex("Base Texture (RGB)", 2D) = "white" {}
    7.     _Mask("Culling Mask", 2D) = "white" {}
    8.     _Cutoff("Alpha cutoff", Range(0,1)) = 0.1
    9.     }
    10.         SubShader
    11.     {
    12.         Tags{ "Queue" = "Transparent" }
    13.         Cull Off ////////// I added this line to have the both sides of my plane mesh visible
    14.         Lighting Off
    15.         ZWrite Off
    16.         Blend SrcAlpha OneMinusSrcAlpha
    17.         AlphaTest GEqual[_Cutoff]
    18.         Pass
    19.     {
    20.         SetTexture[_Mask]{
    21.         constantColor[_Color]
    22.         Combine texture * constant ////////// The alpha component of the _Color property defines the Culling Mask opacity (depending on the distance between the player and the grid)
    23.     }
    24.         SetTexture[_MainTex]{ combine texture, previous }
    25.     }
    26.     }
    27. }
    With this shader, I get a texture combined with an alpha, like if it was in a Mask Layer in photoshop:

    The thing, is that I need a new MainTex (so the old one could be something like _MaskTex) that can go as a usual standard material, and layered above, this 2 layers of Masked Textures.

    I am sorry if my explanation of what I want is not the best I can write, and less with so little experience touching shader scripts. Any help is appreciated.

    Thanks for the attention.
     
unityunity