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.
2 Answers
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!
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];
...
}
-
\$\begingroup\$ Will do! Have to wait 20 hours apparently. Thanks for the reminder tho :) \$\endgroup\$– sebbnAug 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