Skip to content

Instantly share code, notes, and snippets.

@turbohermit
Last active September 1, 2017 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turbohermit/b6a64b2b1da650cc8194bc08afaef2c8 to your computer and use it in GitHub Desktop.
Save turbohermit/b6a64b2b1da650cc8194bc08afaef2c8 to your computer and use it in GitHub Desktop.
Vertex gradient shader that interpolates between 2 colours based on every vertex Y position.
Shader "Vertex/Gradient" {
Properties {
_TopColor("Top Color", Color) = (1,1,1,1)
_BottomColor ("Bottom Color", Color) = (1,1,1,1)
_Scale ("Scale", Float) = 1
_Offset ("Offset", Float) = 1
}
SubShader {
Tags {"Queue"="Transparent" "RenderType"="Transparent" "LightMode"="ForwardBase"}
LOD 100
Lighting Off
ZWrite On
Blend SrcAlpha OneMinusSrcAlpha
Cull Off
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
fixed4 _TopColor;
fixed4 _BottomColor;
fixed _Scale;
fixed _Offset;
struct v2f {
float4 pos : SV_POSITION;
fixed4 col : COLOR;
};
v2f vert (appdata_full v)
{
v2f o;
o.pos = UnityObjectToClipPos (v.vertex);
o.col = lerp(_BottomColor,_TopColor, (v.vertex.y * _Scale) + _Offset);
return o;
}
float4 frag (v2f i) : COLOR {
float4 c = i.col;
return c;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment