How to render a set of points with colors?
I want to render a set of points with colors in unity and I have followed this example http://www.kamend.com/2014/05/rendering-a-point-cloud-inside-unity/ to generate points and their colors randomly.
//C#
public class PointCloud : MonoBehaviour
{
private Mesh mesh;
int numPoints = 60000;
// Use this for initialization
void Start () {
mesh = new Mesh();
GetComponent<MeshFilter>().mesh = mesh;
CreateMesh();
}
void CreateMesh() {
Vector3[] points = new Vector3[numPoints];
int[] indecies = new int[numPoints];
Color[] colors = new Color[numPoints];
for(int i=0;i<points.Length;++i) {
points[i] = new Vector3(Random.Range(-10,10), Random.Range (-10,10), Random.Range (-10,10));
indecies[i] = i;
colors[i] = new Color(Random.Range(0.0f,1.0f),Random.Range (0.0f,1.0f),Random.Range(0.0f,1.0f),1.0f);
}
mesh.vertices = points;
mesh.colors = colors;
mesh.SetIndices(indecies, MeshTopology.Points,0);
}
}
// Shader
Shader "Custom/VertexColor" {
SubShader
{
Pass
{
LOD 200
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
struct VertexInput
{
float4 v : POSITION;
float4 color: COLOR;
};
struct VertexOutput
{
float4 pos : SV_POSITION;
float4 col : COLOR;
};
VertexOutput vert(VertexInput v)
{
VertexOutput o;
o.pos = UnityObjectToClipPos(v.v);
o.col = v.color;
return o;
}
float4 frag(VertexOutput o) : COLOR
{
return o.col;
}
ENDCG
}
}
}
Is there anyway to change colors of these points? Since I set colors of these points with a constant values but it does not work.
Comment
Best I can tell, you are setting the colors... to the random values you assign in your array. Why are you asking how to do something you're already doing?
Your answer
