1 #include "colorcurve.h"
10 static const char fragment_src[] =
11 "uniform sampler2D texture;\n"
12 "uniform float peak;\n"
13 "uniform float brightness;\n"
14 "varying vec2 texcoord;\n"
17 " vec4 sample = texture2D(texture, texcoord);\n"
18 " float maxc = max(sample.r, max(sample.g, sample.b));\n"
19 " if(maxc>1.0-peak)\n"
21 " vec3 saturated = sample.rgb/maxc;\n"
22 " if(maxc>1.0+peak)\n"
24 " gl_FragColor.rgb = mix(vec3(1.0), saturated, 1.0/pow(brightness, maxc-1.0-peak));\n"
28 " float x = (1.0+peak-maxc)/(2.0*peak);\n"
29 " gl_FragColor.rgb = saturated.rgb*(1.0-peak+(1.0-x*x)*peak);\n"
31 " gl_FragColor.a = sample.a;\n"
34 " gl_FragColor = sample;\n"
42 ColorCurve::ColorCurve():
43 quad(get_fullscreen_quad())
45 shprog.attach_shader(get_fullscreen_vertex_shader());
46 shprog.attach_shader_owned(new FragmentShader(fragment_src));
53 void ColorCurve::set_peak(float p)
56 throw invalid_argument("ColorCurve::set_peak");
57 shdata.uniform("peak", p);
60 void ColorCurve::set_brightness(float b)
63 throw invalid_argument("ColorCurve::set_brightness");
64 shdata.uniform("brightness", b);
67 void ColorCurve::render(const Texture2D &color_buf, const Texture2D &)
69 Bind _bind_shader(shprog);
71 Bind _bind_tex(color_buf);