Greetings,
I am trying to recreate @perevalovds sampled slit scan example from his book “Mastering openFrameworks” but using glsl, as my project has other heavier CPU side processing.
When I compile the code below I only get a black screen where the image is to be drawn.
I think I see what I am doing wrong, that is not accessing the correct texture coordinate in shader.frag but I dont seam to be able to figure out how to do that correctly. For reference you can see the code here
Here is my relevant code below
// shader.vert
#version 460
uniform mat4 modelViewProjectionMatrix;
in vec4 position;
in vec2 texcoord;
out vec2 texCoord;
void main()
{
gl_Position = modelViewProjectionMatrix * position;
texCoord = texcoord;
}
// shader.frag
#version 460
uniform sampler2D frames;
uniform vec2 mousePos;
uniform int fSize;
in vec2 texCoord;
out vec4 outputColor;
void main()
{
float dist = distance(mousePos, texCoord.xy);
float f = dist / 8;
int i0 = int(f);
int i1 = i0+1;
float interopAmt = i1 - f;
i0 = clamp(i0, 0, fSize);
i1 = clamp(i1, 0, fSize);
vec2 co1, co2;
co1.x = i0;
co1.y = i0;
co2.x = i1;
co2.y = i1;
vec4 col0 = texture(frames,co1);
vec4 col1 = texture(frames,co2);
outputColor = col1 * interopAmt + (col1 * (1 - interopAmt));
}
ofVideoGrabber video;
deque<ofPixels> frames;
int N;
ofTexture imgTexture;
ofImage image;
ofShader shader;
void ofApp::setup()
{
video.initGrabber(640, 480);
ofSetLogLevel(OF_LOG_VERBOSE);
N = 150;
shader.load("shader.vert", "shader.frag");
image.allocate(640, 480, OF_IMAGE_COLOR);
}
//--------------------------------------------------------------
void ofApp::update()
{
video.update();
glm::vec2 mousePos(mouseX, mouseY);
shader.setUniform2f("mousePos", mousePos);
if (video.isFrameNew()) {
frames.push_front(video.getPixels());
if (frames.size() > N) {
frames.pop_back();
}
}
shader.setUniform1i("fSize", frames.size());
if (!frames.empty()) {
imgTexture.loadData(frames[0]);
shader.setUniformTexture("frames", imgTexture, 0);
}
}
//--------------------------------------------------------------
void ofApp::draw()
{
ofBackground(255, 255, 255);
shader.begin();
// image.bind();
image.draw(0, 0);
shader.end();
// image.unbind();
}
Would someone be kind enought to take out the time to read through this mess and help me?