ScruffyRules

dasdaasd

Jan 19th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.93 KB | None | 0 0
  1. Shader "NEK0/Cam"
  2. {
  3.     Properties
  4.     {
  5.        
  6.         [NoScaleOffset] _HudTex2 ("CAM", 2D) = "white" {}
  7.         [HideInInspector] _TintScnd ("Secondary HUD Tint", Color) = (1,1,1,1)
  8.         [HideInInspector] _TintFlip (".", Color) = (1,1,1,0)
  9.         [HideInInspector]_xtiles ("Flip-book Columns", float) = 1
  10.         [HideInInspector]_ytiles ("Flip-book Rows", float) = 1
  11.         [HideInInspector][NoScaleOffset] _DigitTex ("Digits (RGB)", 2D) = "white" {}
  12.  
  13.         _offset ("Hud offset", Vector) = (0.0, 0.0, 0.0, 0.0)
  14.         [HideInInspector] _range ("Range ", Float) =3
  15.  
  16.  
  17.  
  18.         [HideInInspector][Toggle] _Hide ("Hide from other players", int) = 1
  19.         [HideInInspector] _scale ("Hud's scale in the transform tab", float) = 1.0
  20.        
  21.     }
  22.     SubShader
  23.     {
  24.                Tags { "Queue"="Transparent+99999" "RenderType"="Transparent" }
  25.         LOD 100
  26.        
  27.        // Cull off
  28.         Zwrite Off
  29.        
  30.         Ztest Always
  31.        
  32.         Blend SrcAlpha OneMinusSrcAlpha
  33.        
  34.         Pass {
  35.             CGPROGRAM
  36.             #pragma vertex vert
  37.             #pragma fragment frag
  38.             #include "UnityCG.cginc"
  39.             struct v2f
  40.             {
  41.                 float2 uv : TEXCOORD0;
  42.                 int3x4 digits : TEXCOORD1;
  43.                 int type : TEXCOORD5;
  44.                 float2 ang: TEXCOORD6;
  45.                 float4 pos : SV_POSITION;
  46.                 float4 color : COLOR;
  47.  
  48.             };
  49.            
  50.  
  51.             sampler2D _DigitTex;
  52.             sampler2D _HudTex;
  53.             sampler2D _HudTex2;
  54.             sampler2D _FlipTex;
  55.             sampler2D _CompTex;
  56.             half4 _DigitTex_ST;
  57.             fixed4 _TintMain;
  58.             fixed4 _TintScnd;
  59.             fixed4 _TintComp;
  60.             fixed4 _TintFlip;
  61.             fixed4 _TintGiz;
  62.             fixed4 _TintColor;
  63.             fixed4 _TintColor2;
  64.             fixed4 _TintColorX;
  65.             fixed4 _TintColorY;
  66.             fixed4 _TintColorZ;
  67.             half _convergence;
  68.             half _range;
  69.             half _CompRad;
  70.             half4 _offset;
  71.             half4 _aoffset;
  72.             float _clip;
  73.             half _xtiles;
  74.             half _ytiles;
  75.             half _frame;
  76.             int  _Hide;
  77.             half _scale;
  78.  
  79.            
  80.             float is_eq(float num, float comp)
  81.             {
  82.                 return step(comp-0.01, num)*step(num,comp+0.01);
  83.             }
  84.            
  85.             int display_type(float4 color)
  86.             {
  87.  
  88.                 int type = 0;
  89.                
  90.                 type += step(0.99, color.r)*step(color.g,0.01)*step(color.b,0.01)
  91.                         + step(0.99, color.b)*step(color.r,0.01)*step(color.g,0.01)
  92.                         + step(0.99, color.g)*step(color.r,0.01)*step(color.b,0.01);
  93.                        
  94.                 type += 2*step(color.r + color.g, 0.01)*step(color.b, 0.55)*step(0.45,color.b);
  95.                 type += 3*step(color.r + color.b, 0.01)*step(color.g, 0.55)*step(0.45,color.g);
  96.                 type += 4*step(color.r + color.g + color.b, 0.01); 
  97.                 type += 5*step(color.b + color.g, 0.01)*step(color.r, 0.55)*step(0.45,color.r);
  98.                 type += 6*is_eq(color.r, 0.5)*is_eq(color.g, 0.5)*step(color.b, 0.01);
  99.                 type += 7*is_eq(color.r, 0.5)*is_eq(color.b, 0.5)*step(color.g, 0.01);
  100.                 return type;
  101.             }
  102.            
  103.             int3x4 display_digits(float displayValue, int type, int3x4 digits)
  104.             {
  105.                
  106.        
  107.             }
  108.            
  109.             v2f vert(float4 pos : POSITION, float2 uv : TEXCOORD0, float4 color : COLOR)
  110.             {
  111.                 v2f o;
  112.                
  113.                 o.type = display_type(color);
  114.                
  115.                 float3 WPos = mul(unity_ObjectToWorld, float4(0,0,0,1)).xyz;
  116.                
  117.                 float3 coords = WPos*color.rgb;
  118.                
  119.  
  120.                 float displayValue = 0;
  121.  
  122.                 displayValue += (o.type == 1)*(coords.x + coords.y + coords.z);
  123.  
  124.                 displayValue += (o.type == 4)*unity_DeltaTime[3];
  125.  
  126.                 displayValue += (o.type == 5)*_Time[1];
  127.                
  128.                
  129.                
  130.                
  131.  
  132.                 #if UNITY_SINGLE_PASS_STEREO
  133.                    
  134.  
  135.                     float ipd = _convergence;
  136.                     float4 abspos = pos + float4(ipd*(0.5-unity_StereoEyeIndex), 0, 0, 0);
  137.                     float4 camPos = mul(unity_CameraToWorld, float4(_aoffset.xyz,1) + float4(ipd*(0.5-unity_StereoEyeIndex), 0, 0, 0));
  138.                
  139.                 #else
  140.                     float ipd = 0.0;
  141.                     float4 abspos = pos;
  142.                     float4 camPos = mul(unity_CameraToWorld, float4(_aoffset.xyz,2) );
  143.                
  144.                 #endif
  145.    
  146.    
  147.                 abspos.xyz += _offset.xyz;
  148.                
  149.  
  150.                 float4 worldPos  = mul(unity_CameraToWorld, abspos);   // Transform View to World
  151.                 float4 objectPos = mul(unity_WorldToObject, worldPos); // Transform World To Object
  152.  
  153.                 float4 axisPos = mul(UNITY_MATRIX_V, float4(pos.xyz*_aoffset.w,1) + float4(camPos.xyz,2));
  154.                 axisPos = mul(UNITY_MATRIX_P,axisPos);
  155.                
  156.                 o.pos = UnityObjectToClipPos(objectPos)*(step(o.type,3.9) + step(2.9,o.type)) + (o.type == 2)*axisPos;
  157.  
  158.                 float4 dist = distance(_WorldSpaceCameraPos, mul(unity_ObjectToWorld, float4(0,0,0,1)));
  159.                 o.pos = o.pos - o.pos*step(_range, dist);
  160.  
  161.                 half LocalScale = length(mul(unity_ObjectToWorld, float4(0,0,2/_scale,0)));
  162.                 o.pos = o.pos - o.pos*step(0.02, LocalScale)*(_Hide == 1);
  163.                
  164.  
  165.                
  166.                 o.color = float4(0,0,0,0);
  167.                 o.color += (o.type == 1)*(color.r*_TintColorX + color.g*_TintColorY + color.b*_TintColorZ);
  168.                 o.color += _TintColor*(o.type == 4);
  169.                 o.color += _TintColor2*(o.type == 5);
  170.  
  171.                
  172.                 #if UNITY_SINGLE_PASS_STEREO
  173.                     float3 p1 =  mul(unity_StereoCameraToWorld[0], float4(0,0,0,0));
  174.                     float3 p2 =  mul(unity_StereoCameraToWorld[0], float4(0,0,0,0));
  175.                 #else
  176.                     float3 p1 =  mul(unity_CameraToWorld, float4(0,0,0,0));
  177.                     float3 p2 =  mul(unity_CameraToWorld, float4(0,0,0,0));
  178.                 #endif
  179.                    
  180.                 float3 forward = p2-p1;
  181.                 forward.xz = normalize(forward.xz);
  182.                 o.ang[1] = sign(forward.x)*acos(forward.z) ;
  183.                
  184.                 float2 origin_dir = normalize(p2.xz);
  185.                 o.ang[1] = sign(origin_dir.x)*acos(origin_dir.y);
  186.                
  187.                
  188.  
  189.                 o.uv = TRANSFORM_TEX(uv, _DigitTex);
  190.                 half2 frame = half2(floor(fmod(_frame, _xtiles)), floor(fmod((_frame/float(_xtiles)), _ytiles)));  
  191.                 o.uv += (o.type==0)*(-o.uv + float2((o.uv.x + frame[0])/_xtiles, ((o.uv.y - frame[0])/_ytiles) + (_ytiles - 0.0)/_ytiles));
  192.                    
  193.                 return o;
  194.             }
  195.  
  196.            
  197.  
  198.             static const half numDigits = 0.0;
  199.            
  200.             fixed4 frag(v2f i) : SV_Target
  201.             {                
  202.            
  203.  
  204.                 half dpw = numDigits + 1.5;
  205.                
  206.  
  207.                 half dw = 1.0/(dpw);
  208.                
  209.                 int digit = -1;
  210.                 digit += step(dw, i.uv.x)*step(i.uv.x, 2.0*dw)*(i.digits[0][0] + step(6.9,i.digits[2][2]));
  211.                 digit += step(2.0*dw, i.uv.x)*step(i.uv.x, 3.0*dw)*(i.digits[0][1] + step(5.9,i.digits[2][2]));
  212.                 digit += step(3.0*dw, i.uv.x)*step(i.uv.x, 4.0*dw)*(i.digits[0][2] + step(4.9,i.digits[2][2]));
  213.                 digit += step(4.0*dw, i.uv.x)*step(i.uv.x, 5.0*dw)*(i.digits[0][3] + step(3.9,i.digits[2][2]));
  214.                 digit += step(5.0*dw, i.uv.x)*step(i.uv.x, 6.0*dw)*(i.digits[1][0] + step(2.9,i.digits[2][2]));
  215.                 digit += step(6.0*dw, i.uv.x)*step(i.uv.x, 7.0*dw)*(i.digits[1][1] + step(1.9,i.digits[2][2]));
  216.                 digit += step(7.0*dw, i.uv.x)*step(i.uv.x, 8.0*dw)*(i.digits[1][2] + 1);
  217.                 digit += step(8.5*dw, i.uv.x)*step(i.uv.x, 9.5*dw)*(i.digits[1][3] + 1);
  218.                 digit += step(9.5*dw, i.uv.x)*step(i.uv.x, 1.0)*(i.digits[2][0] + 1);
  219.                
  220.                 float digitUvX = frac((i.uv.x - 0.5*dw*step(8.0*dw,i.uv.x))*dpw)*0.1 + 0.1*digit;
  221.                 fixed4 digitColor = step(-0.1, digit)*tex2D(_DigitTex, float2(digitUvX, i.uv.y*0.5 + 0.5))* i.color;
  222.                
  223.                 float minusUvX = frac(i.uv.x*dpw)*0.1;
  224.                 fixed4 minusColor = step(7.0-i.digits[2][2],i.uv.x*dpw)*step(i.uv.x*dpw, 8-i.digits[2][2])*step(0.5,1-i.digits[2][1])
  225.                                     *tex2D(_DigitTex, float2(minusUvX, i.uv.y*0.5))* i.color;
  226.                
  227.                 float decUvX = frac(i.uv.x*dpw)*0.1+dw;
  228.                 fixed4 decColor = tex2D(_DigitTex, float2(decUvX, i.uv.y*0.5))* i.color;
  229.                
  230.                 fixed4 hud = tex2D(_HudTex,i.uv);
  231.                 fixed4 hud2 = tex2D(_HudTex2,i.uv);
  232.                 fixed4 flipbook = tex2D(_FlipTex,i.uv);
  233.                
  234.                 fixed4 finalcolor = fixed4(0,0,0,0);
  235.                 finalcolor += (i.type == 1 || i.type == 4)*minusColor;
  236.                 finalcolor += (i.type == 1 || i.type == 4)*digitColor;
  237.                 finalcolor += (i.type == 1 || i.type == 4)*step(8.0*dw, i.uv.x)*step(i.uv.x,8.5*dw)*decColor;
  238.                 finalcolor += (i.type == 0)*hud*_TintMain;
  239.                 finalcolor += (i.type == 2)*hud*_TintGiz;
  240.                 finalcolor += (i.type == 6)*hud2*_TintScnd;
  241.                 finalcolor += (i.type == 7)*flipbook*_TintFlip;
  242.                 clip(finalcolor.a - _clip);
  243.                 return finalcolor;
  244.             }
  245.             ENDCG
  246.         }
  247.     }
  248. }
Advertisement
Add Comment
Please, Sign In to add comment