1+ #version 300 es
2+ precision highp float ;
3+ precision mediump sampler2D ;
4+ uniform sampler2D InputBuffer;
5+ uniform sampler2D NoiseMap;
6+ uniform int kernel;
7+ uniform float isofactor;
8+ uniform ivec2 size;
9+ uniform ivec2 tpose;
10+ #define M_PI 3.1415926535897932384626433832795
11+
12+ // #define sigma (0.05)
13+ // const int kernel = 6;
14+ const int window = 2 ;
15+ #import interpolation
16+ #define luminocity(x) ((((x.r+ x.g+ x.b)/ 3.0 ))+ 0.001 )
17+ /* float luminocity(vec3 color) {
18+ return (color.r+color.g+color.b)/3.0;
19+ }*/
20+ #define distribute(x,dev,sigma) ((exp (- (x- dev) * (x- dev) / (2.0 * sigma * sigma)) / (sqrt (2.0 * M_PI) * sigma)))
21+
22+ float nlmeans(ivec2 coords) {
23+ float processed = 0.0 ;
24+ float weights = 0.0 ;
25+ float noisefactor = clamp ((textureBicubic(NoiseMap, vec2 (coords)/ vec2 (size)).r)* 0.55 * isofactor,0.0005 ,1.0 );
26+ noisefactor*= noisefactor;
27+ noisefactor*= 0.6 ;
28+ for (int i = - kernel; i < kernel; i++ ) {
29+ for (int j = - kernel; j < kernel; j++ ) {
30+ ivec2 patchCoord = coords + ivec2 (i, j);
31+ // float w = comparePatches(patchCoord, coords,0.01*0.5 + noisefactor*0.35);
32+ float sigma = (0.01 * 0.5 + noisefactor* 0.35 );
33+ float w = distribute(luminocity(texelFetch(InputBuffer, coords,0 ).rgb),
34+ luminocity(texelFetch(InputBuffer,patchCoord,0 ).rgb),sigma);
35+ w/= ((2.0 * float (window) + 1.0 ) * (2.0 * float (window) + 1.0 ));
36+ processed += w * luminocity(texelFetch(InputBuffer, patchCoord,0 ).rgb);
37+ weights += w;
38+ }
39+ }
40+ return processed / weights;
41+ }
42+
43+ // ////////////////////////////////////////////////////////////////////////////////
44+ out vec3 Output;
45+ uniform int yOffset;
46+ void main() {
47+ ivec2 xy = ivec2 (gl_FragCoord .xy);
48+ xy+= ivec2 (0 ,yOffset);
49+ vec3 xyz = (texelFetch(InputBuffer, xy,0 ).rgb)+ 0.001 ;
50+ float br = (xyz.r+ xyz.g+ xyz.b)/ 3.0 ;
51+ xyz/= br;
52+ br = nlmeans(xy);
53+ Output = clamp (xyz* br,0.0 ,1.0 );
54+ // float noisefactor = clamp(textureLinear(NoiseMap, vec2(xy)/vec2(size)).r,0.0005,0.6);
55+ // Output = vec3(noisefactor*1.9);
56+ }
0 commit comments