2
\$\begingroup\$

I'm writing a shader and I just wanna ask if it's possible to get the ID of the vertex that is currently being manipulated. I read something about gl_vertexID, but I couldn't find out if that is something I can use.

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

I don't seem to have much trouble doing this. Here's a sample vert shader input struct:

struct VS_INPUT
{
 float4 pos        : POSITION;
 float3 norm       : NORMAL;
 float2 uv         : TEXCOORD0;
 float4 col        : COLOR0;
 uint   id         : SV_VertexID;
};

Good luck! I hope it helps!

\$\endgroup\$
0
\$\begingroup\$

Answer: Added the vertexIDs in a second uv(set x value to the id) channel in the mesh(from my c# code), and then in the shader I could use the ids as I needed, example:

     void function(inout appdata_full v) 
     {     
          int vertexID = v.texcoord1[0]; 
          ...
     }
\$\endgroup\$
2
  • \$\begingroup\$ Will do! Have to wait 20 hours apparently. Thanks for the reminder tho :) \$\endgroup\$
    – sebbn
    Aug 10, 2014 at 22:08
  • 1
    \$\begingroup\$ VertexID is auto-generated as a system variable in Direct3D Shader Model 4.0 (Feature Level 10.0 hardware or later), but for older shader models you have to generate it yourself as was done in this answer. \$\endgroup\$ Aug 11, 2014 at 4:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .