Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "NEK0/Cam"
- {
- Properties
- {
- [NoScaleOffset] _HudTex2 ("CAM", 2D) = "white" {}
- [HideInInspector] _TintScnd ("Secondary HUD Tint", Color) = (1,1,1,1)
- [HideInInspector] _TintFlip (".", Color) = (1,1,1,0)
- [HideInInspector]_xtiles ("Flip-book Columns", float) = 1
- [HideInInspector]_ytiles ("Flip-book Rows", float) = 1
- [HideInInspector][NoScaleOffset] _DigitTex ("Digits (RGB)", 2D) = "white" {}
- _offset ("Hud offset", Vector) = (0.0, 0.0, 0.0, 0.0)
- [HideInInspector] _range ("Range ", Float) =3
- [HideInInspector][Toggle] _Hide ("Hide from other players", int) = 1
- [HideInInspector] _scale ("Hud's scale in the transform tab", float) = 1.0
- }
- SubShader
- {
- Tags { "Queue"="Transparent+99999" "RenderType"="Transparent" }
- LOD 100
- // Cull off
- Zwrite Off
- Ztest Always
- Blend SrcAlpha OneMinusSrcAlpha
- Pass {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- struct v2f
- {
- float2 uv : TEXCOORD0;
- int3x4 digits : TEXCOORD1;
- int type : TEXCOORD5;
- float2 ang: TEXCOORD6;
- float4 pos : SV_POSITION;
- float4 color : COLOR;
- };
- sampler2D _DigitTex;
- sampler2D _HudTex;
- sampler2D _HudTex2;
- sampler2D _FlipTex;
- sampler2D _CompTex;
- half4 _DigitTex_ST;
- fixed4 _TintMain;
- fixed4 _TintScnd;
- fixed4 _TintComp;
- fixed4 _TintFlip;
- fixed4 _TintGiz;
- fixed4 _TintColor;
- fixed4 _TintColor2;
- fixed4 _TintColorX;
- fixed4 _TintColorY;
- fixed4 _TintColorZ;
- half _convergence;
- half _range;
- half _CompRad;
- half4 _offset;
- half4 _aoffset;
- float _clip;
- half _xtiles;
- half _ytiles;
- half _frame;
- int _Hide;
- half _scale;
- float is_eq(float num, float comp)
- {
- return step(comp-0.01, num)*step(num,comp+0.01);
- }
- int display_type(float4 color)
- {
- int type = 0;
- type += step(0.99, color.r)*step(color.g,0.01)*step(color.b,0.01)
- + step(0.99, color.b)*step(color.r,0.01)*step(color.g,0.01)
- + step(0.99, color.g)*step(color.r,0.01)*step(color.b,0.01);
- type += 2*step(color.r + color.g, 0.01)*step(color.b, 0.55)*step(0.45,color.b);
- type += 3*step(color.r + color.b, 0.01)*step(color.g, 0.55)*step(0.45,color.g);
- type += 4*step(color.r + color.g + color.b, 0.01);
- type += 5*step(color.b + color.g, 0.01)*step(color.r, 0.55)*step(0.45,color.r);
- type += 6*is_eq(color.r, 0.5)*is_eq(color.g, 0.5)*step(color.b, 0.01);
- type += 7*is_eq(color.r, 0.5)*is_eq(color.b, 0.5)*step(color.g, 0.01);
- return type;
- }
- int3x4 display_digits(float displayValue, int type, int3x4 digits)
- {
- }
- v2f vert(float4 pos : POSITION, float2 uv : TEXCOORD0, float4 color : COLOR)
- {
- v2f o;
- o.type = display_type(color);
- float3 WPos = mul(unity_ObjectToWorld, float4(0,0,0,1)).xyz;
- float3 coords = WPos*color.rgb;
- float displayValue = 0;
- displayValue += (o.type == 1)*(coords.x + coords.y + coords.z);
- displayValue += (o.type == 4)*unity_DeltaTime[3];
- displayValue += (o.type == 5)*_Time[1];
- #if UNITY_SINGLE_PASS_STEREO
- float ipd = _convergence;
- float4 abspos = pos + float4(ipd*(0.5-unity_StereoEyeIndex), 0, 0, 0);
- float4 camPos = mul(unity_CameraToWorld, float4(_aoffset.xyz,1) + float4(ipd*(0.5-unity_StereoEyeIndex), 0, 0, 0));
- #else
- float ipd = 0.0;
- float4 abspos = pos;
- float4 camPos = mul(unity_CameraToWorld, float4(_aoffset.xyz,2) );
- #endif
- abspos.xyz += _offset.xyz;
- float4 worldPos = mul(unity_CameraToWorld, abspos); // Transform View to World
- float4 objectPos = mul(unity_WorldToObject, worldPos); // Transform World To Object
- float4 axisPos = mul(UNITY_MATRIX_V, float4(pos.xyz*_aoffset.w,1) + float4(camPos.xyz,2));
- axisPos = mul(UNITY_MATRIX_P,axisPos);
- o.pos = UnityObjectToClipPos(objectPos)*(step(o.type,3.9) + step(2.9,o.type)) + (o.type == 2)*axisPos;
- float4 dist = distance(_WorldSpaceCameraPos, mul(unity_ObjectToWorld, float4(0,0,0,1)));
- o.pos = o.pos - o.pos*step(_range, dist);
- half LocalScale = length(mul(unity_ObjectToWorld, float4(0,0,2/_scale,0)));
- o.pos = o.pos - o.pos*step(0.02, LocalScale)*(_Hide == 1);
- o.color = float4(0,0,0,0);
- o.color += (o.type == 1)*(color.r*_TintColorX + color.g*_TintColorY + color.b*_TintColorZ);
- o.color += _TintColor*(o.type == 4);
- o.color += _TintColor2*(o.type == 5);
- #if UNITY_SINGLE_PASS_STEREO
- float3 p1 = mul(unity_StereoCameraToWorld[0], float4(0,0,0,0));
- float3 p2 = mul(unity_StereoCameraToWorld[0], float4(0,0,0,0));
- #else
- float3 p1 = mul(unity_CameraToWorld, float4(0,0,0,0));
- float3 p2 = mul(unity_CameraToWorld, float4(0,0,0,0));
- #endif
- float3 forward = p2-p1;
- forward.xz = normalize(forward.xz);
- o.ang[1] = sign(forward.x)*acos(forward.z) ;
- float2 origin_dir = normalize(p2.xz);
- o.ang[1] = sign(origin_dir.x)*acos(origin_dir.y);
- o.uv = TRANSFORM_TEX(uv, _DigitTex);
- half2 frame = half2(floor(fmod(_frame, _xtiles)), floor(fmod((_frame/float(_xtiles)), _ytiles)));
- o.uv += (o.type==0)*(-o.uv + float2((o.uv.x + frame[0])/_xtiles, ((o.uv.y - frame[0])/_ytiles) + (_ytiles - 0.0)/_ytiles));
- return o;
- }
- static const half numDigits = 0.0;
- fixed4 frag(v2f i) : SV_Target
- {
- half dpw = numDigits + 1.5;
- half dw = 1.0/(dpw);
- int digit = -1;
- digit += step(dw, i.uv.x)*step(i.uv.x, 2.0*dw)*(i.digits[0][0] + step(6.9,i.digits[2][2]));
- 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]));
- 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]));
- 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]));
- 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]));
- 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]));
- digit += step(7.0*dw, i.uv.x)*step(i.uv.x, 8.0*dw)*(i.digits[1][2] + 1);
- digit += step(8.5*dw, i.uv.x)*step(i.uv.x, 9.5*dw)*(i.digits[1][3] + 1);
- digit += step(9.5*dw, i.uv.x)*step(i.uv.x, 1.0)*(i.digits[2][0] + 1);
- float digitUvX = frac((i.uv.x - 0.5*dw*step(8.0*dw,i.uv.x))*dpw)*0.1 + 0.1*digit;
- fixed4 digitColor = step(-0.1, digit)*tex2D(_DigitTex, float2(digitUvX, i.uv.y*0.5 + 0.5))* i.color;
- float minusUvX = frac(i.uv.x*dpw)*0.1;
- 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])
- *tex2D(_DigitTex, float2(minusUvX, i.uv.y*0.5))* i.color;
- float decUvX = frac(i.uv.x*dpw)*0.1+dw;
- fixed4 decColor = tex2D(_DigitTex, float2(decUvX, i.uv.y*0.5))* i.color;
- fixed4 hud = tex2D(_HudTex,i.uv);
- fixed4 hud2 = tex2D(_HudTex2,i.uv);
- fixed4 flipbook = tex2D(_FlipTex,i.uv);
- fixed4 finalcolor = fixed4(0,0,0,0);
- finalcolor += (i.type == 1 || i.type == 4)*minusColor;
- finalcolor += (i.type == 1 || i.type == 4)*digitColor;
- finalcolor += (i.type == 1 || i.type == 4)*step(8.0*dw, i.uv.x)*step(i.uv.x,8.5*dw)*decColor;
- finalcolor += (i.type == 0)*hud*_TintMain;
- finalcolor += (i.type == 2)*hud*_TintGiz;
- finalcolor += (i.type == 6)*hud2*_TintScnd;
- finalcolor += (i.type == 7)*flipbook*_TintFlip;
- clip(finalcolor.a - _clip);
- return finalcolor;
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment