arcade icon indicating copy to clipboard operation
arcade copied to clipboard

Store Sprite Colors, and all others, as 4x floats, not 0-255 ints

Open cspotcode opened this issue 2 years ago • 3 comments

Enhancement request:

What should be added/changed?

BasicSprite._color should be stored as floats internally, not as ints from 0 to 255.

What would it help with?

A list of reasons discussed here: https://discord.com/channels/458662222697070613/458662458198982676/1110348630956720158

Color manipulation within python is easier and has greater precision w/floats. Useful for smoothly lerping between colors using float math instead of imprecise int math.

Easier for consumers to think about. More performant(?) since we never need to convert back and forth between int and float, only copy the float values to the GPU. A bit more data transfer.

Shaders already convert the ints to floats anyway.

cspotcode avatar May 22 '23 23:05 cspotcode

Related to #1772

cspotcode avatar May 22 '23 23:05 cspotcode

I really want these to be floats because of the flexibility this adds, but I'm not entirely sure yet if this is worth it. At least I don't think there's a fast way to have backwards compatible support for both byte and float colors. Worst case it could be something we consider futher down the line. Some more thinking is needed here.

We do have some places were float colors are used, so having the type certainly doesn't hurt.

einarf avatar May 26 '23 02:05 einarf

I see three orthogonal concerns:

  1. lerping and intermediate generation, also solvable by generators or other internal error-tracking approaches
  2. Speed comparisons of color types & annotations (NamedTuple vs Tuple, protocol vs tuple subclass, etc), answerable with benchmarks
  3. Internal storage / object.color_float property interaction with object.color

The most urgent issue for me is the last one since it determines whether I should continue work on #1772.

  1. Do we have an efficient & clean way to handle lazily calculating the RGBA255 object.color property?
  2. In the absence of anything better, is object._color_dirty + properties acceptable?

pushfoo avatar May 28 '23 06:05 pushfoo