PDA

View Full Version : Sharp triangle color transition (FEA results)



devdept
09-14-2008, 01:38 PM
Hi All,

Everybody knows how to draw a triangle with one different color per vertex and obtain a smooth color transition between corners.

What about drawing sharp transition between color separated by isolines inside the single triangle? Take a look at the following image for example: http://www.premea.co.uk/gfx/stress_plot_tbn.jpg

Thanks,

Alberto

ZbuffeR
09-14-2008, 02:25 PM
1D texturing with GL_NEAREST interpolation.
Or use a fragment shader to discretize the interpolated color.
Something in the lines of result_color = (int(STEPS*in_color))/STEPS

devdept
09-16-2008, 12:58 AM
Hi ZbuffeR,

Wow, I would have never think about 1D texturing? Does it give perfect color transitions?

Can you point me to a small tutorial/example that show how to do it?

Thanks so much again,

Alberto

ZbuffeR
09-16-2008, 05:31 AM
By "perfect color transitions", you mean sharp ? yes, with GL_NEAREST interpolation.
you can search the web for "opengl 1D texturing".

In fact it is easy, like classic 2D texturing, with only the first texture coordinate to set for each vertex (glTexCoord1f) :
http://www.opengl.org/sdk/docs/man/xhtml/glTexCoord.xml
Build your custom 1D texture with a single row of colors, with the gradient you want, ranging from texture coordinate 0.0 to 1.0.

devdept
09-16-2008, 05:57 AM
Thanks again ZbuffeR I will try and let you know.

Alberto