18 #ifndef PIC_GL_FILTERING_FILTER_BILATERAL_2DAS_HPP 19 #define PIC_GL_FILTERING_FILTER_BILATERAL_2DAS_HPP 21 #include "../../util/vec.hpp" 22 #include "../../util/std_util.hpp" 23 #include "../../gl/filtering/filter.hpp" 24 #include "../../gl/filtering/filter_sampling_map.hpp" 25 #include "../../gl/point_samplers/sampler_random_m.hpp" 126 if(
param.size() == 3) {
177 uniform sampler2D u_tex;
178 uniform isampler2D u_poisson;
179 uniform sampler2D u_sample;
180 uniform isampler2D u_rand;
181 uniform isampler2D u_levelsR;
182 uniform
float sigmas2;
183 uniform
float sigmar2;
184 uniform
int levelsR_Size;
188 int CalculateSamples(
int shifter, ivec2 tSize) {
190 float levelVal = dot(texture(u_sample, gl_FragCoord.xy / tSize.xy).xyz, vec3(1.0)) / 3.0;
191 levelVal = clamp(1.0f - levelVal, 0.0, 1.0) * float(levelsR_Size);
193 int levelInt = int(floor(levelVal));
195 int nSamples = texelFetch(u_levelsR, ivec2(levelInt, shifter), 0).x;
197 if(levelInt < (levelsR_Size - 1)) {
198 float tmp = (levelVal - float(levelInt));
201 int nSamples1 = texelFetch(u_levelsR, ivec2(levelInt + 1, shifter), 0).x;
203 nSamples += int(
float(nSamples1 - nSamples) * tmp);
211 ivec2 coordsFrag = ivec2(gl_FragCoord.xy);
214 int shifter = texelFetch(u_rand, coordsFrag.xy % 128, 0).x;
217 ivec2 tSize = textureSize(u_tex, 0);
219 int nSamples = CalculateSamples(shifter, tSize);
223 vec3 colRef = texelFetch(u_tex, coordsFrag, 0).xyz;
224 vec3 color = vec3(0.0);
227 for(
int i = 0; i < nSamples; i++) {
228 ivec4 coords = texelFetch(u_poisson, ivec2(i, shifter), 0);
231 tmpCol = texelFetch(u_tex, coordsFrag.xy + coords.xy, 0).xyz;
232 vec3 tmpCol2 = tmpCol - colRef;
233 float dstR = dot(tmpCol2.xyz, tmpCol2.xyz);
234 float tmp = exp(-dstR / sigmar2 -
float(coords.z) / sigmas2);
235 color += tmpCol * tmp;
239 color = weight > 0.0 ? color / weight : colRef;
240 f_color = vec4(color, 1.0);
256 flag = (this->sigma_s ==
sigma_s);
261 flag = flag || (this->sigma_r ==
sigma_r);
271 Image tmp_image_rand(1, 128, 128, 1);
273 tmp_image_rand *= float(nRand - 1);
282 int halfKernelSize = kernelSize >> 1;
283 Vec2i window =
Vec2i(halfKernelSize, halfKernelSize);
287 printf(
"Window: %d\n", halfKernelSize);
295 printf(
"Number of samples: %d\n",
ms->
nSamples >> 1);
305 float sigmas2 = 2.0f * this->sigma_s * this->
sigma_s;
306 float sigmar2 = 2.0f * this->sigma_r * this->
sigma_r;
MRSamplersGL< 2 > * ms
Definition: filter_bilateral_2das.hpp:33
TechniqueGL technique
Definition: display.hpp:45
static int getKernelSize(float sigma)
KernelSize computes the size of a kernel in pixel give its sigma.
Definition: precomputed_gaussian.hpp:121
FilterGLBilateral2DAS()
FilterGLBilateral2DAS.
T * delete_s(T *data)
delete_s
Definition: std_util.hpp:123
GLuint generateLevelsRTexture()
generateLevelsRTexture
Definition: sampler_random_m.hpp:222
GLuint generateTextureGL(GLenum target, GLenum format_type, bool mipmap)
generateTextureGL
ImageGL * allocateOutputMemory(ImageGLVec imgIn, ImageGL *imgOut, bool bDelete)
allocateOutputMemory
Definition: display.hpp:217
void updateParam()
updateParam
Definition: filter_bilateral_2das.hpp:55
void bind()
bind
Definition: display.hpp:189
#define MAKE_STRING(input_string)
Definition: filter_bilateral_2das.hpp:29
The Image class stores an image as buffer of float.
Definition: filter_radial_basis_function.hpp:60
bool bDelete
Definition: display.hpp:54
PIC_INLINE ImageGLVec SingleGL(ImageGL *img)
SingleGL creates a single for filters input.
Definition: image_vec.hpp:39
void setNULL()
setNULL
Definition: filter_bilateral_2das.hpp:71
ImageGL * Process(ImageGLVec imgIn, ImageGL *imgOut)
Process.
Definition: filter_npasses.hpp:323
The ImageGL class.
Definition: image.hpp:42
Vec< 2, int > Vec2i
Vec2i.
Definition: vec.hpp:829
void setUniform1f(const char *name_uniform, float value0)
SetUniform1f.
Definition: display.hpp:247
ImageGL * setupAux(ImageGLVec imgIn, ImageGL *imgOut)
setupAux
Definition: filter_bilateral_2das.hpp:121
void initShaders()
initShaders
ImageGL * sampleMap
Definition: filter_bilateral_2das.hpp:40
virtual ImageGL * Process(ImageGLVec imgIn, ImageGL *imgOut)
Process.
Definition: display.hpp:258
void update(float sigma_s, float sigma_r)
update
int nLevels
Definition: display.hpp:44
void updateGL(Vec< N, int > window, int nSamples)
updateGL
Definition: sampler_random_m.hpp:129
The FilterGL class.
Definition: filter.hpp:35
ImageGL * imageRand
Definition: filter_bilateral_2das.hpp:36
void setRand(unsigned int seed)
setRand
Definition: filter_radial_basis_function.hpp:1392
GLuint generateTexture()
generateTexture
Definition: sampler_random_m.hpp:151
void FragmentShader()
FragmentShader.
The FilterGL class.
Definition: display.hpp:35
The MRSamplersGL class.
Definition: sampler_random_m.hpp:45
#define PIC_INLINE
Definition: base.hpp:33
The ImageGL class.
Definition: display.hpp:42
The Vec class.
Definition: display.hpp:35
bool initStandard(std::string version_number, std::string vertex_shader_source, std::string fragment_shader_source, std::string name)
initStandard
Definition: display.hpp:114
static ImageGL * execute(ImageGL *imgIn, float sigma_s, float sigma_r)
execute
Definition: filter_bilateral_2das.hpp:140
ImageGLVec param
Definition: display.hpp:49
FilterGLSamplingMap * fGLsm
Definition: filter_bilateral_2das.hpp:39
Definition: point_samplers.hpp:51
void releaseAux()
releaseAux
Definition: filter_bilateral_2das.hpp:93
ImageGL * getImageLevelsR()
getImageLevelsR
Definition: display.hpp:100
void unbind()
unbind
Definition: display.hpp:197
float sigma_s
Definition: filter_bilateral_2das.hpp:32
std::string vertex_source
Definition: display.hpp:57
Definition: bilateral_separation.hpp:25
float sigma_r
Definition: filter_bilateral_2das.hpp:32
std::string fragment_source
Definition: display.hpp:57
The FilterGLSamplingMap class.
Definition: filter_sampling_map.hpp:38
int nSamples
Definition: display.hpp:53
ImageGL * getImage()
getImage
Definition: display.hpp:89
std::vector< ImageGL * > ImageGLVec
ImageGLVec an std::vector of pic::ImageGL.
Definition: image_vec.hpp:32
void release()
release
Definition: display.hpp:85
void setUniform1i(const char *name_uniform, int value0)
SetUniform.
Definition: display.hpp:236
The FilterGLSamplingMap class.
Definition: display.hpp:38