Advertisement
Bagserk

ColorMask3LayerMetal_AlphaTest

Oct 4th, 2018
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/ColorMask3LayerMetal_AlphaTest" {
  2.     Properties
  3.     {
  4.         _Color ("Color", Color) = (1,1,1,1)
  5.         _Color_2 ("Color_2", Color) = (1,1,1,1)
  6.         _Color_3 ("Color_3", Color) = (1,1,1,1)    
  7.         _MainTex ("Texture", 2D) = "white" {}
  8.         _MaskTex ("MaskTexture", 2D) = "white" {}
  9.         _MaskColor("MaskColor", Color) = (1,0,0,1)
  10.         _MaskStrength("Mask Strength", Range(0.0, 1.0)) = 1
  11.         _BumpMap ("Bumpmap", 2D) = "bump" {}
  12.         _MetalGlossMap("Metallic Texture", 2D) = "white" {}
  13.         _SpecColor("SpecColor", Color) = (1,1,1,1)
  14.         _SpecColor_3 ("SpecColor_3", Color) = (1,1,1,1)
  15.         _OcclusionStrength("Occlusion Strength", Range(0.0, 1.0)) = 1
  16.         _OcclusionMap("Occlusion Map", 2D) = "white" {}
  17.         _Metallic ("Metallic", Range(0,1)) = 1
  18.         _Metallic_2 ("Metallic 2", Range(0,1)) = 1     
  19.         _Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5       
  20.         _Smoothness_2("Smoothness_2", Range(0.0, 1.0)) = 0.5
  21.         _EmissionColor("Emission Color", Color) = (0,0,0)
  22.         _EmissionMap("Emission", 2D) = "black" {}
  23.         _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
  24.         _DetailBump ("Detail Bumpmap", 2D) = "bump" {}
  25.         _DetailBumpStrength("Detail Bumpmap Strength", Range(0.0,1.0)) = 0.0
  26.         _DetailBumpScale ("Detail Bumpmap Scale", Int) = 1
  27.         _DetailMask ("Detail Mask", 2D) = "white" {}
  28.     }
  29.     SubShader {
  30.         Tags {"Queue" = "AlphaTest" "RenderType"="TransparentCutout" }
  31.  
  32.         LOD 200
  33.        
  34.         CGPROGRAM
  35.         #include "UnityPBSLighting.cginc"
  36.         // Physically based Standard lighting model, and enable shadows on all light types
  37.         #pragma surface surf Standard fullforwardshadows alphatest:_Cutoff addshadow
  38.  
  39.         // Use shader model 3.0 target, to get nicer looking lighting
  40.         #pragma target 3.0
  41.  
  42.         sampler2D _MainTex, _MaskTex, _BumpMap, _MetalGlossMap, _OcclusionMap, _EmissionMap, _DetailBump, _DetailMask;
  43.         fixed4 _Color, _Color_2, _Color_3;
  44.         fixed4 _SpecColor_3;   
  45.         fixed4 _MaskColor;
  46.         half3 _EmissionColor;
  47.         half _Metallic, _Metallic_2;       
  48.         half _Smoothness, _Smoothness_2;
  49.         half _OcclusionStrength;
  50.         half _MaskStrength;
  51.         int _DetailBumpScale;
  52.         half _DetailBumpStrength;
  53.  
  54.         //float4 mask;
  55.  
  56.         struct Input {
  57.             float2 uv_MainTex;
  58.             float2 uv_MaskTex;
  59.             float2 uv_BumpMap;
  60.             float2 uv_EmissionMap; 
  61.             float2 uv_DetailBump;
  62.         };
  63.  
  64.  
  65.  
  66.         void surf (Input IN, inout SurfaceOutputStandard o) {
  67.             // Albedo comes from a texture tinted by colo
  68.             float4 c = tex2D (_MainTex, IN.uv_MainTex);
  69.             float4 mask = tex2D (_MaskTex, IN.uv_MaskTex);         
  70.             float cmask = min(1.0 ,mask.r + mask.g + mask.b);
  71.             float4 n = tex2D (_BumpMap, IN.uv_BumpMap);
  72.             float4 sp = tex2D (_MetalGlossMap, IN.uv_MainTex);
  73.             float oc = tex2D(_OcclusionMap, IN.uv_MainTex).rgb;
  74.             float em = tex2D(_EmissionMap, IN.uv_EmissionMap).r;           
  75.             float4 detailn = tex2D (_DetailBump, IN.uv_DetailBump * _DetailBumpScale);
  76.             float4 detailmask = tex2D(_DetailMask, IN.uv_DetailBump);
  77.             half3 normalTangent = UnpackNormal(n);
  78.             half3 detailNormalTangent = UnpackScaleNormal(detailn, _DetailBumpStrength);
  79.             normalTangent = lerp(normalTangent, BlendNormals(normalTangent, detailNormalTangent), detailmask.r);
  80.            
  81.            
  82.             mask = lerp(float4(0,0,0,0), mask * _MaskColor, _MaskStrength);
  83.            
  84.             c.rgb = c.rgb * (1 - cmask) * _Color_2 + (c * _Color * mask.r) + (c * _SpecColor.rgb * mask.g) + (c * _Color_3 * mask.b);
  85.             //sp.rgb = sp.rgb * _Metallic;
  86.            
  87.             o.Albedo = c.rgb;          
  88.             o.Normal = normalTangent;          
  89.             //o.Metallic = sp.rgb;
  90.             o.Metallic = clamp(sp.rgb * (1 - cmask) * _Metallic_2 + (sp.rgb * _Metallic * mask.r) + (sp.rgb * _SpecColor_3.g * mask.g) + (sp.rgb * _SpecColor_3.r * mask.b),0,1);
  91.             o.Smoothness = clamp(sp.a * (1 - cmask) * _Smoothness_2 + ((sp.a * _Smoothness) * mask.r) + ((sp.a * _SpecColor_3.b) * mask.g) + ((sp.a * _SpecColor_3.a) * mask.b),0,1);          
  92.             o.Occlusion = lerp(float4(1,1,1,1), oc, _OcclusionStrength).rgba;          
  93.             o.Emission = em * _EmissionColor;
  94.             o.Alpha = c.a;
  95.         }
  96.         ENDCG
  97.     }
  98.     FallBack "Transparent/Cutout/Diffuse"
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement