- Home /
Question by
maddFrogg · Apr 07, 2016 at 10:22 AM ·
shadershadersshaderlabvertex shadervertexcolor
Quad vertex color shader
I need a shader that paints the 4 vertexs of a quad, with customizable colors. I already have this shader, which paints vertexs 2 and 2, with a gradient between them (required too in the 4 different vertex color). I have been wondering and have no clue how to make this 2-2 vertex color to 4 vertex colors.
Shader "Custom/GradientWhiteToAlpha" {
Properties{
//_MainTex("Color (RGB) Alpha (A)", 2D) = "white" {}
_ColorTop("Top Color", Color) = (1,1,1,1)
_ColorBot("Bot Color", Color) = (1,1,1,0)
}
SubShader{
Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
LOD 100
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
fixed4 _ColorTop;
fixed4 _ColorBot;
struct v2f {
float4 pos : SV_POSITION;
float4 texcoord : TEXCOORD0;
};
v2f vert(appdata_full v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.texcoord = v.texcoord;
return o;
}
fixed4 frag(v2f i) : COLOR{
fixed4 c = lerp(_ColorTop, _ColorBot, i.texcoord.y) * step(0, i.texcoord.y);
return c;
}
ENDCG
}
}
}
^ This shader result is like this:
The one I'm asking for help would be like this:
Thanks!
gradient.png
(6.7 kB)
ss2016-04-07at121806.jpg
(8.8 kB)
Comment
Your answer
Follow this Question
Related Questions
Local position in vertex shader? 1 Answer
Shaders - changing the vertex color via script 1 Answer
Help me understand stencil shader logic 1 Answer
Fog not working in my Shader~ 0 Answers