by Sajt » Wed May 05, 2010 10:27 pm
The way hardware rendering works (using vertex arrays) is, understandably, not built with fast flat-shading in mind.
A triangle is defined as three vertex indices. A vertex can have attributes such as position, colour, normal, etc. The triangle cannot contain separate "vertex position" and "vertex colour" indices. When you run a shader, first the vertices are set up, then the fragment shader is run interpolating vertex values across triangles. It's not set up for "triangle attributes".
The only way it could be implemented on the engine would be:
- To split the vertices up at load-time, the same thing that an offline model tool would do, resulting in 3x as many vertices as triangles.
- Draw models not using vertex arrays, which is much slower.
- Possibly some complicated shader trick which could hack in "triangle attributes", but at the cost of speed (both batching overhead and fillrate would suffer).
- Maybe there is some brand-new feature in DX10 or DX11 which allows triangles to have indices to different attributes? I don't know if it would be worth it, if they did...
The fastest solution is the brutest: to give each triangle its very own vertices. Even if those vertices are in the same position as other triangles' vertices, they can have different colour/normal attributes. Yes, you end up with more vertices than you think you should need, but flat-shaded games are usually low-poly anyway so it shouldn't matter.
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.