Present a float as a unique color

Hi all,

I would like to cast a float to a vec3 in such a way that it represents a unique color. In OpenGL you could use glColor3ubv or a similar function.

Does anyone know how to solve this in GLSL?

Kind regards,

Roy

I would like to cast a float to a vec3 in such a way that it represents a unique color. In OpenGL you could use glColor3ubv or a similar function.
That function doesn’t turn it into a unique color. I’m not sure what you mean by a “unique” color to begin with. A color that isn’t being used by something?

You can not access the real bits of the float, so I guess it will be really hard.
It probably depends of the range of your floats, and how you want to represent this value in the RGB8 space.

Could you put the float into a 1x1 texture, internal format=GL_RGB, type=GL_FLOAT and then use a sampler
to access it?
If you post the context of the problem you’re trying to solve I’m sure someone will have a idea.
–Stuart.

Thanks for the replies. I have a set of particles, which I want to assign each a different color. In that sense it must be unique for each particles.

Each particle already has a number assigned, which I would like to use to generate the color vector. However, as ZbuffeR statet, it is not possible to access the actual bits.

Any ideas?

So your float value is in fact an integer ?
What about (pseudocode):

int particleid = int(value)
int r = particleid / 256 / 256
int g = (particleid - r * 256 * 256) / 256
int b = (particleid - r * 256 * 256 - g * 256)

vec3 color = vec3(r,g,b);
color = color / 256.0

Right, that seems fairly good. Probably I was thinking in a harder direction than necessary.

Thanks for the help :slight_smile:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.