Hello,
I would like to wrap a shader I wrote to the surface of a mesh, animating the surface of the 3D object. I suppose turning the shader into a texture is the way to go. So, my current approach has been to draw the shader to an ofFbo and then get the texture from the fbo, bind it and draw the mesh but this doesn’t seem to work. (the shader runs fine and works on a 2d surface) Please let me know what I’m doing wrong or if there’s a better approach. Thanks!
void ofApp::setup(){
ofBackground(0,0,0);
ofDisableAlphaBlending();
ofEnableDepthTest();
windowSize.set((float)ofGetWidth()*1.0, (float)ofGetHeight()*1.0);
// setup mesh
mesh.setMode(OF_PRIMITIVE_LINES);
mesh.enableColors();
mesh.enableIndices();
// create vertices for mesh
for (int y = 0; y < windowSize.y; y++){
for (int x = 0; x < windowSize.x; x++){
if( x == 0 && y == 0) {
glm::vec3 p( 0., 0., 0.);
mesh.addVertex(p);
mesh.addColor(ofFloatColor(255,255,255));
}
// space vertices out
if( (y * x) > 0 && (y * x) % meshVertDivisor == 0) {
glm::vec3 p( float(x), float(y), 0.);
mesh.addVertex(p);
mesh.addColor(ofFloatColor(255,255,255));
}
}
}
shader.load(shaderPath+shaderName);
ofDisableArbTex();
// frame buffer object
fbo.allocate(windowSize.x, windowSize.y, GL_RGBA);
}
void ofApp::draw(){
fbo.begin();
ofClear(255,255,255, 0);
shader.begin();
shader.setUniform1f("u_timef", nowf);
shader.setUniform2f("u_resolution", windowSize.x, windowSize.y );
shader.end();
fbo.end();
texture = fbo.getTexture();
cam.begin();
ofPushMatrix();
ofTranslate(-windowSize.x*.5, -windowSize.y*.5);
texture.bind();
mesh.draw();
texture.unbind();
ofPopMatrix();
cam.end();
}