PICCANTE  0.4
The hottest HDR imaging library!
filter_remove_nuked.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_REMOVE_NUKED_HPP
19 #define PIC_GL_FILTERING_FILTER_REMOVE_NUKED_HPP
20 
21 #include "../../base.hpp"
22 #include "../../gl/filtering/filter.hpp"
23 
24 namespace pic {
25 
30 {
31 protected:
32  float threshold;
33 
37  void initShaders();
38 
42  void FragmentShader();
43 
44 public:
50 
55  void update(float threshold);
56 };
57 
59 {
60  this->threshold = threshold;
61 
63  initShaders();
64 }
65 
67 {
69  (
70  uniform sampler2D u_tex;
71  uniform float threshold;
72  out vec4 f_color;
73 
74  void main(void) {
75 
76  ivec2 coordsFrag = ivec2(gl_FragCoord.xy);
77 
78  float ref = texelFetch(u_tex, coordsFrag, 0).x;
79  float tmp;
80 
81  int count = 0;
82 
83  vec3 colorNuked = vec3(0.0);
84 
85  for(int i = -2; i < 3; i++) {
86  for(int j = -2; j < 3; j++) {
87  //Coordinates
88  ivec2 coords = ivec2(i, j);
89  //Texture fetch
90  tmp = texelFetch(u_tex, coordsFrag.xy + coords.xy, 0).x;
91  float tmp2 = abs(tmp - ref);
92 
93  if(tmp2 > threshold) {
94  count = count + 1;
95  colorNuked = vec3(tmp);
96  }
97  }\n
98  }\n
99 
100  vec3 color = vec3(ref);
101  \n
102 
103  if(count > 12)\n
104  color = colorNuked;
105 
106  \n
107  f_color = vec4(color, 1.0);
108  \n
109  }\n
110  );
111 }
112 
114 {
115  technique.initStandard("330", vertex_source, fragment_source, "FilterGLRemoveNuked");
116 
117  update(-1.0f);
118 }
119 
121 {
122  if(threshold > 0.0f) {
123  this->threshold = threshold;
124  }
125 
126  technique.bind();
127  technique.setUniform1i("u_tex", 0);
128  technique.setUniform1f("threshold", this->threshold);
129  technique.unbind();
130 }
131 
132 } // end namespace pic
133 
134 #endif /* PIC_GL_FILTERING_FILTER_REMOVE_NUKED_HPP */
135 
TechniqueGL technique
Definition: display.hpp:45
The FilterGLRemoveNuked class.
Definition: filter_remove_nuked.hpp:29
FilterGLRemoveNuked(float threshold)
FilterGLRemoveNuked.
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
void update(float threshold)
update
The FilterGL class.
Definition: filter.hpp:35
float threshold
Definition: filter_remove_nuked.hpp:32
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
void FragmentShader()
FragmentShader.
void unbind()
unbind
Definition: display.hpp:197
std::string vertex_source
Definition: display.hpp:57
Definition: bilateral_separation.hpp:25
std::string fragment_source
Definition: display.hpp:57
void initShaders()
initShaders
void setUniform1i(const char *name_uniform, int value0)
SetUniform.
Definition: display.hpp:236