Hacker News new | ask | show | jobs
by MyMemoryfails 20 days ago
As game dev, i never understood why floats are used to present colors? Isn't integers better? The issues which this article mentioned wouldn't exist.

I can only think its due integers having undefined behavior what happens on overflow, usually its wrapping but not always.

3 comments

It is because light(colors) is a fundamentally exponential process and floats are also a fundamentally exponential process and as such the two are a good match for one another.
The problem would still exist, for example when you want to multiply colors which is common in lighting calculations - with integers you would need to divide by either 255 or 256 after such an operation. Which floats you only need to make that decision when converting to/from float representation, which is part of what makes them convenient.
Floats are better for calculating lighting. I would think some GPUs are probably also more optimized for float processing than ints.