3 #include "colorcurve.h"
14 ColorCurve::ColorCurve():
15 shprog(Resources::get_global().get<Program>("_colorcurve.glsl.shader")),
16 quad(Resources::get_global().get<Mesh>("_fullscreen_quad.mesh")),
17 linear_sampler(Resources::get_global().get<Sampler>("_linear_clamp.samp")),
18 nearest_sampler(Resources::get_global().get<Sampler>("_nearest_clamp.samp"))
20 curve.storage(LUMINANCE8, 256, 1);
22 set_exposure_adjust(0.0f);
23 set_brightness_response(0.4f);
27 void ColorCurve::set_exposure_adjust(float e)
29 shdata.uniform("exposure", pow(2.0f, e));
32 void ColorCurve::set_brightness_response(float b)
35 throw invalid_argument("ColorCurve::set_brightness_response");
36 // Calculate an offset value to obtain a derivative of 1 at zero intensity.
37 float t = (b<1 ? pow(b, 1/(1-b)) : 0.0f);
38 shdata.uniform("brightness_response", b, t, pow(t, b));
41 void ColorCurve::set_gamma(float g)
44 throw invalid_argument("ColorCurve::set_gamma");
46 unsigned char curve_data[256];
47 for(unsigned i=0; i<256; ++i)
48 curve_data[i] = pow(i/255.0f, 1/g)*255+0.5f;
49 curve.image(0, curve_data);
52 void ColorCurve::set_srgb()
54 unsigned char curve_data[256];
56 for(unsigned i=1; i<256; ++i)
57 curve_data[i] = to_srgb(i/255.0f)*255+0.5f;
58 curve.image(0, curve_data);
61 void ColorCurve::set_linear()
63 unsigned char curve_data[256];
64 for(unsigned i=0; i<256; ++i)
66 curve.image(0, curve_data);
69 void ColorCurve::render(Renderer &renderer, const Texture2D &color_buf, const Texture2D &)
71 Renderer::Push push(renderer);
72 renderer.set_shader_program(&shprog, &shdata);
73 renderer.set_texture("source", &color_buf, &nearest_sampler);
74 renderer.set_texture("curve", &curve, &linear_sampler);
78 void ColorCurve::set_debug_name(const string &name)
81 shdata.set_debug_name(name+" [UBO]");
82 curve.set_debug_name(name+"/curve.tex");
89 ColorCurve *ColorCurve::Template::create(unsigned, unsigned) const
91 RefPtr<ColorCurve> colorcurve = new ColorCurve();
92 colorcurve->set_exposure_adjust(exposure_adjust);
93 colorcurve->set_brightness_response(brightness_response);
95 colorcurve->set_srgb();
97 colorcurve->set_gamma(gamma);
98 return colorcurve.release();
102 ColorCurve::Template::Loader::Loader(Template &t):
103 DataFile::DerivedObjectLoader<Template, PostProcessor::Template::Loader>(t)
105 add("brightness_response", &Template::brightness_response);
106 add("exposure_adjust", &Template::exposure_adjust);
107 add("gamma", &Loader::gamma);
108 add("srgb", &Loader::srgb);
111 void ColorCurve::Template::Loader::gamma(float g)
117 void ColorCurve::Template::Loader::srgb()