This repository has been archived on 2024-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
snakeinabox/Assets/Materials/Snake.shader
2020-07-09 11:41:01 -07:00

107 lines
No EOL
2.3 KiB
Text

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 = fixed4(1, 1, 1, 1);
return i;
}
// 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
i.color *= 1 - ((half)id / 729);
if (id == _JustAte)
{
i.color += fixed4(1,1,1,1) * (1 - clamp((half)id / 27, 0, 1));
}
// Alpha Fix
i.color.a = 1;
}
return i;
}
fixed4 FragmentProgram (Interpolators i) : SV_TARGET
{
return i.color;
}
ENDCG
}
}
}