• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Сolor transition

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1Yura  Members

Posted 02 January 2013 - 07:09 AM

I want to make color transition from one point to another. By default, when I have one red point and one blue point, in the middle of the connecting line, I have violet. But is it possible to make color transition from red to blue, using different colors?

I have a rectangle, which consists of 4 points. 2 points are red and 2 are blue.

this is color transition buy default

and this is what I want to do

### #2Ashaman73  Members

Posted 02 January 2013 - 09:24 AM

The easiest way to do this is to use some kind of lookup table. Determine an alpha value (0..1) on the x axis and use this alpha value to look up the mapped color in a 1d lookup table. This can be done on the GPU using some simple shader.

Edited by Ashaman73, 02 January 2013 - 09:25 AM.

Ashaman

### #3NewDisplayName  Members

Posted 02 January 2013 - 09:38 AM

To add to above solution, it isn't possible to "average" out the colors the way you are trying to achieve it in the colorbar fashion. So you do need separate buffer for each bar and use a color value for that. Ofcourse, getting the value of color to fill up each bar is easier to achieve by simply taking the leftmost and rightmost bar's color and breaking up into N components for N bars using Arithmetic progression logic or whatever suits you.

### #4C0lumbo  Members

Posted 02 January 2013 - 12:37 PM

I would just use a texture lookup, i.e. don't even bother providing colours for your vertices, just provide UV coordinates into a texture containing the colours you want with the colour steps you want.

If you didn't actually want the colour to step like the second image in the original post, then an alternative might be to convert your RGB values into HSV values in the vertex shader. They'll then interpolate through the hues, and you can convert back in your pixel shader. I suspect the texture approach is more straightforward.

### #5Yura  Members

Posted 03 January 2013 - 03:10 AM

I have VertexBuffer filled with points (position and color).
Determining table is a good idea, but how to implement it to primitive? To many primitives - possible, but how to fill one (or two, as in picture) triangles with so much colors?
1 rectangle = 2 triangles

Edited by Yura, 09 January 2013 - 07:26 AM.

### #6Yura  Members

Posted 03 January 2013 - 06:46 AM

The easiest way to do this is to use some kind of lookup table. Determine an alpha value (0..1) on the x axis and use this alpha value to look up the mapped color in a 1d lookup table. This can be done on the GPU using some simple shader.

Please, tell me more details.  Maybe, you have some example how to do this?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.