PICCANTE  0.4
The hottest HDR imaging library!
filter_simple_tmo.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_GL_FILTERING_FILTER_SIMPLE_TMO_HPP
19 #define PIC_GL_FILTERING_FILTER_SIMPLE_TMO_HPP
20 
21 #include "../../base.hpp"
22 
23 #include "../../gl/filtering/filter.hpp"
24 
25 namespace pic {
26 
31 {
32 protected:
33  float fstop, gamma;
34 
35  void initShaders()
36  {
38  (
39  uniform sampler2D u_tex; \n
40  uniform float tn_gamma; \n
41  uniform float tn_exposure; \n
42  out vec4 f_color; \n
43 
44  void main(void) { \n
45  ivec2 coords = ivec2(gl_FragCoord.xy); \n
46  vec3 color = texelFetch(u_tex, coords, 0).xyz; \n
47  color = pow(color * tn_exposure, vec3(tn_gamma));
48  f_color = vec4(color, 1.0);
49  \n
50  }\n
51  );
52 
53  technique.initStandard("330", vertex_source, fragment_source, "FilterGLSimpleTMO");
54  }
55 
56 public:
61  {
62  initShaders();
63  update(2.2f, 0.0f);
64  }
65 
72  {
73  initShaders();
74  update(gamma, fstop);
75  }
76 
82  void update(float gamma, float fstop)
83  {
84  gamma = gamma > 0.0f ? gamma : 2.2f;
85 
86  this->gamma = gamma;
87  this->fstop = fstop;
88 
89  float invGamma = 1.0f / gamma;
90  float exposure = powf(2.0f, fstop);
91 
92  if(technique.isValid()) {
93  technique.bind();
94  technique.setUniform1i("u_tex", 0);
95  technique.setUniform1f("tn_gamma", invGamma);
96  technique.setUniform1f("tn_exposure", exposure);
97  technique.unbind();
98  }
99  }
100 };
101 
102 } // end namespace pic
103 
104 #endif /* PIC_GL_FILTERING_FILTER_SIMPLE_TMO_HPP */
105 
TechniqueGL technique
Definition: display.hpp:45
FilterGLSimpleTMO()
FilterGLSimpleTMO.
Definition: filter_simple_tmo.hpp:60
void bind()
bind
Definition: display.hpp:189
FilterGLSimpleTMO(float gamma, float fstop)
FilterGLSimpleTMO.
Definition: filter_simple_tmo.hpp:71
#define MAKE_STRING(input_string)
void setUniform1f(const char *name_uniform, float value0)
SetUniform1f.
Definition: display.hpp:247
The FilterGLSimpleTMO class.
Definition: filter_simple_tmo.hpp:30
void update(float gamma, float fstop)
update
Definition: filter_simple_tmo.hpp:82
float fstop
Definition: filter_simple_tmo.hpp:33
The FilterGL class.
Definition: filter.hpp:35
bool initStandard(std::string version_number, std::string vertex_shader_source, std::string fragment_shader_source, std::string name)
initStandard
Definition: display.hpp:114
void initShaders()
Definition: filter_simple_tmo.hpp:35
void unbind()
unbind
Definition: display.hpp:197
std::string vertex_source
Definition: display.hpp:57
Definition: bilateral_separation.hpp:25
bool isValid()
Definition: display.hpp:62
float gamma
Definition: filter_simple_tmo.hpp:33
std::string fragment_source
Definition: display.hpp:57
void setUniform1i(const char *name_uniform, int value0)
SetUniform.
Definition: display.hpp:236