look up table

Started by
2 comments, last by superpig 18 years, 9 months ago
Hello, I am simulating corrosion with particles. I adjust the color of a particle according to his life time. If a particle is dead, it get black and i use alpha channel to simulate holes in the surface. But how can i use a lookup table, to find colors according to the life time of a particle? I got the colors from real life images of corrosion. According to his lifetime i have to choose one of them. How longer a particle lives, how darker brown it get.
Advertisement
The easiest way to do it is to use a 1D texture. You create your lookup table as a texture 1 pixel high by N pixels across, going from initial time at the left to 'maximum' time at the right (the end of your table). When rendering, divide the life of your particle by the maximum time represented by your texture, and use the resulting 0..1 value as a texture coordinate. You get interpolation between neighbouring entries for free which can be quite nice.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

If i understand it correctly: i just have to put my N colors in an 1xN array.
Yup, basically. That's all a texture really is, after all - an array of colours.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

This topic is closed to new replies.

Advertisement