Last active
September 1, 2017 10:23
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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