1

RBG values are 0-255 integers, so why was float4 chosen as the vector data type?

Seems to me that byte would be the ideal data type for a color in Fuse.

Pete Alvin
  • 4,646
  • 9
  • 39
  • 56

2 Answers2

2

RGB values are only 1-byte (0-255) values in some contexts. There are numerous color spaces in common use which use more or less than 1 byte to repesent colors (such as compact 8bit and 16bit colorspaces, or HDR colorspaces using 16 or even 32 bits per channel). These aren't just theoretical uses, when dealing with images and GL textures they are used.

What's important is that each of these represent a range of values, from 0, no intensity, to 1, full intensity, for that channel. This is why float is used: it's the correct semantic type to represent a normalized range. It's also happens to be what OpenGL, the default graphic backend for Fuse, uses to represent colors.

float has the advantage of being a continuous value, unlike a byte which has discrete increments. This is important for interpolation. Consider animation between two colors, having a linear gradient, changing the opacity, or decreasing saturation; all of these need to be done on a continuous value range, such as float.

float also allows values to go about 1, and below 0. While these cannot be reflected in the final display they play a role during calculations. If you're doing many color operations in sequence you don't want to prematurely clamp your values.

Don't worry about things like memory bandwidth or storage space. Actual stored color values are a miniscule fraction of what occupies memory.

Also, the common hex syntaxes for color notation are supported in Fuse. You can use a simple #FAA for a light red, or #AB74FD80 for a more precise half-transparent color.

edA-qa mort-ora-y
  • 30,295
  • 39
  • 137
  • 267
0

First I'm going to assume that by float you mean a 4-byte value.

  • Four floats take up 4 times as much memory. This is important not just for the space but the amount of time it takes to move the memory around since memory bandwidth is limited.
  • You can't use bit mask operators and shift on floats (well, you can, but it's not common).
  • Most display tech is limited to 16M colors, which is 24-bit RGB. Even if you have a 12-bit or 16-bit/channel display tech, floats still take at least twice as much memory.
  • Not all platforms even have native support for floating point operations.

I could probably keep going but you get the idea.

Krum
  • 460
  • 8
  • 19