View Full Version : Present a float as a unique color
05-01-2007, 07:02 AM
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?
05-01-2007, 10:41 AM
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?
05-01-2007, 02:58 PM
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.
05-01-2007, 10:40 PM
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.
05-02-2007, 12:21 AM
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.
05-02-2007, 01:40 AM
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
05-02-2007, 03:53 AM
Right, that seems fairly good. Probably I was thinking in a harder direction than necessary.
Thanks for the help :)
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.