godot-color-lut-shader
godot-color-lut-shader copied to clipboard
Interpolation not made in linear space colors
I decided to comment here instead of derailing https://gitlab.freedesktop.org/mesa/mesa/issues/1867
I think that instantly converting to sRGB here will lead to a subtle error.
Later you are calling get_interpolated_color
involving these values which are in sRGB color space however get_interpolated_color
assumes linear color space. sRGB is not linear and cannot be interpolated that easily.
Originally posted by @werman in https://github.com/thiagoamendola/godot-color-lut-shader/pull/2
I tried to make a simple correction by making the convert_linear_to_srgb
call only in the final color value but the final image became lighter. It may have something to do with this snippet:
// Get floor and ceil colors and diff from identity lut
vec3 old_color_lut_base = lut_div * old_color.rgb;
vec3 old_color_floor_vec = floor(old_color_lut_base);
vec3 old_color_ceil_vec = ceil(old_color_lut_base);
vec3 old_color_diff = (old_color_floor_vec - old_color_ceil_vec)/lut_div;
vec3 old_color_percentages = get_interp_percent_color(old_color.rgb, old_color_floor_vec/lut_div, old_color_diff);
As those percentages are being generated from sRGB colors, the final conversion won't work properly. It may be necessary to convert old_color.rgb
from sRGB to linear space for the final convert_linear_to_srgb
to work properly.
Also relates to #1
The question is, why do you need to have LUT texture in sRGB format?
As those LUTs will be edited in external image editors, I prefer to deal with linear colorspace only inside the shader. It's advantageous to use sRGB LUTs for better visual guidance while editing and to decrease difficulties when saving and bringing it back to Godot.