00001 #ifndef GAMMA_AGGREGATED
00002 #define GAMMA_AGGREGATED
00003
00004
00005
00006
00007 static char *gamma_get_pixel1 =
00008 "vec4 gamma_get_pixel()\n"
00009 "{\n"
00010 " return gl_FragColor;\n"
00011 "}\n";
00012
00013 static char *gamma_get_pixel2 =
00014 "uniform sampler2D tex;\n"
00015 "vec4 gamma_get_pixel()\n"
00016 "{\n"
00017 " return texture2D(tex, gl_TexCoord[0].st);\n"
00018 "}\n";
00019
00020 static char *gamma_pow_frag =
00021 "float my_pow(float x, float y, float max)\n"
00022 "{\n"
00023 " return (x > 0.0) ? pow(x * 2.0 / max, y) : 0.0;\n"
00024 "}\n";
00025
00026 static char *gamma_rgb_frag =
00027 "uniform float gamma_scale;\n"
00028 "uniform float gamma_gamma;\n"
00029 "uniform float gamma_max;\n"
00030 "void main()\n"
00031 "{\n"
00032 " vec4 pixel = gamma_get_pixel();\n"
00033 " pixel.r = pixel.r * gamma_scale * my_pow(pixel.r, gamma_gamma, gamma_max);\n"
00034 " pixel.g = pixel.g * gamma_scale * my_pow(pixel.g, gamma_gamma, gamma_max);\n"
00035 " pixel.b = pixel.b * gamma_scale * my_pow(pixel.b, gamma_gamma, gamma_max);\n"
00036 " gl_FragColor = pixel;\n"
00037 "}\n";
00038
00039 static char *gamma_yuv_frag =
00040 "uniform float gamma_scale;\n"
00041 "uniform float gamma_gamma;\n"
00042 "uniform float gamma_max;\n"
00043 "void main()\n"
00044 "{\n"
00045 " vec4 pixel = gamma_get_pixel();\n"
00046 YUV_TO_RGB_FRAG("pixel")
00047 " pixel.r = pixel.r * gamma_scale * my_pow(pixel.r, gamma_gamma, gamma_max);\n"
00048 " pixel.g = pixel.g * gamma_scale * my_pow(pixel.g, gamma_gamma, gamma_max);\n"
00049 " pixel.b = pixel.b * gamma_scale * my_pow(pixel.b, gamma_gamma, gamma_max);\n"
00050 RGB_TO_YUV_FRAG("pixel")
00051 " gl_FragColor = pixel;\n"
00052 "}\n";
00053
00054 #define GAMMA_COMPILE(shader_stack, current_shader, aggregate_interpolation) \
00055 { \
00056 if(aggregate_interpolation) \
00057 shader_stack[current_shader++] = gamma_get_pixel1; \
00058 else \
00059 shader_stack[current_shader++] = gamma_get_pixel2; \
00060 \
00061 switch(get_output()->get_color_model()) \
00062 { \
00063 case BC_YUV888: \
00064 case BC_YUVA8888: \
00065 shader_stack[current_shader++] = gamma_pow_frag; \
00066 shader_stack[current_shader++] = gamma_yuv_frag; \
00067 break; \
00068 default: \
00069 shader_stack[current_shader++] = gamma_pow_frag; \
00070 shader_stack[current_shader++] = gamma_rgb_frag; \
00071 break; \
00072 } \
00073 }
00074
00075 #define GAMMA_UNIFORMS(frag) \
00076 { \
00077 float max = get_output()->get_params()->get("GAMMA_MAX", (float)1); \
00078 float gamma = get_output()->get_params()->get("GAMMA_GAMMA", (float)1) - 1.0; \
00079 float scale = 1.0 / max; \
00080 glUniform1f(glGetUniformLocation(frag, "gamma_scale"), scale); \
00081 glUniform1f(glGetUniformLocation(frag, "gamma_gamma"), gamma); \
00082 glUniform1f(glGetUniformLocation(frag, "gamma_max"), max); \
00083 printf("GAMMA_UNIFORMS %f %f\n", max, gamma); \
00084 }
00085
00086
00087
00088
00089
00090 #endif