X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcolorcurve.cpp;h=54fbc767bb77a75ce19356d446a7c38d13526b52;hp=d008593e047a0c2f9fed620471dcdea1057d794c;hb=HEAD;hpb=9733137499a84f44c29d06d2551d41a903de1112 diff --git a/source/colorcurve.cpp b/source/colorcurve.cpp deleted file mode 100644 index d008593e..00000000 --- a/source/colorcurve.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "colorcurve.h" -#include "mesh.h" -#include "shader.h" -#include "texture2d.h" - -using namespace std; - -namespace { - -static const char fragment_src[] = - "uniform sampler2D texture;\n" - "uniform float peak;\n" - "uniform float brightness;\n" - "varying vec2 texcoord;\n" - "void main()\n" - "{\n" - " vec4 sample = texture2D(texture, texcoord);\n" - " float maxc = max(sample.r, max(sample.g, sample.b));\n" - " if(maxc>1.0-peak)\n" - " {\n" - " vec3 saturated = sample.rgb/maxc;\n" - " if(maxc>1.0+peak)\n" - " {\n" - " gl_FragColor.rgb = mix(vec3(1.0), saturated, 1.0/pow(brightness, maxc-1-peak));\n" - " }\n" - " else\n" - " {\n" - " float x = (1.0+peak-maxc)/(2.0*peak);\n" - " gl_FragColor.rgb = saturated.rgb*(1.0-peak+(1-x*x)*peak);\n" - " }\n" - " gl_FragColor.a = sample.a;\n" - " }\n" - " else\n" - " gl_FragColor = sample;\n" - "}"; - -} - -namespace Msp { -namespace GL { - -ColorCurve::ColorCurve(): - quad(get_fullscreen_quad()) -{ - shprog.attach_shader(get_fullscreen_vertex_shader()); - shprog.attach_shader_owned(new FragmentShader(fragment_src)); - shprog.link(); - - set_peak(0.2); - set_brightness(1.5); -} - -void ColorCurve::set_peak(float p) -{ - if(p<0 || p>1) - throw invalid_argument("ColorCurve::set_peak"); - shdata.uniform("peak", p); -} - -void ColorCurve::set_brightness(float b) -{ - if(b<1) - throw invalid_argument("ColorCurve::set_brightness"); - shdata.uniform("brightness", b); -} - -void ColorCurve::render(const Texture2D &color_buf, const Texture2D &) -{ - Bind _bind_shader(shprog); - shdata.apply(); - Bind _bind_tex(color_buf); - quad.draw(); -} - -} // namespace GL -} // namespace Msp