ofDisableArbTex() and blur shader

hi all,

I have a custom shader to process the pixels in a texture that I have to use ofDisableArbTex() with to get it to work. However, I also need to use blur but when calling this none of the blur shader addons will work.

I’m a bit fuzzy on why I need to call ofDisableArbTex() in the first place. Can anyone offer any advice on how to approach this?

Best,
nay.

p.s. on a macbook pro retina, latest OSX 10.8.x

btw, this is the frag shader I want to use at the same time as the blur (simply turns black to faded white and white to clear - using with ofxOpenNI masks):

  
#version 120  
  
uniform sampler2D tex0;  
uniform float opacity;  
  
void main(void)  
{  
  
	vec4 col = texture2D( tex0, gl_TexCoord[0].xy);  
	//float average = (col.r + col.g + col.b) / 3.0;  
    float average = col.r;  
  
	if (average > 0.5)  
	{  
		col.a = 0.0;  
	} else {  
	    col.r = 1.0;  
	    col.g = 1.0;  
	    col.b = 1.0;  
	    col.a = col.a*opacity;  
	}  
  
	gl_FragColor = col;  
  
}  

from reading I assume the best option is to get this to work with non power of 2 textures like the blur shaders, but not sure how to go about this.

It should work just fine if you change sampler2D to sampler2DRect and texture2D to texture2DRect

  
  
#version 120    
    
uniform sampler2DRect tex0;    
uniform float opacity;    
    
void main(void)    
{    
    
    vec4 col = texture2DRect( tex0, gl_TexCoord[0].xy);    
    //float average = (col.r + col.g + col.b) / 3.0;    
    float average = col.r;    
    
    if (average > 0.5)    
    {    
        col.a = 0.0;    
    } else {    
        col.r = 1.0;    
        col.g = 1.0;    
        col.b = 1.0;    
        col.a = col.a*opacity;    
    }    
    
    gl_FragColor = col;    
    
}    
  

unless I’m missing something else, that should work.

thanks tim, i did eventually get the shader to work with arb textures using:

  
  
 #extension GL_ARB_texture_rectangle : enable  
...  
  
vec2 st = gl_TexCoord[0].st;  
     vec4 col =  texture2DRect(tex0, st);  

However, the blur still doesn’t work. I also realised it renders fine to screen but if I draw to an fbo, then when I draw this to screen it is all messed up. so something definitely screwy.

Anything else I should be looking at?
Cheers,
nay.

nay,

If you post the relevant code, I’ll have a better idea of what’s going on. Also, what do you mean by all messed up?

sorry tim,
app is massive but here’s the snippet:

  
//                        fbo.begin();  
                        //ofClear(255,0);  
                        shaderMask.begin();  
                        shaderMask.setUniform1f("opacity", g->kinectMaskOpacity/255.0f);  
                        shaderMask.setUniformTexture("tex0", user.getMaskTextureReference(), 0);  
                        ofEnableAlphaBlending();  
                        drawPlane(INPUT_W,INPUT_H,p.x,p.y);//draws textured quad  
                        shaderMask.end();  
//                        fbo.end();  
//  
//                        fbo.draw(0,0);  
  
//                        shaderBlur.begin();  
//                        fbo.draw(0,0);  
//                        shaderBlur.end();  
//                        shaderBlur.draw();  
  

draws fine with commented out lines, but if I draw to fbo then draw, or if I use blur on the fbo or the uncommented draw code I get glitches that look like graphics memory access errors. if I call clear at the start of the fbo it stays clear and never ends up with anything in it. I am about to leave my desk for a while now but will check back in later today or tomorrow morn at latest. any help appreciated!
thanks,
nay.

Hmm, well the only thing I can think of at the moment is that you might be drawing outside the boundary of the FBO. If your FBO is the same size as that textured quad you’re drawing, make sure you draw the quad at (0,0) then draw the FBO where you want the quad to be.

Maybe that’s too simple a solution but its all I can see from the code right now, not knowing the dimensions of the FBO or the position that the quad is drawn at.

hey tim,

so I moved around my convoluted draw code to make sure that wasn’t the prob and sure enough the fbo started working. I then tried the current blur addons but they all had a trailing effect where as my alpha mask moved around eventually the entire area would become filled in and stay that way. I added a clear() function to the blur addons to clear the ping pong FBOs that I could call each frame to stop this happening. Now it all works!

Thanks for helping out and sorry I wasn’t more clear form the beginning.
best,
nay.

Great, glad you got it all working!