r869: Merge 2.1:
[cinelerra_cv/mob.git] / plugins / gamma / aggregated.h
blobb947834b5b024047ea2a23525cf6040aebc1fa18
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"
9 "{\n"
10 " return gl_FragColor;\n"
11 "}\n";
13 static char *gamma_get_pixel2 =
14 "uniform sampler2D tex;\n"
15 "vec4 gamma_get_pixel()\n"
16 "{\n"
17 " return texture2D(tex, gl_TexCoord[0].st);\n"
18 "}\n";
20 static char *gamma_pow_frag =
21 "float my_pow(float x, float y, float max)\n"
22 "{\n"
23 " return (x > 0.0) ? pow(x * 2.0 / max, y) : 0.0;\n"
24 "}\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"
30 "void main()\n"
31 "{\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"
37 "}\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"
43 "void main()\n"
44 "{\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"
52 "}\n";
54 #define GAMMA_COMPILE(shader_stack, current_shader, aggregate_interpolation) \
55 { \
56 if(aggregate_interpolation) \
57 shader_stack[current_shader++] = gamma_get_pixel1; \
58 else \
59 shader_stack[current_shader++] = gamma_get_pixel2; \
61 switch(get_output()->get_color_model()) \
62 { \
63 case BC_YUV888: \
64 case BC_YUVA8888: \
65 shader_stack[current_shader++] = gamma_pow_frag; \
66 shader_stack[current_shader++] = gamma_yuv_frag; \
67 break; \
68 default: \
69 shader_stack[current_shader++] = gamma_pow_frag; \
70 shader_stack[current_shader++] = gamma_rgb_frag; \
71 break; \
72 } \
75 #define GAMMA_UNIFORMS(frag) \
76 { \
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); \
90 #endif