Hi everyone, I try to color the faces of my hexagon.
My problem it colors the hexagon vertices and then interpolate the color… I would like to color each face with a different color and not blend them.
My code:
using UnityEngine;
using System.Collections;
public class SetCubeColor : MonoBehaviour {
public Shader shaders;
// Use this for initialization
void Start()
{
Mesh mesh = GetComponent<MeshFilter>().mesh;
GetComponent<MeshRenderer>().material = new Material(shaders);
Vector3[] vertices = mesh.vertices;
Debug.Log("taille vercitces, MMMMMMMMMMMMMMMMMM" + mesh.colors.Length + " " + mesh.colors32.Length);
Color[] colors = new Color[vertices.Length];
int i = 0;
while (i < vertices.Length)
{
colors[i] = Color.Lerp(Color.blue, Color.green, vertices[i].y);
i++;
}
mesh.colors = colors;
}
}
The shader code:
Shader "VertexColour"
{
SubShader{
Pass{
Fog{ Mode Off }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// vertex input: position, color
struct appdata {
float4 vertex : POSITION;
fixed4 color : COLOR;
};
struct v2f {
float4 pos : SV_POSITION;
fixed4 color : COLOR;
};
v2f vert(appdata v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.color = v.color;
return o;
}
fixed4 frag(v2f i) : SV_Target{ return i.color; }
ENDCG
}
}
}
Current rendering :
I simply want to colorate each face of the hexagon with a different color.
Thanks in advance.