Okay I had the time to check out your shader, and I have a variant of your code working on my machine.
So first, why are you using
ofSetBackgroundAuto(false)? I can’t seem to figure out a reason why. When the shader is drawn, it’s result is getting blended into the background of the screen. Since you aren’t clearing the screen, and since blending is enabled, each frame is blended into whatever is on the screen. The easy fix would be to set background auto to true or add an
ofBackground(0) before starting your shader.
Beyond that, does your shader work as you expected? I had to make a series of tweaks both in
testApp.cpp and in the shader to get it working. I’ll list them out in case it might be helpful:
float snoise(vec2 v) This function is not defined in what you posted, so maybe I’m just missing some code. I pulled an implementation from here.
I used GLSL version 150 (the version that corresponds to openGL 3.2), so I had to change
gl_FragCoord.xy, and define an
out vec4 outputColor to use instead of
gl_FragColor. (Using this version of GLSL is probably more of a convention choice than anything else.)
texture0 isn’t assigned a value in the code you posted. To do that,
testApp.cpp's draw becomes:
shader.setUniform1f( "time", ofGetElapsedTimef() );
shader.setUniform1i( "circleRadius", 200 );
shader.setUniform2f( "mouse", mouseX, ofGetHeight()-mouseY );
shader.setUniformTexture( "texture1", fbo2.getTextureReference(), 1 );
ofSetColor( 255, 255, 255 );
fbo.draw( 0, 0 );
I also had to mirror the image over the x-axis, since textures coordinates in openGL are measured from the bottom left of a texture, whereas openFrameworks coordinates are the upper left.
Other small points:
I’m a little confused as to why you are doing a masking with a circle and also doing a fragment shader that does a masking with a nosily growing/shrinking circle. (Though I haven’t read “Mastering openFrameworks,” so I don’t have the complete context.) You are calculating a noisy circle radius for each fragment. The only thing that the noise depends on is the current time, so each fragment is running the same calculation. It seems like you would want to send a uniform noisyRadius to the shader, letting the CPU calculate the noise.
Also, the calculation using
fbo2's circle texture seems redundant for the moment. The fragment can calculate it’s color purely based on distance from the mouse. This would not be true if
fbo2 contained another image - like a picture of the sky - to be used as the mask. I assume that’s what you have planned.
Hopefully some chunk of this is useful to you and helps solve your issues getting the code working as you want.