Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't believe you can do so directly but you could use the second <code>UV</code> channel to store your IDs. </p> <p>Here is a re-purposed <a href="http://docs.unity3d.com/Documentation/Manual/ShaderTut2.html" rel="nofollow">Unity normal shading example</a> using a "vertex ID" to determine when to apply the normal as a color. </p> <pre><code>Shader "Custom/ColorIdentity" { Properties { //_MainTex ("Base (RGB)", 2D) = "white" {} } SubShader { Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag struct appdata { float4 vertex : SV_POSITION; float3 normal : NORMAL; float4 texCoord2 : TEXCOORD1; }; struct v2f { float4 pos : SV_POSITION; float3 color : COLOR0; }; v2f vert (appdata v) { v2f o; //here is where I read the vertex id, in texCoord2[0] //in this case I'm binning all values &gt; 1 to id 1, else id 0 //that way they can by multiplied against to the vertex normal //to turn color on and off. int vID = (v.texCoord2[0]&gt;1)?1:0; o.pos = mul (UNITY_MATRIX_MVP, v.vertex); o.color = v.normal * vID; //Use normal as color for vertices w/ ids&gt;1 return o; } half4 frag (v2f i) : COLOR { return half4 (i.color, 1); } ENDCG } } Fallback "Diffuse" } </code></pre> <p>Also, here is the dummy script I ginned up to assign completely arbitrary IDs. IDs are assigned based on a vertex's position on the y-axis. The bounds were chosen at random based on the mesh I had handy:</p> <pre><code>public class AssignIdentity : MonoBehaviour { public GameObject LiveObject; // Use this for initialization void Start () { Mesh mesh = LiveObject.GetComponent&lt;MeshFilter&gt;().mesh; Vector3[] vertices = mesh.vertices; Vector2[] uv2s = new Vector2[vertices.Length]; int i = 0; foreach(Vector3 v in vertices){ if(v.y&gt;9.0f || v.y &lt; 4.0){ uv2s[i++] = new Vector2(2,0); } else { uv2s[i++] = new Vector2(1,0); } } mesh.uv2 = uv2s; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload