Drake Designer
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
bilateral_filter.glsl
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: bilateral_filter.glsl
5 
6  Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
7  All rights reserved.
8 
9  ParaView is a free software; you can redistribute it and/or modify it
10  under the terms of the ParaView license version 1.2.
11 
12  See License_v1.2.txt for the full ParaView license.
13  A copy of this license can be obtained by contacting
14  Kitware Inc.
15  28 Corporate Drive
16  Clifton Park, NY 12065
17  USA
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 =========================================================================*/
32 /*----------------------------------------------------------------------
33 Acknowledgement:
34 This algorithm is the result of joint work by Electricité de France,
35 CNRS, Collège de France and Université J. Fourier as part of the
36 Ph.D. thesis of Christian BOUCHENY.
37 ------------------------------------------------------------------------*/
39 //
40 //
41 // Bilateral filtering
42 //
43 // C.B. - 16 aout 2008
44 //
45 // IN:
46 // s2_I - Image to blur
47 // s2_D - Modulating depth image
48 // s1_F - Gaussian spatial kernel
49 // s2_G - Gaussian depth kernel
50 //
51 // OUT:
52 // Filtered image
53 //
55 
56 /****************************************************/
57 uniform sampler2D s2_I;
58 uniform sampler2D s2_D;
59 uniform float SX;
60 uniform float SY;
61 uniform int N;
62 // filter size (full width, necessarily odd, like 3, 5...)
63 uniform float sigma;
64 /****************************************************/
65 
66 /****************************************************/
67 vec3 C;
68 float z;
69 float sigmaz = 0.005;
70 /****************************************************/
71 
72 void main (void)
73 {
74  C = texture2D(s2_I,gl_TexCoord[0].st).rgb;
75  // gl_FragColor = vec4( z,z,z , 1. );
76  // return;
77  z = texture2D(s2_D,gl_TexCoord[0].st).r;
78 
79  float ALL = 0.; // sum of all weights
80  vec3 RES = vec3(0.); // sum of all contributions
81  int hN = N/2; // filter half width
82  vec2 coordi = vec2(0.,0.);
83  vec3 Ci;
84  float zi;
85  float dist;
86  float dz;
87  float Fi,Gi;
88 
89  int c,d;
90  for(c=-hN;c<hN+1;c++)
91  {
92  for(d=-hN;d<hN+1;d++)
93  {
94  coordi = vec2(float(c)*SX,float(d)*SY);
95  Ci = texture2D(s2_I,gl_TexCoord[0].st+coordi).rgb;
96  zi = texture2D(s2_D,gl_TexCoord[0].st+coordi).r;
97 
98  dist = clamp( float(c*c+d*d)/float(hN*hN) , 0., 1. );
99  dz = (z-zi)*(z-zi);
100 
101  Fi = exp(-dist*dist/(2.* sigma*sigma));
102  Gi = exp(-dz*dz/(2.* sigmaz*sigmaz));
103 
104  RES += Ci * Fi * Gi;
105  ALL += Fi * Gi;
106  }
107  }
108  RES /= ALL;
109 
110  gl_FragColor = vec4( RES , z );
111 }
uniform sampler2D s2_I
vec3 C
uniform int N
float sigmaz
uniform float d
Definition: edl_shade.glsl:56
uniform sampler2D s2_D
float z
uniform float SY
uniform float sigma
uniform float SX
void main(void)