Quantcast
Channel: Question and Answer » shaders
Viewing all articles
Browse latest Browse all 64

How to apply individual colours in a fragment shader?

$
0
0

I’m trying to write my own shader. Within the target mesh I have assigned the following attributes in a script:

 mesh.vertices = points;
 mesh.colors = colours; //Each element of the array hold a Color value
 mesh.SetIndices(indecies, MeshTopology.Points, 0);

My shader code looks like this

Shader "Cosmos_Vertex" {
    Pass{
        CGPROGRAM

        #pragma vertex vert 
        #pragma fragment frag

        float4 vert(float4 vertexPos : POSITION) : SV_POSITION{
            return mul(UNITY_MATRIX_MVP, vertexPos); 
        }

        float4 frag(void) : COLOR {
            return float4(1.0, 0.0, 0.0, 1.0);
        }
        ENDCG
    }
  }
}

At the moment the colours for the vertices is set to red. How would I go about colouring each vertex to its correlated colour?


Viewing all articles
Browse latest Browse all 64

Latest Images

Trending Articles





Latest Images