Guest User

ProcEye.shader

a guest
Aug 13th, 2019
1,438
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/ProcEye"
  2. {
  3.     Properties
  4.     {
  5.         [Header(Main)]
  6.         _Color ("Color", Color) = (1,1,1,1)
  7.      
  8.         [Header(Iris)]
  9.         _IrisTex("Iris Texture (RGB)", 2D) = "white" {}
  10.         _IrisTexColor("Iris Texture Tint", Color) = (1,0,0,1)
  11.         _Radius("Iris Radius", Range(0,1)) = 0.4
  12.         _IrisColor("Iris Color", Color) = (0,1,1,1)
  13.         _IrisColorOut("Iris Color Out", Color) = (0,1,0,1)
  14.         _IrisScaleX("Iris Scale X", Range(0,2)) = 1
  15.         _IrisScaleY("Iris Scale Y", Range(0,2)) = 1
  16.         _Speed("Iris Scroll Speed", Range(-10,10)) = 0
  17.         _Scale("Iris Texture Scale", Range(0.1,10)) = 10
  18.         [Toggle(TEXTURE)] _TEXTURE("Circlular Texture", Float) = 0
  19.         _Distort("Iris Texture Distortion", Range(0,1)) = 0.5
  20.  
  21.         [Header(Pupil)]    
  22.         _RadiusPupil("Pupil Radius", Range(0,0.5)) = 0.1
  23.         _PupilColor("Pupil Color", Color) = (0,0,0,1)
  24.         _PupilColorOut("Pupil Color Out", Color) = (0,0,1,1)
  25.         _PupilScaleX("Pupil Scale X", Range(0,1)) = 0.5
  26.         _PupilScaleY("Pupil Scale Y", Range(0,1)) = 0.5
  27.  
  28.         [Header(Specular and Iris Edge)]
  29.         _Edgewidth("Iris Edge Width", Range(0,2)) = 0.1
  30.         _SpecSize("Specular Size", Range(0.2,0.5)) = 0.47
  31.         _IrisEdgeColor("Iris Edge Color", Color) = (0,0,0,1)
  32.                    
  33.        
  34.     }
  35.         SubShader
  36.         {
  37.             Tags { "RenderType" = "Opaque" }
  38.             LOD 200
  39.           CGPROGRAM
  40.         // Physically based Standard lighting model, and enable shadows on all light types
  41.         #pragma surface surf  Standard fullforwardshadows vertex:vert
  42.         #pragma target 3.5
  43.      
  44.         #pragma shader_feature TEXTURE
  45.  
  46.         sampler2D _MainTex, _IrisTex;
  47.         struct Input
  48.         {
  49.             float2 uv_MainTex;
  50.             float3 objPos;
  51.             float3 lightDir;
  52.             float3 viewDir;
  53.         };
  54.  
  55.  
  56.         float _Radius, _RadiusPupil;
  57.         fixed4 _Color, _IrisColor, _PupilColor, _PupilColorOut, _IrisColorOut, _IrisTexColor, _IrisEdgeColor;
  58.         float _PupilScaleX, _PupilScaleY, _Edgewidth, _SpecSize, _IrisScaleX, _IrisScaleY, _Scale, _Speed, _Distort;
  59.        
  60.  
  61.         void vert(inout appdata_full v, out Input o) {
  62.             UNITY_INITIALIZE_OUTPUT(Input, o);
  63.             o.objPos = v.vertex;
  64.             o.lightDir = WorldSpaceLightDir(v.vertex); // get the worldspace lighting direction
  65.         }
  66.  
  67.         // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
  68.         // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
  69.         // #pragma instancing_options assumeuniformscaling
  70.         UNITY_INSTANCING_BUFFER_START(Props)
  71.             // put more per-instance properties here
  72.         UNITY_INSTANCING_BUFFER_END(Props)
  73.  
  74.         void surf (Input IN, inout SurfaceOutputStandard o)
  75.         {
  76.      
  77.             // circles
  78.             float dis= distance(0, float3(IN.objPos.x * _IrisScaleX, IN.objPos.y * _IrisScaleY, IN.objPos.z - 0.5));
  79.             float disPup = (distance(0, float3(IN.objPos.x * _PupilScaleX, IN.objPos.y * _PupilScaleY , IN.objPos.z - 0.5)));
  80.             float irisRadius = 1- saturate(dis / _Radius);
  81.             float pupilRadius = 1 - saturate(disPup / _RadiusPupil);
  82.             float irisEdge = 1 - saturate(dis / _Radius - _Edgewidth);
  83.        
  84.             // specular
  85.             half d = dot(o.Normal, normalize(IN.lightDir + IN.viewDir))*0.5;
  86.             d = step(_SpecSize, d);
  87.            
  88.            
  89.             // Iris texture
  90.             float4 i = tex2D(_IrisTex, IN.uv_MainTex);
  91.  
  92.             float speed = _Time.x * _Speed + (_Distort *i);
  93.  
  94. #if TEXTURE
  95.             // circular
  96.             i = tex2D(_IrisTex, float2((irisRadius * IN.uv_MainTex + speed) * _Scale) ) ;
  97. #else
  98.             // normal
  99.             i =tex2D(_IrisTex, (float2(IN.uv_MainTex.x, IN.uv_MainTex.y + speed)  * _Scale) ) * _Color;
  100. #endif
  101.             // add extra tint
  102.             i *= _IrisTexColor;
  103.  
  104.  
  105.             // increase strength then clamp it for a smooth circle
  106.             float irisCircle = saturate(irisRadius * 20);
  107.             float pupilCircle = saturate(pupilRadius * 20);
  108.             float irisEdgeCircle = saturate(irisEdge * 20);
  109.            
  110.             // eyewhite is everything but the iris
  111.             float4 eyeWhite = _Color * (1 - irisEdgeCircle);
  112.  
  113.             // subract to avoid bleeding through of colors
  114.             irisEdgeCircle -= irisCircle;
  115.             irisCircle -= pupilCircle;
  116.  
  117.             // lerp colors
  118.             float4 irisLerp = lerp(_IrisColorOut,_IrisColor, irisRadius ) + i;
  119.             float4 irisColored = irisCircle * irisLerp;
  120.        
  121.             float4 pupilLerp = lerp(_PupilColorOut,_PupilColor, pupilRadius);
  122.             float4 pupilColored = pupilCircle * pupilLerp;
  123.  
  124.             float4 irisEdgeColored = irisEdgeCircle * _IrisEdgeColor;
  125.  
  126.             // all together
  127.             o.Albedo = eyeWhite + irisColored + pupilColored + irisEdgeColored;
  128.  
  129.             // specular in emission
  130.             o.Emission = d;
  131.  
  132.         }
  133.         ENDCG
  134.     }
  135.     FallBack "Diffuse"
  136. }
RAW Paste Data