Questions about using shaders for image processing (broken example attached)

I’m still getting pretty stuck on using shaders for just plain image processing. Had plans to take some of the shaders from Jitter and just break them apart and use them in OF but I’m not having the best luck so far, and it’s probably just something fundamental that I’m missing.

I’ve attached a (OS X) project with a shader that should just let you control brightness/contrast/saturation of the image, but I’m just getting black.

Anyone have any tips on what I might be missing to make my dreams come true?

shader_Texturetest.zip

I don’t see the texture getting bound anywhere, you need to either call

  
vidGrabber.getTextureReference().bind();  

of

  
shader.setUniformTexture("tex", vidGrabber.getTextureReference(), 1);  

somewhere so that your shader knows which texture to use. Also, if you’re going to use gl_MultiTexCoord0 you have to set up your texture coordinates with glMultiTexCoord2f() or glMultiTexCoord2d(), which isn’t necessary unless you have multiple texture coordinates, you should just be able to use gl_FragCoord. Hope that helps a little bit,

Thanks Josh, the binding part makes a lot of sense, I was wondering how it knew what to grab from where.

I’m not as clear on the gl_MultiTexCoord0 bit. I tried swapping instances of texcoord in my fragment shader with gl_FragColor but that isn’t working out either.

Is using the OpenGl Shader Builder that comes with the graphical developer tools a reasonable one to test things out on if I’m just doing image processing, not lighting/geometry stuff?

I had gotten it non-black at some point, but I broke something somewhere and it’s back to black.

Here are the shaders for anyone who doesn’t have time to download

Frag:

  
const vec3 LumCoeff = vec3 (0.2125, 0.7154, 0.0721);  
  
varying vec2 texcoord;  
uniform sampler2DRect image;  
  
uniform vec3 avgluma;  
uniform float saturation;  
uniform float contrast;  
uniform float brightness;  
uniform float alpha;  
  
void main (void)  
{  
	vec3 texColor  	= texture2DRect(image, texcoord).rgb;  
	vec3 intensity 	= vec3 (dot(texColor, LumCoeff));  
	vec3 color     	= mix(intensity, texColor, saturation);  
	color          	= mix(avgluma, color, contrast);  
	color			*= brightness;  
	gl_FragColor   	= vec4 (color, color.g*alpha);  
}  

Vertex:

  
varying vec2 texcoord;  
  
void main (void)  
  
{  
    gl_Position = ftransform();  
    texcoord    = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);  
}  

Other relevant code:

  
void testApp::setup(){  
      
    ofSetLogLevel(OF_LOG_VERBOSE);  
		ofSetVerticalSync(false);  
	//ofEnableAlphaBlending();  
   // ofDisableArbTex();  
    camWidth=640;  
    camHeight = 480;  
    vidGrabber.initGrabber(camWidth, camHeight);  
    tex1.allocate(camWidth,camHeight,GL_RGB);  
    shader.load("shaders/brcosa.vert", "shaders/brcosa.frag");	  
      
    shader.setUniform3f("avgluma", 0.62,0.62,0.62);  
    shader.setUniform1f("contrast", 1.0);  
    shader.setUniform1f("brightness", 1.0);  
    shader.setUniform1f("saturation", 1.0);  
    shader.setUniform1f("alpha", 1.0);  
  
  
}  
  
//--------------------------------------------------------------  
void testApp::update(){  
    vidGrabber.grabFrame();  
      
    if (vidGrabber.isFrameNew()) {  
        tex1=vidGrabber.getTextureReference();  
    }  
      
}  
  
//--------------------------------------------------------------  
void testApp::draw(){  
    ofBackgroundGradient(ofColor::gray, ofColor::black);  
  
      
    shader.begin();  
        shader.setUniformTexture("image", tex1, 1);  
        tex1.draw(0,0);  
    shader.end();  
}