diff --git a/libweston/renderer-gl/fragment.glsl b/libweston/renderer-gl/fragment.glsl index 1a8b1ef8..7361df71 100644 --- a/libweston/renderer-gl/fragment.glsl +++ b/libweston/renderer-gl/fragment.glsl @@ -127,14 +127,17 @@ uniform sampler2D tex2; uniform float view_alpha; uniform vec4 unicolor; +#define MAX_CURVE_PARAMS 10 +#define MAX_CURVESET_PARAMS (MAX_CURVE_PARAMS * 3) + uniform HIGHPRECISION sampler2D color_pre_curve_lut_2d; uniform HIGHPRECISION vec2 color_pre_curve_lut_scale_offset; -uniform HIGHPRECISION float color_pre_curve_params[30]; +uniform HIGHPRECISION float color_pre_curve_params[MAX_CURVESET_PARAMS]; uniform bool color_pre_curve_clamped_input; uniform HIGHPRECISION sampler2D color_post_curve_lut_2d; uniform HIGHPRECISION vec2 color_post_curve_lut_scale_offset; -uniform HIGHPRECISION float color_post_curve_params[30]; +uniform HIGHPRECISION float color_post_curve_params[MAX_CURVESET_PARAMS]; uniform bool color_post_curve_clamped_input; #if DEF_COLOR_MAPPING == SHADER_COLOR_MAPPING_3DLUT @@ -245,19 +248,22 @@ powlin(float x, float g, float a, float b, float c, float d) } float -sample_color_pre_curve_linpow(float x, compile_const int color_channel) +sample_linpow(float params[MAX_CURVESET_PARAMS], bool must_clamp, + float x, compile_const int color_channel) { float g, a, b, c, d; - /* For each color channel we have 10 parameters. The params are - * linearized in an array of size 30, in RGB order. */ - g = color_pre_curve_params[0 + (color_channel * 10)]; - a = color_pre_curve_params[1 + (color_channel * 10)]; - b = color_pre_curve_params[2 + (color_channel * 10)]; - c = color_pre_curve_params[3 + (color_channel * 10)]; - d = color_pre_curve_params[4 + (color_channel * 10)]; + /* + * For each color channel we have MAX_CURVE_PARAMS parameters. + * The parameters for the three curves are stored in RGB order. + */ + g = params[0 + color_channel * MAX_CURVE_PARAMS]; + a = params[1 + color_channel * MAX_CURVE_PARAMS]; + b = params[2 + color_channel * MAX_CURVE_PARAMS]; + c = params[3 + color_channel * MAX_CURVE_PARAMS]; + d = params[4 + color_channel * MAX_CURVE_PARAMS]; - if (color_pre_curve_clamped_input) + if (must_clamp) x = clamp(x, 0.0, 1.0); /* We use mirroring for negative input values. */ @@ -267,6 +273,15 @@ sample_color_pre_curve_linpow(float x, compile_const int color_channel) return linpow(x, g, a, b, c, d); } +vec3 +sample_linpow_vec3(float params[MAX_CURVESET_PARAMS], bool must_clamp, + vec3 color) +{ + return vec3(sample_linpow(params, must_clamp, color.r, 0), + sample_linpow(params, must_clamp, color.g, 1), + sample_linpow(params, must_clamp, color.b, 2)); +} + float sample_color_pre_curve_powlin(float x, compile_const int color_channel) { @@ -290,29 +305,6 @@ sample_color_pre_curve_powlin(float x, compile_const int color_channel) return powlin(x, g, a, b, c, d); } -float -sample_color_post_curve_linpow(float x, compile_const int color_channel) -{ - float g, a, b, c, d; - - /* For each color channel we have 10 parameters. The params are - * linearized in an array of size 30, in RGB order. */ - g = color_post_curve_params[0 + (color_channel * 10)]; - a = color_post_curve_params[1 + (color_channel * 10)]; - b = color_post_curve_params[2 + (color_channel * 10)]; - c = color_post_curve_params[3 + (color_channel * 10)]; - d = color_post_curve_params[4 + (color_channel * 10)]; - - if (color_post_curve_clamped_input) - x = clamp(x, 0.0, 1.0); - - /* We use mirroring for negative input values. */ - if (x < 0.0) - return -linpow(-x, g, a, b, c, d); - - return linpow(x, g, a, b, c, d); -} - float sample_color_post_curve_powlin(float x, compile_const int color_channel) { @@ -348,10 +340,9 @@ color_pre_curve(vec3 color) color_pre_curve_lut_scale_offset, color); } else if (c_color_pre_curve == SHADER_COLOR_CURVE_LINPOW) { - ret.r = sample_color_pre_curve_linpow(color.r, 0); - ret.g = sample_color_pre_curve_linpow(color.g, 1); - ret.b = sample_color_pre_curve_linpow(color.b, 2); - return ret; + return sample_linpow_vec3(color_pre_curve_params, + color_pre_curve_clamped_input, + color); } else if (c_color_pre_curve == SHADER_COLOR_CURVE_POWLIN) { ret.r = sample_color_pre_curve_powlin(color.r, 0); ret.g = sample_color_pre_curve_powlin(color.g, 1); @@ -399,10 +390,9 @@ color_post_curve(vec3 color) color_post_curve_lut_scale_offset, color); } else if (c_color_post_curve == SHADER_COLOR_CURVE_LINPOW) { - ret.r = sample_color_post_curve_linpow(color.r, 0); - ret.g = sample_color_post_curve_linpow(color.g, 1); - ret.b = sample_color_post_curve_linpow(color.b, 2); - return ret; + return sample_linpow_vec3(color_post_curve_params, + color_post_curve_clamped_input, + color); } else if (c_color_post_curve == SHADER_COLOR_CURVE_POWLIN) { ret.r = sample_color_post_curve_powlin(color.r, 0); ret.g = sample_color_post_curve_powlin(color.g, 1);