PDA

View Full Version : Mesh with fill and wireframe



Wasabi
07-14-2011, 12:01 PM
I am aware that the simplest and most commonly used method to draw a mesh with both fill and wireframe is by simply running through the geometry twice, altering glPolygonMode().

However, my question is how to make the two runs have different colors. Must each vertex contain two color values, one for the fill and one for the wireframe?

The suggestion I see often is to use two shaders, one for each run. However, these two shaders are going to be exactly the same, only with a different offset to the correct color values. All of their uniforms are the same. This means I'd have to update twice as many uniforms to simply have the wireframe suffer the same transformations as the fill. My shaders are the definition of simple, so wouldn't it be faster (processing-wise) to simply create a boolean uniform in the fragment shader, so that:

//in the frag shader
if(wireframe==0)
gl_FragColor = fill_color;
else
gl_FragColor = wire_color;
or something of the sort?

This would, however, imply in having to send two colors through the shader even though I only end up using one.

So what's better?
- Two identical shader programs (other than the offset of one of the attributes), one for the fill and the other for the wireframe, generating thus twice as many uniforms I have to update each time I change them and having to use glUseProgram();
- One shader with a boolean uniform, with two colors going through it though only one is used;
- Or, which is most likely, I'm doing this entirely wrong and am thus going about this the wrong way.

Ilian Dinev
07-14-2011, 12:40 PM
One shader with a boolean uniform - would be best.

If the total size of uniforms in the shader would be like over 10kB, the best way would be to have the boolean uniform, and put all other uniforms in a UBO (uniform buffer object). (but there access to uniforms might become slightly slower/heavier for the gpu)

Wasabi
07-14-2011, 01:07 PM
Good to hear, because I just refreshed this page after implementing the boolean uniform. Would have hated to see a "boolean uniform? what kind of idiot are you?" comment. :D