PICCANTE  0.4
The hottest HDR imaging library!
filter_sigmoid_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_SIGMOID_TMO_HPP
19 #define PIC_GL_FILTERING_FILTER_SIGMOID_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:
34  float alpha, epsilon;
36 
40  void initShaders();
41 
42 public:
47 
49 
57 
62  void update(float alpha);
63 };
64 
66 {
67  alpha = 0.15f;
68  bGammaCorrection = false;
69  bLocal = false;
70  epsilon = 1.0f;
71 
72  initShaders();
73 }
74 
76 {
77  release();
78 }
79 
81  bool bGammaCorrection): FilterGL()
82 {
83  this->alpha = alpha;
84  this->bLocal = bLocal;
85  this->bGammaCorrection = bGammaCorrection;
86  epsilon = 1.0f;
87 
88  initShaders();
89 }
90 
92 {
94  (
95  uniform sampler2D u_tex; \n
96  uniform sampler2D u_tex_adapt; \n
97  uniform float alpha; \n
98  uniform float epsilon; \n
99  out vec4 f_color; \n
100  const vec3 LUM_XYZ = vec3(0.213, 0.715, 0.072); \n
101 
102  void main(void) {
103  \n
104  ivec2 coords = ivec2(gl_FragCoord.xy);
105  \n
106  vec3 color = texelFetch(u_tex, coords, 0).xyz;
107  \n
108  __LOCAL__1__ \n
109  float Lw = dot(color, LUM_XYZ);
110  \n
111  __LOCAL__2__ \n
112  color = (color.xyz * Ld) / Lw;
113  \n
114  __GAMMA__CORRECTION__ \n
115  f_color = vec4(color, 1.0);
116  \n
117  }\n
118  );
119 
120  size_t processing_found1 = fragment_source.find("__LOCAL__1__");
121 
122  if(bLocal) {
123  fragment_source.replace(processing_found1, 12,
124  " float Lwa = texelFetch(u_tex_adapt, coords,0).x; ");
125 
126  size_t processing_found2 = fragment_source.find("__LOCAL__2__");
127  fragment_source.replace(processing_found2, 12,
128  " float Ld = (Lw * alpha)/(Lwa * alpha + epsilon); ");
129  } else {
130  fragment_source.replace(processing_found1, 12, " ");
131 
132  size_t processing_found2 = fragment_source.find("__LOCAL__2__");
133  fragment_source.replace(processing_found2, 12,
134  " float Lscale = Lw * alpha;\n float Ld = Lscale / (Lscale + epsilon); ");
135  }
136 
138 
139  //
140  //
141  //
142 
143  technique.initStandard("330", vertex_source, fragment_source, "FilterGLSigmoidTMO");
144 
145  update(alpha);
146 }
147 
149 {
150  if(alpha > 0.0f) {
151  this->alpha = alpha;
152  }
153 
154  technique.bind();
155  technique.setUniform1i("u_tex", 0);
156  technique.setUniform1i("u_tex_adapt", 1);
157  technique.setUniform1f("alpha", this->alpha);
158  technique.setUniform1f("epsilon", epsilon);
159  technique.unbind();
160 }
161 
162 } // end namespace pic
163 
164 #endif /* PIC_GL_FILTERING_FILTER_SIGMOID_TMO_HPP */
165 
TechniqueGL technique
Definition: display.hpp:45
FilterGLSigmoidTMO()
FilterGLSigmoidTMO.
float alpha
Definition: filter_sigmoid_tmo.hpp:34
void bind()
bind
Definition: display.hpp:189
#define MAKE_STRING(input_string)
void setUniform1f(const char *name_uniform, float value0)
SetUniform1f.
Definition: display.hpp:247
The FilterGL class.
Definition: filter.hpp:35
static std::string gammaCorrection(std::string fragment_source, bool bGammaCorrection)
gammaCorrection
Definition: display.hpp:182
void update(float alpha)
update
bool bLocal
Definition: filter_sigmoid_tmo.hpp:35
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 FilterGLSigmoidTMO class.
Definition: filter_sigmoid_tmo.hpp:31
void unbind()
unbind
Definition: display.hpp:197
std::string vertex_source
Definition: display.hpp:57
void initShaders()
initShaders
Definition: bilateral_separation.hpp:25
bool bGammaCorrection
Definition: filter_sigmoid_tmo.hpp:35
std::string fragment_source
Definition: display.hpp:57
float epsilon
Definition: filter_sigmoid_tmo.hpp:34
void release()
release
Definition: display.hpp:85
void setUniform1i(const char *name_uniform, int value0)
SetUniform.
Definition: display.hpp:236