1 #ifndef GAMMA_AGGREGATED
2 #define GAMMA_AGGREGATED
4 // Gamma sections performed by other plugins
6 // Functions to get pixel from either previous effect or texture
7 static char *gamma_get_pixel1
=
8 "vec4 gamma_get_pixel()\n"
10 " return gl_FragColor;\n"
13 static char *gamma_get_pixel2
=
14 "uniform sampler2D tex;\n"
15 "vec4 gamma_get_pixel()\n"
17 " return texture2D(tex, gl_TexCoord[0].st);\n"
20 static char *gamma_pow_frag
=
21 "float my_pow(float x, float y, float max)\n"
23 " return (x > 0.0) ? pow(x * 2.0 / max, y) : 0.0;\n"
26 static char *gamma_rgb_frag
=
27 "uniform float gamma_scale;\n"
28 "uniform float gamma_gamma;\n"
29 "uniform float gamma_max;\n"
32 " vec4 pixel = gamma_get_pixel();\n"
33 " pixel.r = pixel.r * gamma_scale * my_pow(pixel.r, gamma_gamma, gamma_max);\n"
34 " pixel.g = pixel.g * gamma_scale * my_pow(pixel.g, gamma_gamma, gamma_max);\n"
35 " pixel.b = pixel.b * gamma_scale * my_pow(pixel.b, gamma_gamma, gamma_max);\n"
36 " gl_FragColor = pixel;\n"
39 static char *gamma_yuv_frag
=
40 "uniform float gamma_scale;\n"
41 "uniform float gamma_gamma;\n"
42 "uniform float gamma_max;\n"
45 " vec4 pixel = gamma_get_pixel();\n"
46 YUV_TO_RGB_FRAG("pixel")
47 " pixel.r = pixel.r * gamma_scale * my_pow(pixel.r, gamma_gamma, gamma_max);\n"
48 " pixel.g = pixel.g * gamma_scale * my_pow(pixel.g, gamma_gamma, gamma_max);\n"
49 " pixel.b = pixel.b * gamma_scale * my_pow(pixel.b, gamma_gamma, gamma_max);\n"
50 RGB_TO_YUV_FRAG("pixel")
51 " gl_FragColor = pixel;\n"
54 #define GAMMA_COMPILE(shader_stack, current_shader, aggregate_interpolation) \
56 if(aggregate_interpolation) \
57 shader_stack[current_shader++] = gamma_get_pixel1; \
59 shader_stack[current_shader++] = gamma_get_pixel2; \
61 switch(get_output()->get_color_model()) \
65 shader_stack[current_shader++] = gamma_pow_frag; \
66 shader_stack[current_shader++] = gamma_yuv_frag; \
69 shader_stack[current_shader++] = gamma_pow_frag; \
70 shader_stack[current_shader++] = gamma_rgb_frag; \
75 #define GAMMA_UNIFORMS(frag) \
77 float max = get_output()->get_params()->get("GAMMA_MAX", (float)1); \
78 float gamma = get_output()->get_params()->get("GAMMA_GAMMA", (float)1) - 1.0; \
79 float scale = 1.0 / max; \
80 glUniform1f(glGetUniformLocation(frag, "gamma_scale"), scale); \
81 glUniform1f(glGetUniformLocation(frag, "gamma_gamma"), gamma); \
82 glUniform1f(glGetUniformLocation(frag, "gamma_max"), max); \
83 printf("GAMMA_UNIFORMS %f %f\n", max, gamma); \