15 #define PF_MAX_LAYERS 12 17 ofFbo downs[PF_MAX_LAYERS];
18 ofFbo ups [PF_MAX_LAYERS];
30 void init(
int _w,
int _h,
int _depth){
33 depth = min(PF_MAX_LAYERS,_depth);
35 for (
int i = 0; i < depth; i++){
38 downs[i].allocate(_w,_h,GL_RGBA);
40 for (
int i = 0; i < depth; i++){
43 ups[i].allocate(_w,_h,GL_RGBA);
45 shader = shader2way();
55 int _depth = log2(min(_w,_h))-1;
64 pass(downs[0],&tex,NULL);
65 for (i = 1; i < depth; i++){
66 pass(downs[i],&(downs[i-1].
getTexture()),NULL);
70 for (i = 1; i < depth-1; i++){
73 pass(ups[depth-1],&tex,&(ups[depth-2].
getTexture()));
80 return ups[depth-1].getTexture();
83 void pass(ofFbo& p, ofTexture* tex1, ofTexture* tex2){
96 shader.setUniformTexture(
"unf",*tex1,1);
98 shader.setUniformTexture(
"fil",*tex2,2);
100 shader.setUniform1i(
"isup",tex2 != NULL);
102 ofDrawRectangle(0,0,p.getWidth(),p.getHeight());
108 ofShader shader2way(){
110 sh.setupShaderFromSource(GL_FRAGMENT_SHADER, R
"( 112 uniform sampler2DRect unf; 113 uniform sampler2DRect fil; 119 if (i == 0 || i == 4){ 122 if (i == 1 || i == 3){ 129 if (i == 0 || i == 2){ 137 int i = int(gl_FragCoord.y-0.5); 138 int j = int(gl_FragCoord.x-0.5); 145 vec4 acc = vec4(0.0,0.0,0.0,0.0); 146 for (int dy = -2; dy <= 2; dy++) { 147 for (int dx = -2; dx <= 2; dx++) { 151 // if (nx < 0 || nx >= w || ny < 0 || ny >= h){ 155 vec4 col = texture2DRect(unf, vec2(float(nx)+1.0, float(ny)+1.0)); 157 acc.r += h1(dx+2) * h1(dy+2) * col.r; 158 acc.g += h1(dx+2) * h1(dy+2) * col.g; 159 acc.b += h1(dx+2) * h1(dy+2) * col.b; 160 acc.a += h1(dx+2) * h1(dy+2) * col.a; 166 gl_FragColor = vec4(acc.r/acc.a,acc.g/acc.a,acc.b/acc.a,1.0); 172 vec4 acc = vec4(0.0,0.0,0.0,0.0); 173 for (int dy = -1; dy <= 1; dy++) { 174 for (int dx = -1; dx <= 1; dx++) { 178 // if (nx < 0 || nx >= w || ny < 0 || ny >= h){ 182 vec4 col = texture2DRect(unf, vec2(float(nx)+1.0, float(ny)+1.0)); 184 acc.r += G(dx+1) * G(dy+1) * col.r; 185 acc.g += G(dx+1) * G(dy+1) * col.g; 186 acc.b += G(dx+1) * G(dy+1) * col.b; 187 acc.a += G(dx+1) * G(dy+1) * col.a; 190 for (int dy = -2; dy <= 2; dy++) { 191 for (int dx = -2; dx <= 2; dx++) { 196 // if (nx < 0 || nx >= w/2 || ny < 0 || ny >= h/2){ 199 vec4 col = texture2DRect(fil, vec2(float(nx), float(ny))); 201 acc.r += h2 * h1(dx+2) * h1(dy+2) * col.r; 202 acc.g += h2 * h1(dx+2) * h1(dy+2) * col.g; 203 acc.b += h2 * h1(dx+2) * h1(dy+2) * col.b; 204 acc.a += h2 * h1(dx+2) * h1(dy+2) * col.a; 210 gl_FragColor = vec4(acc.r/acc.a,acc.g/acc.a,acc.b/acc.a,1.0); Definition: ofxPoissonFill.hpp:16
ofTexture & getTexture()
Get the processed output.
Definition: ofxPoissonFill.hpp:79
void init(int _w, int _h, int _depth)
Initialize Poisson filler and allocate necessary datastructures.
Definition: ofxPoissonFill.hpp:30
void process(ofTexture &tex)
Process a texture (RGBA)
Definition: ofxPoissonFill.hpp:62
void init(int _w, int _h)
Initialize Poisson filler and allocate necessary datastructures.
Definition: ofxPoissonFill.hpp:54