Advertisement
Bagserk

Custom PBR ColorMask3Layer (Metallic)

Feb 27th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.02 KB | None | 0 0
  1. Shader "Custom/ColorMask3LayerMetal" {
  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.     }
  24.     SubShader {
  25.         Tags { "RenderType"="Opaque" }
  26.  
  27.         LOD 200
  28.        
  29.         CGPROGRAM
  30.         #include "UnityPBSLighting.cginc"
  31.         // Physically based Standard lighting model, and enable shadows on all light types
  32.         #pragma surface surf Standard fullforwardshadows
  33.  
  34.         // Use shader model 3.0 target, to get nicer looking lighting
  35.         #pragma target 3.0
  36.  
  37.         sampler2D _MainTex, _MaskTex, _BumpMap, _MetalGlossMap, _OcclusionMap, _EmissionMap;
  38.         fixed4 _Color, _Color_2, _Color_3;
  39.         fixed4 _SpecColor_3;   
  40.         fixed4 _MaskColor;
  41.         half3 _EmissionColor;
  42.         half _Metallic, _Metallic_2;       
  43.         half _Smoothness, _Smoothness_2;
  44.         half _OcclusionStrength;
  45.         half _MaskStrength;
  46.         //float4 mask;
  47.  
  48.         struct Input {
  49.             float2 uv_MainTex;
  50.             float2 uv_MaskTex;
  51.             float2 uv_BumpMap;
  52.             float2 uv_MetalGlossMap;
  53.             float2 uv_EmissionMap;
  54.             float2 uv_OcclusionMap;
  55.         };
  56.  
  57.  
  58.  
  59.         void surf (Input IN, inout SurfaceOutputStandard o) {
  60.             // Albedo comes from a texture tinted by colo
  61.             float4 c = tex2D (_MainTex, IN.uv_MainTex);
  62.             float4 mask = tex2D (_MaskTex, IN.uv_MaskTex);         
  63.             float cmask = min(1.0 ,mask.r + mask.g + mask.b);
  64.             float4 n = tex2D (_BumpMap, IN.uv_BumpMap);
  65.             float4 sp = tex2D (_MetalGlossMap, IN.uv_MainTex);
  66.             float oc = tex2D(_OcclusionMap, IN.uv_MainTex).rgb;
  67.             float em = tex2D(_EmissionMap, IN.uv_EmissionMap).r;
  68.            
  69.             mask = lerp(float4(0,0,0,0), mask * _MaskColor, _MaskStrength);
  70.            
  71.             c.rgb = c.rgb * (1 - cmask) + (c * _Color * mask.r) + (c * _SpecColor.rgb * mask.g) + (c * _Color_3 * mask.b);
  72.             //sp.rgb = sp.rgb * _Metallic;
  73.            
  74.             o.Albedo = c.rgb;          
  75.             o.Normal = UnpackNormal (n);           
  76.             //o.Metallic = sp.rgb;
  77.             o.Metallic = sp.rgb * (1 - cmask) + (sp.rgb * _Metallic * mask.r) + (sp.rgb * _Metallic_2 * mask.g) + (sp.rgb * _SpecColor_3.rgb * mask.b);
  78.             o.Smoothness = (sp.a * (1 - cmask) + ((sp.a * _Smoothness) * mask.r) + ((sp.a * _Smoothness_2) * mask.g) + ((sp.a * _SpecColor_3.a) * mask.b));
  79.             o.Occlusion = lerp(float4(1,1,1,1), oc, _OcclusionStrength).rgba;          
  80.             o.Emission = em * _EmissionColor;
  81.         }
  82.         ENDCG
  83.     }
  84.     FallBack "Diffuse"
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement