Converting colors set at runtime to sRGB

Hi, hope you’re all doing well.

I have recently converted my textures and vertex coloring to sRGB through external scripts. However, I have a lot of manual setColor, setColorScale, etc. calls that are done at runtime.

How would I go about switching these over to the new color space?..there’s quite a lot which is why I’m looking for an automatic way to do this–does such a way exist? If not, what would be the best steps forward?

Thanks all!

If done correctly, this is not required since assets are created using linear space.

sRGB is displayed either on the monitor or through a post-processing effect.

In other words, you don’t need to physically convert textures, since there will be double the brightness if the user’s monitor already displays sRGB mode.

1 Like

I had a feeling I was completely misunderstanding haha. I’ll research more into all of this, thanks!

Here is a good material to study on this concept.

In Panda3D, this is the case it can be done in hardware, in the prc file.
framebuffer-srgb

2 Likes

To convert an sRGB color in range 0-255 to linear floating-point, you can use this function:

from panda3d.core import decode_sRGB_float

# html color #123456
color = (
    decode_sRGB_float(0x12),
    decode_sRGB_float(0x34),
    decode_sRGB_float(0x56),
)

If you already have them in floating point 0.0-1.0 range, you can also pass those directly to the same function; it behaves differently depending on whether you pass it an integer or floating-point number.