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-peak));\n"
28 " float x = (1.0+peak-maxc)/(2.0*peak);\n"
29 " gl_FragColor.rgb = saturated.rgb*(1.0-peak+(1-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 Shader *fs = new Shader(FRAGMENT_SHADER, fragment_src);
47 shprog.attach_shader_owned(fs);
54 void ColorCurve::set_peak(float p)
57 throw invalid_argument("ColorCurve::set_peak");
58 shdata.uniform("peak", p);
61 void ColorCurve::set_brightness(float b)
64 throw invalid_argument("ColorCurve::set_brightness");
65 shdata.uniform("brightness", b);
68 void ColorCurve::render(const Texture2D &color_buf, const Texture2D &)
70 Bind _bind_shader(shprog);
72 Bind _bind_tex(color_buf);