Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Unable to get Unity Game to add MainTex Alpha to existing Shader

Discussion in 'Shaders' started by Deleted User, Nov 21, 2021.

  1. Deleted User

    Deleted User

    Guest

    Greetings,

    I have tried following a number of different threads and tutorials to try to figure out how to get this existing shader to add the Main Texture's Alpha cutoff with proper Z Depth. I have not been able to get anything to work in game. The shader edits I have tried work in the 2017.3.1 Unity Editor but not in game.

    The object needs to be a single objects for the games painting system to work on it. I can't get the holes in the surface created with the alpha texture to work. Any suggestions on best method to go at this with? Below is code for the basic "Paint Metallic" Shader I'm trying to add the Alpha Cutoff to.

    Capture.JPG

    Code (CSharp):
    1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
    2.  
    3. Shader "Custom/KingSpray_Paint_Metallic" {
    4.     Properties{
    5.  
    6.         _MainTex("Base Color", 2D) = "white" {}
    7.         [NoScaleOffset]_MetallicGlossMap("MSMO", 2D) = "grey" {}
    8.         [NoScaleOffset]_BumpMap("Normal Map", 2D) = "bump" {}
    9.         _BumpScale("Bump Scale",Range(0,3)) = 1
    10.         _PaintTex("Paint", 2D) = "black" {}
    11.         _PaintMask("Paint Mask", 2D) = "black" {}
    12.     }
    13.         SubShader{
    14.         Tags{ "RenderType" = "Opaque" }
    15.         LOD 300
    16.  
    17.         CGPROGRAM
    18.  
    19. #pragma surface surf Standard
    20. #pragma target 3.0
    21.  
    22.     uniform sampler2D _MainTex;
    23.     uniform sampler2D _MetallicGlossMap;
    24.     uniform sampler2D _BumpMap;
    25.     uniform sampler2D _PaintTex;
    26.     uniform sampler2D _PaintMask;
    27.     half _BumpScale;
    28.  
    29.     struct Input {
    30.         fixed4 color : COLOR;
    31.         float2 uv_MainTex;
    32.         float2 uv3_PaintTex;
    33.         float3 worldPos;
    34.         float3 viewDir;
    35.     };
    36.  
    37.  
    38.     void surf(Input IN, inout SurfaceOutputStandard o) {
    39.  
    40.        
    41.         //set up UVs
    42.         float2 uv = IN.uv_MainTex;
    43.         float2 uvPaint = IN.uv3_PaintTex;
    44.         fixed4 msmo = tex2D(_MetallicGlossMap, uv);
    45.         fixed4 paint = tex2D(_PaintTex, uvPaint);
    46.         fixed4 paintMask = tex2D(_PaintMask, uvPaint);
    47.         fixed3 bump = UnpackScaleNormal(tex2D(_BumpMap, uv), _BumpScale);
    48.         fixed4 diffuse = tex2D(_MainTex, uv);
    49.         paint *= IN.color.b;
    50.         diffuse = lerp(diffuse, paint, (paint.a));
    51.         diffuse += paint*(1 - paint.a);
    52.  
    53.         o.Normal = bump;
    54.         o.Albedo = diffuse;
    55.         o.Metallic = max(msmo.r*((paint.a*-1) + 1), paintMask.r);
    56.         o.Smoothness = clamp(msmo.a + paintMask.g, .2, .9);
    57.     }
    58.     ENDCG
    59.     }
    60.         FallBack "Diffuse"
    61. }