Triangle color from code
Members - Reputation: 254
Posted 31 May 2013 - 05:34 PM
The meshes are loaded when the game run and are not know in advance. The meshes uses shared vertices.
Which would be the best way to implement this? Use a geometry shader?
I will use this to display the hitpoints on each armor segment of the hull on a vehicle.
Moderators - Reputation: 20363
Posted 31 May 2013 - 07:37 PM
Shaders are certainly one perfectly acceptable method. If that makes sense in your case, go ahead.
Swapping textures, dynamically recoloring textures, or setting vertex colors directly may also make sense, depending on your setup.
Crossbones+ - Reputation: 2462
Posted 31 May 2013 - 07:38 PM
The obvious option is to read SV_PrimitiveID in the pixel shader, and use that to look up the colour from a texture or constant buffer.
Alternatively avoid the shared vertices, and do the work in the vertex shader. You could then put the colour data in a separate vertex stream. This should be more efficient than doing it in the pixel shader.