PICCANTE  0.4
The hottest HDR imaging library!
filter_durand_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_DURAND_TMO_HPP
19 #define PIC_GL_FILTERING_FILTER_DURAND_TMO_HPP
20 
21 #include "../../base.hpp"
22 
23 #include "../../gl/filtering/filter.hpp"
24 #include "../../gl/filtering/filter_luminance.hpp"
25 
26 namespace pic {
27 
32 {
33 protected:
36 
40  void initShaders();
41 
45  void FragmentShader();
46 
47 public:
48 
53 
61  bool bGammaCorrection);
62 
64 
70  void update(float compression_factor, float log_absolute);
71 };
72 
74 {
76  this->log_absolute = this->compression_factor * 6.0f;
77 
78  this->bGammaCorrection = false;
79 
81  initShaders();
82 }
83 
84 PIC_INLINE FilterGLDurandTMO::FilterGLDurandTMO(float compression_factor, float log_absolute,
85  bool bGammaCorrection = false): FilterGL()
86 {
88 
90  initShaders();
91 
92  update(compression_factor, log_absolute);
93 }
94 
96 {
97  release();
98 }
99 
101 {
103  (
104  uniform sampler2D u_tex; \n
105  uniform sampler2D u_lum_log; \n
106  uniform sampler2D u_base; \n
107  uniform float compression_factor;\n
108  uniform float log_absolute;\n
109  out vec4 f_color; \n
110 
111  void main(void) {\n
112  \n
113  ivec2 coords = ivec2(gl_FragCoord.xy);\n
114  vec3 color = texelFetch(u_tex, coords, 0).xyz;\n
115  float L = dot(vec3(0.213, 0.715, 0.072), color);\n
116  float L_log = texelFetch(u_lum_log, coords, 0).x;\n
117  float base = texelFetch(u_base, coords, 0).x;\n
118  float detail = L_log - base;\n
119  float L_comp = (base * compression_factor + detail) - log_absolute;\n
120  L_comp = pow(10.0, L_comp);\n
121  color = (color * L_comp / L);\n
122  __GAMMA__CORRECTION__ \n
123  f_color = vec4(color, 1.0);\n
124  \n
125  }\n
126  );
127 
129 }
130 
132 {
133  technique.initStandard("330", vertex_source, fragment_source, "FilterGLDurandTMO");
134 }
135 
136 PIC_INLINE void FilterGLDurandTMO::update(float compression_factor, float log_absolute)
137 {
138  this->compression_factor = compression_factor;
139  this->log_absolute = log_absolute;
140 
141  technique.bind();
142  technique.setUniform1i("u_tex", 0);
143  technique.setUniform1i("u_lum_log", 1);
144  technique.setUniform1i("u_base", 2);
145  technique.setUniform1f("compression_factor", compression_factor);
146  technique.setUniform1f("log_absolute", log_absolute);
147  technique.unbind();
148 }
149 
150 } // end namespace pic
151 
152 #endif /* PIC_GL_FILTERING_FILTER_DURAND_TMO_HPP */
153 
TechniqueGL technique
Definition: display.hpp:45
void initShaders()
initShaders
void bind()
bind
Definition: display.hpp:189
PIC_INLINE float log10fPlusEpsilon(float x)
log10fPlusEpsilon
Definition: math.hpp:355
#define MAKE_STRING(input_string)
float compression_factor
Definition: filter_durand_tmo.hpp:34
bool bGammaCorrection
Definition: filter_durand_tmo.hpp:35
FilterGLDurandTMO()
FilterGLDurandTMO.
void setUniform1f(const char *name_uniform, float value0)
SetUniform1f.
Definition: display.hpp:247
The FilterGL class.
Definition: filter.hpp:35
float log_absolute
Definition: filter_durand_tmo.hpp:34
static std::string gammaCorrection(std::string fragment_source, bool bGammaCorrection)
gammaCorrection
Definition: display.hpp:182
void FragmentShader()
FragmentShader.
The FilterGL class.
Definition: display.hpp:35
#define PIC_INLINE
Definition: base.hpp:33
bool initStandard(std::string version_number, std::string vertex_shader_source, std::string fragment_shader_source, std::string name)
initStandard
Definition: display.hpp:114
The FilterGLDurandTMO class.
Definition: filter_durand_tmo.hpp:31
void unbind()
unbind
Definition: display.hpp:197
std::string vertex_source
Definition: display.hpp:57
Definition: bilateral_separation.hpp:25
void update(float compression_factor, float log_absolute)
update
std::string fragment_source
Definition: display.hpp:57
void release()
release
Definition: display.hpp:85
void setUniform1i(const char *name_uniform, int value0)
SetUniform.
Definition: display.hpp:236