PDA

View Full Version : Triangle Fans and Color Gradients



lasserix
07-04-2012, 03:06 PM
I'm stuck with opengl 1.0 es, since my target is android phones*. However this question regards just triangle fans and colors.

I've generated an array of vertices forming a circular shape, drawing it as a closed triangle fan. I'm not packing my array (will do in the future), so I'm loading my color array separately. My goal is to have a smooth HSV gradient per subsequent triangle of the fan. Which works along the edge; however, towards the center of the triangle fan the color blends to the original color set the first iteration of the loop. So instead of a smooth rainbow per say, each subsequent triangle correctly graduates in color along the edge, but blends to that original color set with the first vertex / origin of the fan.

My question is is there any way to update the color value of the "implicit vertex" (represented by the origin) of each subsequent triangle? Or do I have to use another primitive all together?

If anything is unclear, let me know!

Thanks for any help!

* Android phones support opengles 2.0, however that is near-future work. Also, I'm stuck using only triangle primitives, no quads.

Update:

While not solving the problem above, I used a circular triangle strip, so I could graduate the color of the inner set of vertices. However this makes the vertex buffer at least twice as large, which is undesirable.

carsten neumann
07-06-2012, 12:06 PM
If the color of the central vertex is different in each triangle, it is effectively a different vertex (just the same as with a cube where you repeat each corner position three times, once for each face/normal direction) - I usually think of a vertex as a tuple of attributes, for example (position, normal, color), if any entry in the tuple is different between faces, it's a different vertex. So unless someone else here can think of a neat trick to get around that, you'll have to accept the increase in vertex buffer size and model the circle with individual triangles.
Note however, that if you use individual triangles and assign different colors to the central vertex the edges between triangles become noticeable - especially towards the center of the circle, because there the color of the central vertex dominates.

aqnuep
07-06-2012, 01:42 PM
For what you want to achieve you have to use a triangle strip instead.

Considering you had your vertex positions in the following order: 1,2,3,4,5,6,7,etc. you'll have to use the vertex positions for the triangle strip in the order: 2,1,3,1,4,1,5,1,6,1,7,1,etc.
While for the colors, if you had the following order: 1,2,3,4,5,6,7,etc. (where 2,3,4,etc. is the gradient) then you'll have to use the vertex colors for the triangle strip in the order: 2,2,3,3,4,4,5,5,6,6,7,7,etc.

The reason for this is that you want to have different colors for the center vertex across the object, and that means it has to be a different vertex itself.