// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' Shader "Custom/Snake" { Properties { _Base ("Base", Color) = (0.4, 1, 0.25, 1) _Delta ("Delta", Vector) = (-0.1, 0, 0.05, 1) _Backup ("Backup", Color) = (0.4, 1, 0.25, 1) _DirectionA ("Direction A", Vector) = (0.8, 1, 0.9) _DirectionB ("Direction B", Vector) = (-0.8, -0.7, -0.9) } SubShader { Pass { CGPROGRAM #pragma vertex VertexProgram #pragma fragment FragmentProgram #pragma multi_compile_instancing #pragma target 3.5 // #include "UnityCG.cginc" #include "UnityStandardBRDF.cginc" struct VertexData { fixed4 position : POSITION; fixed3 normal : NORMAL; UNITY_VERTEX_INPUT_INSTANCE_ID fixed4 color : COLOR; }; struct Interpolators { fixed4 position : SV_POSITION; fixed3 normal : TEXCOORD1; fixed4 color : COLOR0; }; int _JustAte, _Flash; fixed4 _Base, _Delta; fixed3 _DirectionA, _DirectionB; Interpolators VertexProgram (VertexData v) { Interpolators i; UNITY_SETUP_INSTANCE_ID(v); int id = 0; #ifdef UNITY_INSTANCING_ENABLED id = unity_InstanceID; #endif i.position = UnityObjectToClipPos(v.position); i.normal = UnityObjectToWorldNormal(v.normal); i.color = v.color; if (_Flash > 0) { i.color = v.color = fixed4(1, 1, 1, 1); // return i; } fixed3 worldPos = mul(unity_ObjectToWorld, v.position).xyz; fixed3 viewDir = normalize(UnityWorldSpaceViewDir(worldPos)); fixed4 rimColor = fixed4(1, 1, 1, 1); fixed rimStr = 1; // if mesh = snake green (for snake head) if (i.color.g > 0.5 && i.color.r < 0.5) { // Base Color i.color = fixed4(0, 0, 0, 1); // Complimentary Lights i.color += _Base * clamp(dot(i.normal, _DirectionA), 0, 1); i.color += (_Base + _Delta) * clamp(dot(i.normal, _DirectionB), 0, 1); // Rings if ((id / 1.5) % 2 == 0) { i.color.r *= 1 + 0.8 * (1 - clamp((half)id / 27, 0, 1)); } // Decay float decay = 1 - ((half)id / 729); i.color *= decay; if (id == _JustAte) { i.color += fixed4(1,1,1,1) * (1 - clamp((half)id / 27, 0, 1)); } // Alpha Fix i.color.a = 1; // view lighting for depth clarity fixed camDist = distance(worldPos / 7, -normalize(_WorldSpaceCameraPos)); // camDist = 30 - camDist; // clamp(0 + camDist / 20, 0, 1); rimStr = clamp(camDist, 0, 1); i.color = lerp(fixed4(0.26, 0.2, 0.23, 1), i.color, rimStr); rimColor = fixed4(1, 0.95, 0.75, 1); rimStr *= decay; } // Rim lighting fixed rim = 1.0 - saturate(dot (normalize(viewDir), i.normal)); i.color = lerp(i.color, rimColor, rim * rim * rim * rimStr); if (v.color.r == 1 && v.color.g == 1 && v.color.b == 1) { fixed s = (1 + sin(_Time.x * 800)) / 2; fixed3 strobe = normalize(fixed3(1 - s, s, 1 - s)); i.color = fixed4(strobe, 1); } return i; } fixed4 FragmentProgram (Interpolators i) : SV_TARGET { return i.color; } ENDCG } } }