- Home /
Question by
Cuddl3s · Feb 06, 2018 at 12:37 AM ·
shadersshader programmingshader writing
Change color of a 3D object based on the vertex' y-value
What I'm trying to achieve is creating a shader that colors a mesh using 2 different colors and a progression value. The progression value (from 0 to 1) shows how much of the mesh is colored with the second color. The coloring should be done on one axis, in my case the y-axis. So for example, if the progression value is currently at 0.4, the bottom 40% of the model should be colored with color one, whereas the top 60% use color two. I feel like this should not be that hard, but I can't find a way to get the y-value of a vertex (or better, the normalized y-value) to do something like
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = i.vertex.y > _ColorSwitchProgression ? _Color1 : _Color2;
return col;
}
in my fragment shader. Can someone help out?
Comment