Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Combining textures in custom shader

Discussion in 'Shaders' started by rostik1975, Mar 22, 2021.

  1. rostik1975

    rostik1975

    Joined:
    May 14, 2015
    Posts:
    44
    Hi,
    Is it possible to define an "empty transparent texture" as a default, or somehow detect if no texture was assigned, in a shader?
    I have a custom shader where several layers are combined - everything works OK if I assign all the slots. But if I left secondary texture slot empty, it looks like a white color is passed instead.
    Code (CSharp):
    1.  
    2. _Color ("Main Color", Color) = (1,1,1,1)
    3. _SkinTex ("Skin Texture (RGBA)", 2D) = "white" {}
    4. _TattooTex ("Tattoo Texture (RGBA)", 2D) = "" {}
    5. _TattooAlpha ("Tattoo Alpha", Range (0, 1)) = 0
    6. _ScarTex ("Scar Texture (RGBA)", 2D) = "" {}
    7. _ScarAlpha ("Scar Alpha", Range (0, 1)) = 0
    8.  
    ...

    Code (CSharp):
    1.  
    2. void surf(Input IN, inout SurfaceOutputStandard o)
    3.         {
    4.             half4 c = tex2D(_SkinTex, IN.uv_SkinTex) * _Color;
    5.             half4 tattoo = tex2D(_TattooTex, IN.uv_TattooTex);
    6.             half4 scar =   tex2D(_ScarTex, IN.uv_ScarTex);
    7.             c.rgb = lerp (c.rgb, tattoo.rgb, tattoo.a * _TattooAlpha);
    8.             c.rgb = lerp (c.rgb, scar.rgb, scar.a * _ScarAlpha);
    9.             o.Albedo = c.rgb * _Color.rgb;
    10.  


    Is it possible to ignore a secondary map if it is not assigned?
    The only workaround I have found for now is assigning a transparent image as a secondary map if I don't need it.

    Thank you.
     

    Attached Files:

  2. rostik1975

    rostik1975

    Joined:
    May 14, 2015
    Posts:
    44
    Update:
    Resolved by setting all _...Alpha sliders to 0 by default.