PICCANTE  0.4
The hottest HDR imaging library!
filter_drago_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_DRAGO_TMO_HPP
19 #define PIC_GL_FILTERING_FILTER_DRAGO_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:
37 
41  void computeConstants();
42 
46  void initShaders();
47 
51  void FragmentShader();
52 
53 public:
58 
60 
68  void update(float Ld_Max, float b, float LMax, float Lwa);
69 };
70 
72 {
73  Ld_Max = 100.0f;
74  b = 0.95f;
75  LMax = 1e6f;
76  Lwa = -1.0f;
77 
78  bGammaCorrection = false;
79 
81  initShaders();
82 }
83 
85 {
86  release();
87 }
88 
89 
91 {
93  (
94  uniform sampler2D u_tex;\n
95  uniform float constant1;\n
96  uniform float constant2;\n
97  uniform float LMax;\n
98  uniform float Lwa;\n
99  out vec4 f_color;\n
100 
101  void main(void) {
102  \n
103  ivec2 coords = ivec2(gl_FragCoord.xy);\n
104  vec3 color = texelFetch(u_tex, coords, 0).xyz;\n
105  float L = dot(vec3(0.213, 0.715, 0.072), color);
106  float L_scaled = L / Lwa;\n
107  float tmp = pow((L_scaled / LMax), constant1);\n
108  float Ld = constant2 * log(1.0 + L_scaled) / log(2.0 + 8.0 * tmp);\n
109  color = (color * Ld) / L;\n
110  __GAMMA__CORRECTION__ \n
111  f_color = vec4(color, 1.0);\n
112  \n
113  }\n
114  );
115 
117 }
118 
120 {
121  technique.initStandard("330", vertex_source, fragment_source, "FilterGLDragoTMO");
122  update(Ld_Max, b, LMax, Lwa);
123 }
124 
125 PIC_INLINE void FilterGLDragoTMO::update(float Ld_Max, float b, float LMax, float Lwa)
126 {
127  this->Ld_Max = Ld_Max > 0.0f ? Ld_Max : 100.0f;
128  this->b = b > 0.0f ? b : 0.95f;
129  this->LMax = LMax > 0.0f ? LMax : 1e6f;
130  this->Lwa = Lwa > 0.0f ? Lwa : 1.0f;
131 
132  Lwa_scaled = Lwa / powf(1.0f + b - 0.85f, 5.0f);
134  constant1 = logf(b) / logf(0.5f);
135  constant2 = (Ld_Max / 100.0f) / (log10(1 + LMax_scaled));
136 
137  technique.bind();
138  technique.setUniform1i("u_tex", 0);
139  technique.setUniform1f("constant1", constant1);
140  technique.setUniform1f("constant2", constant2);
143  technique.unbind();
144 }
145 
146 } // end namespace pic
147 
148 #endif /* PIC_GL_FILTERING_FILTER_DRAGO_TMO_HPP */
149 
TechniqueGL technique
Definition: display.hpp:45
float LMax_scaled
Definition: filter_drago_tmo.hpp:34
void bind()
bind
Definition: display.hpp:189
#define MAKE_STRING(input_string)
float Lwa_scaled
Definition: filter_drago_tmo.hpp:34
void initShaders()
initShaders
void setUniform1f(const char *name_uniform, float value0)
SetUniform1f.
Definition: display.hpp:247
float b
Definition: filter_drago_tmo.hpp:34
float constant1
Definition: filter_drago_tmo.hpp:35
The FilterGL class.
Definition: filter.hpp:35
static std::string gammaCorrection(std::string fragment_source, bool bGammaCorrection)
gammaCorrection
Definition: display.hpp:182
The FilterGL class.
Definition: display.hpp:35
#define PIC_INLINE
Definition: base.hpp:33
bool bGammaCorrection
Definition: filter_drago_tmo.hpp:36
FilterGLDragoTMO()
FilterGLDragoTMO.
bool initStandard(std::string version_number, std::string vertex_shader_source, std::string fragment_shader_source, std::string name)
initStandard
Definition: display.hpp:114
float Ld_Max
Definition: filter_drago_tmo.hpp:34
float Lwa
Definition: filter_drago_tmo.hpp:34
void unbind()
unbind
Definition: display.hpp:197
The FilterGLDragoTMO class.
Definition: filter_drago_tmo.hpp:31
std::string vertex_source
Definition: display.hpp:57
Definition: bilateral_separation.hpp:25
std::string fragment_source
Definition: display.hpp:57
float constant2
Definition: filter_drago_tmo.hpp:35
float LMax
Definition: filter_drago_tmo.hpp:34
void computeConstants()
computeConstants
void FragmentShader()
FragmentShader.
void release()
release
Definition: display.hpp:85
void setUniform1i(const char *name_uniform, int value0)
SetUniform.
Definition: display.hpp:236
void update(float Ld_Max, float b, float LMax, float Lwa)
update