PICCANTE  0.4
The hottest HDR imaging library!
filter_slicer.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_SLICER_HPP
19 #define PIC_GL_FILTERING_FILTER_SLICER_HPP
20 
21 #include "../../base.hpp"
22 
23 #include "../../gl/filtering/filter.hpp"
24 
25 namespace pic {
26 
30 class FilterGLSlicer: public FilterGL
31 {
32 protected:
33 
34  void initShaders();
35  void FragmentShader();
36 
37  float s_S, s_R, mul_E;
38 
39 public:
45  FilterGLSlicer(float s_S, float s_R);
46 
48 
54  void update(float s_S, float s_R);
55 };
56 
58 {
59  this->s_S = s_S;
60  this->s_R = s_R;
61 
63  initShaders();
64 }
65 
67 {
68  release();
69 }
70 
72 {
74  (
75  uniform sampler2D u_tex;
76  uniform sampler3D u_grid;
77  uniform float mul_E;
78  uniform float s_S;
79 
80  out vec4 f_color;
81 
82  void main(void) {
83  //Fetch texture color
84  ivec2 coordsFrag = ivec2(gl_FragCoord.xy);
85  vec4 colRef = texelFetch(u_tex, coordsFrag, 0);
86 
87  //Fetch E
88  vec3 tSize3 = vec3(textureSize(u_grid, 0));
89  float E = dot(colRef.xyz, vec3(1.0)) * mul_E;
90  E /= tSize3.z;
91 
92  //Fetch from the grid
93  vec2 coord = (gl_FragCoord.xy * s_S) / tSize3.xy;
94  vec4 sliced = texture(u_grid, vec3(coord.xy, E));
95 
96  vec3 color = sliced.w > 0.0 ? sliced.xyz / sliced.w : vec3(0.0);
97 
98  f_color = vec4(color.xyz, 1.0);
99  }
100  );
101 }
102 
104 {
105  technique.initStandard("400", vertex_source, fragment_source, "FilterGLSlicer");
106 
107  update(s_S, s_R);
108 }
109 
110 PIC_INLINE void FilterGLSlicer::update(float s_S, float s_R)
111 {
112  this->s_S = s_S;
113  this->s_R = s_R;
114 
115  mul_E = s_R / 3.0f;
116 
117 #ifdef PIC_DEBUG
118  printf("Rate S: %f Rate R: %f Mul E: %f\n", s_S, s_R, mul_E);
119 #endif
120 
121  technique.bind();
122  technique.setUniform1i("u_tex", 0);
123  technique.setUniform1i("u_grid", 1);
124  technique.setUniform1f("s_S", s_S);
125  technique.setUniform1f("mul_E", mul_E);
126  technique.unbind();
127 }
128 
129 } // end namespace pic
130 
131 #endif /* PIC_GL_FILTERING_FILTER_SLICER_HPP */
TechniqueGL technique
Definition: display.hpp:45
void update(float s_S, float s_R)
update
float s_R
Definition: filter_slicer.hpp:37
void bind()
bind
Definition: display.hpp:189
#define MAKE_STRING(input_string)
The FilterGLSlicer class.
Definition: filter_slicer.hpp:30
void setUniform1f(const char *name_uniform, float value0)
SetUniform1f.
Definition: display.hpp:247
The FilterGL class.
Definition: filter.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
float mul_E
Definition: filter_slicer.hpp:37
void unbind()
unbind
Definition: display.hpp:197
std::string vertex_source
Definition: display.hpp:57
Definition: bilateral_separation.hpp:25
float s_S
Definition: filter_slicer.hpp:37
std::string fragment_source
Definition: display.hpp:57
FilterGLSlicer(float s_S, float s_R)
FilterGLSlicer.
void release()
release
Definition: display.hpp:85
void setUniform1i(const char *name_uniform, int value0)
SetUniform.
Definition: display.hpp:236