Advertisement
uurha

Untitled

Nov 30th, 2022
1,794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  2.  
  3. // Alpha of color - intensity of mask
  4. Shader "Custom/Neon_height_hard_color2" {
  5.  
  6.     Properties {
  7.         _MainTex ("Main texture", 2D) = "white" {}
  8.         _SkinTex ("Mask texture", 2D) = "white" {}
  9.  
  10.             [Space]
  11.  
  12.         _EmissionMap("Emission map", 2D) = "black"{}
  13.  
  14.             [Space]
  15.  
  16.         _MainColor ("Main color (red)", Color) = (1,1,1,1)
  17.         _AddColor ("Additional color (green)", Color) = (1,1,1,1)
  18.         _ExtColor ("Extra color (blue)", Color) = (1,1,1,1)
  19.  
  20.             [Space]
  21.  
  22.         [Toggle] _Emission("Emission", Float) = 0
  23.  
  24.         [Enum(UnityEngine.Rendering.CullMode)] _Cull("Cull", Float) = 2 //"Back"
  25.        
  26.         [Space]
  27.  
  28.         [HDR]_MinColor("Min color", Color) = (0,0,0,1)
  29.        
  30.         [Space]
  31.        
  32.         _MinY1("Min Y", Float) = 0.0
  33.         _MaxY1("Max Y", Float) = 0.95
  34.         [HDR]_MaxColor1("Max color 1", Color) = (0,1,1,1)
  35.  
  36.         [Space]
  37.         _MinY2("Min Y", Float) = 0.0
  38.         _MaxY2("Max Y", Float) = 0.95
  39.         [HDR]_MaxColor2("Max color 2", Color) = (0,1,1,1)
  40.  
  41.     }
  42.  
  43.     SubShader {
  44.         Cull [_Cull]
  45.         Blend SrcAlpha OneMinusSrcAlpha
  46.  
  47.         Pass {
  48.             CGPROGRAM
  49.             #pragma fragment frag
  50.             #pragma vertex vert
  51.             #pragma multi_compile_fog
  52.  
  53.             #include "UnityCG.cginc"
  54.             #include "UnityLightingCommon.cginc"
  55.                
  56.             sampler2D _MainTex;
  57.             sampler2D _SkinTex;
  58.             float4 _MainTex_ST;
  59.             float4 _MainColor;
  60.             float4 _AddColor;
  61.             float4 _ExtColor;
  62.             float _Emission;
  63.             sampler2D _EmissionMap;
  64.            
  65.             float4 _MinColor;
  66.  
  67.             float _MinY1;
  68.             float _MaxY1;
  69.             float4 _MaxColor1;
  70.  
  71.             float _MinY2;
  72.             float _MaxY2;
  73.             float4 _MaxColor2;
  74.  
  75.             struct Interpolators {
  76.                 float4 position : SV_POSITION;
  77.                 float2 uv : TEXCOORD0;
  78.                 float2 uvSplat : TEXCOORD1;
  79.                 float3 normal : NORMAL;
  80.                 fixed4 diff : COLOR0; // diffuse lighting color
  81.                 fixed4 world : TEXCOORD2;
  82.                 UNITY_FOG_COORDS(3)
  83.             };
  84.  
  85.             struct VertexData {
  86.                 float4 position : POSITION;
  87.                 float2 uv : TEXCOORD0;
  88.                 float3 normal : NORMAL;
  89.             };
  90.  
  91.             Interpolators vert (VertexData v) {
  92.                 Interpolators i;
  93.                 i.position = UnityObjectToClipPos(v.position);
  94.                 i.uv = TRANSFORM_TEX(v.uv, _MainTex);
  95.                 i.uvSplat = v.uv;
  96.                 i.normal = UnityObjectToWorldNormal(v.normal);
  97.                 half nl = max(0, dot(i.normal, _WorldSpaceLightPos0.xyz));
  98.                 nl = clamp(nl, 0, 1);
  99.                 i.diff = lerp(unity_AmbientSky, _LightColor0 * nl, nl);
  100.                 //i.world = mul(unity_ObjectToWorld, v.position);
  101.                 i.world = mul(unity_ObjectToWorld, float4(0.0,0.0,0.0,1.0) );
  102.                 UNITY_TRANSFER_FOG(i, i.position);
  103.                 return i;
  104.             }
  105.  
  106.             float4 frag(Interpolators i) : SV_TARGET{
  107.                 float4 splat = tex2D(_SkinTex, i.uvSplat);
  108.                 float3 tex = tex2D(_MainTex, i.uv);
  109.  
  110.                 float4 color = float4(tex.rgb * (1 - splat.r - splat.g - splat.b) +
  111.                     lerp (tex.rgb, _MainColor.rgb, _MainColor.a) * splat.r +
  112.                     lerp (tex.rgb, _AddColor.rgb, _AddColor.a) * splat.g +
  113.                     lerp (tex.rgb, _ExtColor.rgb, _ExtColor.a) * splat.b, splat.a);
  114.                 color.rgb *= i.diff.rgb;
  115.  
  116.                 fixed c1 = step(i.world.y, _MaxY1) * step(_MinY1, i.world.y);
  117.                 float h1 = step((i.world.y - _MinY1) / (_MaxY1 - _MinY1), 1.0);
  118.                 float3 emisColor1 = lerp(_MinColor, _MaxColor1, h1);
  119.                
  120.                 fixed c2 = step(i.world.y, _MaxY2) * step(_MinY2, i.world.y);
  121.                 float h2 = step((i.world.y - _MinY2) / (_MaxY2 - _MinY2), 1.0);
  122.                 float3 emisColor2 = lerp(_MaxColor1, _MaxColor2, h2);
  123.                
  124.                 float3 emisColor = emisColor1 * c1 + emisColor2 * c2 + _MaxColor2 * step(_MaxY2, i.world.y) + _MinColor * step(i.world.y, _MinY1);
  125.                
  126.                 float h = step(i.world.y, _MinY1);
  127.                 float emisPower = lerp(0, _Emission, h);
  128.  
  129.                 float3 emisG = tex2D(_EmissionMap, i.uv).g * emisPower;
  130.                 float3 emis = tex2D(_EmissionMap, i.uv).r;
  131.  
  132.                 color.rgb = lerp(color.rgb, emisG * emisColor, emisG * _Emission);
  133.                 color.rgb = lerp(color.rgb, emis * emisColor, emis * _Emission);
  134.  
  135.                 UNITY_APPLY_FOG(i.fogCoord, color);
  136.                 return color;
  137.             }
  138.  
  139.             ENDCG
  140.         }
  141.     }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement