Advertisement
Guest User

ParallaxIceGrabpass.shader

a guest
Sep 8th, 2019
1,117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Shader "Toon/Parallax Ice Grabpass"
  3. {
  4.     Properties
  5.     {
  6.         [Header(Main and Grabpass)]
  7.         _ToonRamp("Toonramp Color", Color) = (0,0,0,1)
  8.         _MainTex("Main Texture (RGB)", 2D) = "white" {}
  9.         _GrabPassOpacity("Grabpass Opacity", Range(0,1)) = 0.1
  10.         _Distort("Grabpass Distortion", Range(0,8)) = 0.1
  11.  
  12.         [Header(Parallax)]
  13.         _Parallax("Parallax", Range(0,0.5)) = 0.1
  14.         _HeightMap("Height Map", 2D) = "white" {}
  15.         _Normal("Normal Map", 2D) = "bump" {}
  16.  
  17.         [Header(Texture)]      
  18.         _Tint("Texture Tint", Color) = (1,1,0,1)
  19.         _ColorTop("Top Col", Color) = (0,1,1,1)
  20.         _BottomCol("Bottom Col", Color) = (0,1,0,1)
  21.         _Offset("Gradient Offset", Range(-1,1)) = 0.1
  22.         _Scale("Main Texture Scale", Range(0,10)) = 1  
  23.         _Brightness("Texture Brigthness", Range(0,5)) = 1
  24.        
  25.         [Header(Spec and Rim)]
  26.         _SpecSize("Specular Size", Range(0.2,0.5)) = 0.47
  27.         _RimPower("Rimpower", Range(0,20)) = 0.47
  28.         _SoftRimColor("SoftRim Color", Color) = (0,0,0,1)
  29.         _HardRimColor("HardRim Color", Color) = (0,0,0,1)
  30.        
  31.     }
  32.         SubShader
  33.         {
  34.             Tags { "RenderType" = "Opaque" "Queue" = "Geometry +1"  }
  35.             LOD 200
  36.            
  37.               GrabPass{ "_GrabTexture" }
  38.           CGPROGRAM
  39.             // Physically based Standard lighting model, and enable shadows on all light types
  40. #pragma surface surf ToonRamp fullforwardshadows vertex:vert
  41. #pragma target 3.5
  42.  
  43.         float4 _ToonRamp;
  44.        
  45.  
  46.         // custom lighting function that uses a texture ramp based
  47.         // on angle between light direction and normal
  48.     #pragma lighting ToonRamp exclude_path:prepass
  49.         inline half4 LightingToonRamp(SurfaceOutput s, half3 lightDir, half atten)
  50.         {
  51.     #ifndef USING_DIRECTIONAL_LIGHT
  52.             lightDir = normalize(lightDir);
  53.     #endif
  54.             float d = dot(s.Normal, lightDir);
  55.             float dChange = fwidth(d);
  56.             float3 lightIntensity = smoothstep(0 , dChange + 0.05, d) + (_ToonRamp);
  57.  
  58.             half4 c;
  59.             c.rgb = s.Albedo * _LightColor0.rgb * (lightIntensity) * (atten * 2);      
  60.             c.a = s.Alpha;
  61.             return c;
  62.         }
  63.  
  64.             sampler2D  _MainTex,_HeightMap, _Normal;
  65.             struct Input
  66.             {
  67.                 float2 uv_MainTex;
  68.                 float2 uv_Normal;
  69.                 float3 objPos;
  70.                 float3 lightDir;
  71.                 float3 viewDir2;// something weird happens to viewdir when using parallax, so it's gettin recalculated
  72.                 float3 vertexNormal;
  73.                 float3 viewDir;
  74.                 float4 grabUV;
  75.  
  76.             };
  77.             float _RimPower;
  78.             float4 _SoftRimColor, _HardRimColor;
  79.             float _Offset;
  80.             fixed4  _ColorTop, _BottomCol, _Tint;
  81.             float _SpecSize,  _Scale, _Parallax, _Brightness, _GrabPassOpacity, _Distort;
  82.             sampler2D _GrabTexture;
  83.  
  84.             void vert(inout appdata_full v, out Input o) {
  85.                 UNITY_INITIALIZE_OUTPUT(Input, o);
  86.                 o.objPos = v.vertex;
  87.                 o.lightDir = WorldSpaceLightDir(v.vertex); // get the worldspace lighting direction
  88.                 o.vertexNormal = mul(unity_ObjectToWorld, v.normal);
  89.                 o.viewDir2 = WorldSpaceViewDir(v.vertex);
  90.                 float4 hpos = UnityObjectToClipPos(v.vertex);
  91.                 o.grabUV = ComputeGrabScreenPos(hpos);
  92.             }
  93.  
  94.             void surf(Input IN, inout SurfaceOutput o)
  95.             {
  96.  
  97.                 //parallax
  98.                 float heightTex = tex2D(_HeightMap, IN.uv_MainTex).r;
  99.                 float2 parallaxOffset = ParallaxOffset(heightTex, _Parallax, IN.viewDir);
  100.  
  101.                 // specular
  102.                 half s = dot((IN.vertexNormal), normalize(IN.lightDir + IN.viewDir2))*0.5;
  103.                 s = step(_SpecSize, s);
  104.  
  105.                 // normals
  106.                 o.Normal = UnpackNormal(tex2D(_Normal, IN.uv_Normal + parallaxOffset));
  107.  
  108.                 // tex
  109.                 float4 c = tex2D(_MainTex, (float2(IN.uv_MainTex.xy) - parallaxOffset * _Scale));
  110.  
  111.                 // add extra tint
  112.                 c *= _Tint;
  113.                 c *= _Brightness;
  114.            
  115.                 // rim lighting
  116.                 float Rim = 1.0 - saturate(dot(normalize(o.Normal) + c, normalize(IN.viewDir)));// calculate a soft fresnel based on the view direction and the normals of the object
  117.                 float softRim = pow(Rim, _RimPower) ;
  118.                 float hardRim = round(softRim);
  119.            
  120.                 float4 softRimColored = softRim * _SoftRimColor ;
  121.                 float4 hardRimColored = hardRim * _HardRimColor;
  122.  
  123.                 //Grabpass
  124.                 float4 grabPass = tex2Dproj(_GrabTexture, UNITY_PROJ_COORD(IN.grabUV + float4(parallaxOffset * _Distort,0,0)));
  125.                 grabPass *= 1-smoothstep(0, 0.1, Rim);
  126.  
  127.                 // lerp colors
  128.                 float4 colors = lerp(_BottomCol, _ColorTop, saturate(IN.objPos.y+ _Offset)) + c;
  129.                
  130.                 // specular and rim emmision
  131.  
  132.                 o.Emission = s  + softRimColored + hardRimColored;
  133.  
  134.                 o.Albedo = (grabPass * _GrabPassOpacity) + colors + softRimColored;
  135.             }
  136.             ENDCG
  137.         }
  138.             FallBack "Diffuse"
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement