简体   繁体   中英

Direct3D 11 - HLSL - Get vertex-index ID

In Direct3D 11, I have a vertex that is used for multiple triangles. In other words, the same vertex is referenced by multiple indices. In my HLSL vertex shader, I want to know which INDEX is being processed. Is there a way to do this? Something similar like the HLSL semantics 'SV_VertexID' or 'SV_PrimitiveID', but for the current index?

To be clear, suppose the index buffer is: Index[3]={10,11,12}; SV_VertexID (using ID3D11DeviceContext::DrawIndexed()) will return 10, 11 and 12. But I want 0, 1, 2.

A counter inside the vertex shader that starts at 0 and is increased each call to the vertex shader would also helpfull. Each frame, this counter should be reset to 0. Is this possible?

Thank you.

I don't think that's possible. By definition the vertex shader runs per vertex, not per index. So if two triangles share a vertex, there's a good chance that the vertex shader will run only once for it, not twice. The second time an index fetches this vertex, the result of vertex shader will be fetched from a cache (the "post transform cache") instead of re-running the shader.

What you can do however, is make all the vertices unique. Then you don't need an index buffer, and the SV_VertexID is basically the index ID (that takes more memory though).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM