Advertisement
Guest User

EyeBallTex.shader

a guest
Feb 19th, 2020
2,426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/ProcEye Textured"
  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) = "black" {}
  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.         _Brightness("Iris Texture Brigthness", Range(0,5)) = 1
  21.  
  22.         [Header(Pupil)]    
  23.         _PupilTex("Pupil Texture (RGB)", 2D) = "white" {}
  24.         _PupilScale("Pupil Tex Radius", Range(0,1)) = 0.3
  25.         _RadiusPupil("Pupil Radius", Range(0,0.5)) = 0.1
  26.         _PupilColor("Pupil Color", Color) = (0,0,0,1)
  27.         _PupilColorOut("Pupil Color Out", Color) = (0,0,1,1)
  28.         _PupilScaleX("Pupil Scale X", Range(0,1)) = 0.5
  29.         _PupilScaleY("Pupil Scale Y", Range(0,1)) = 0.5
  30.  
  31.         [Header(Highlight and Iris Edge)]
  32.         _GlintTex("Glint Texture (RGB)", 2D) = "black" {}
  33.         _GlintScale("Glint Scale", Range(0,1)) = 0.3
  34.         _Edgewidth("Iris Edge Width", Range(0,2)) = 0.1
  35.         _IrisEdgeColor("Iris Edge Color", Color) = (0,0,0,1)
  36.                    
  37.        
  38.     }
  39.         SubShader
  40.         {
  41.             Tags { "RenderType" = "Opaque" }
  42.             LOD 200
  43.           CGPROGRAM
  44.         // Physically based Standard lighting model, and enable shadows on all light types
  45.         #pragma surface surf  Standard fullforwardshadows vertex:vert
  46.         #pragma target 3.5
  47.      
  48.         #pragma shader_feature TEXTURE
  49.  
  50.         sampler2D _MainTex, _IrisTex, _PupilTex, _GlintTex;
  51.         struct Input
  52.         {
  53.             float2 uv_MainTex;
  54.             float4 objPos;
  55.             float3 viewDir;
  56.         };
  57.  
  58.  
  59.         float _Radius, _RadiusPupil;
  60.         fixed4 _Color, _IrisColor, _PupilColor, _PupilColorOut, _IrisColorOut, _IrisTexColor, _IrisEdgeColor;
  61.         float _PupilScaleX, _PupilScaleY, _Edgewidth, _IrisScaleX, _IrisScaleY, _Scale, _Speed, _Distort, _Brightness;
  62.         float _PupilScale;
  63.         float  _GlintScale;
  64.  
  65.         void vert(inout appdata_full v, out Input o) {
  66.             UNITY_INITIALIZE_OUTPUT(Input, o);
  67.             o.objPos = v.vertex;
  68.         }
  69.  
  70.         // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
  71.         // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
  72.         // #pragma instancing_options assumeuniformscaling
  73.         UNITY_INSTANCING_BUFFER_START(Props)
  74.             // put more per-instance properties here
  75.         UNITY_INSTANCING_BUFFER_END(Props)
  76.  
  77.         void surf (Input IN, inout SurfaceOutputStandard o)
  78.         {
  79.  
  80.  
  81.             // circles
  82.             float dis= distance(0, float3(IN.objPos.x * _IrisScaleX, IN.objPos.y * _IrisScaleY, IN.objPos.z - 0.5));
  83.             float disPup = (distance(0, float3(IN.objPos.x * _PupilScaleX, IN.objPos.y * _PupilScaleY , IN.objPos.z - 0.5)));
  84.             float irisRadius = 1- saturate(dis / _Radius);
  85.             float pupilRadius = 1 - saturate(disPup / _RadiusPupil);
  86.             float irisEdge = 1 - saturate(dis / _Radius - _Edgewidth);
  87.        
  88.             // point in center of eye, flipped
  89.             float2 uv = float2(-IN.objPos.x , IN.objPos.y );
  90.             // uv for the pupil, adjusted for a sphere
  91.             float2 uvPup  = uv / (_PupilScale * 2);
  92.             uvPup += 0.5;
  93.            
  94.             // uv for the glint, adjusted for a sphere
  95.             float2 uvGlint = uv / (_GlintScale * 2);
  96.             uvGlint += 0.5;
  97.             uvGlint.x -= 0.2;
  98.             uvGlint += IN.viewDir * 0.2;
  99.  
  100.        
  101.            
  102.             // Iris texture
  103.             float4 i = tex2D(_IrisTex, IN.uv_MainTex);
  104.  
  105.             float speed = _Time.x * _Speed + (_Distort *i);
  106.  
  107. #if TEXTURE
  108.             // circular
  109.             i = tex2D(_IrisTex, float2((disPup * IN.uv_MainTex + speed) * _Scale) ) ;
  110. #else
  111.             // normal
  112.             i =tex2D(_IrisTex, (float2(IN.uv_MainTex.x, IN.uv_MainTex.y + speed)  * _Scale) );
  113. #endif
  114.  
  115.             // glint and pupil texture
  116.             float4 glint = tex2D(_GlintTex, uvGlint);
  117.             float4 pup = tex2D(_PupilTex, uvPup);
  118.  
  119.             // add extra tint
  120.             i *= _IrisTexColor;
  121.             i *= _Brightness;
  122.  
  123.             // increase strength then clamp it for a smooth circle
  124.             float irisCircle = saturate(irisRadius * 20);
  125.             float pupilCircle = saturate(pupilRadius * 20);
  126.             pupilCircle *= pup.r;
  127.             float irisEdgeCircle = saturate(irisEdge * 10);
  128.            
  129.             // eyewhite is everything but the iris
  130.             float4 eyeWhite = _Color * (1 - irisEdgeCircle);
  131.             glint *= irisCircle;
  132.             // subract to avoid bleeding through of colors
  133.             irisEdgeCircle -=irisCircle ;
  134.        
  135.             irisCircle -= pupilCircle;
  136.  
  137.             // lerp colors
  138.             float4 irisLerp = lerp(_IrisColorOut,_IrisColor, irisRadius ) + i;
  139.             float4 irisColored = irisCircle * irisLerp;
  140.        
  141.             float4 pupilLerp = lerp(_PupilColorOut,_PupilColor, pupilRadius);
  142.             float4 pupilColored = pupilCircle * pupilLerp;
  143.  
  144.  
  145.             float4 irisEdgeColored = irisEdgeCircle * _IrisEdgeColor;
  146.        
  147.             // all together
  148.             o.Albedo = eyeWhite + irisColored + pupilColored + irisEdgeColored;
  149.             // glint in emission
  150.             o.Emission =  glint;
  151.             o.Smoothness = 0.75;
  152.  
  153.  
  154.         }
  155.         ENDCG
  156.     }
  157.     FallBack "Diffuse"
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement