I'm doing a university project and have got everything in place for a shader-tastic engine. I managed to get shadow mapping, bump mapping & phong lighting done in one shader and it is coming to the point where I'll probably have to split these up and do them each in passes. Especially if I'm going to implement bloom/motion blur and other post-processing effects.
My question is, how? When doing shadow mapping you have quite a few passes there for each light but the general thing is:
change pov light -> render scene -> change pov camera -> render scene -> apply shadow.
The way I've done shadow mapping is via an fbo and I was thinking, are multi-pass rendering generally rendering to an fbo, saving the results to a texture attached to the fbo, run the 2nd shader on this texture, saving to another fbo, etc. at the end render the resulting texture as a quad on the screen? So in pseudocode:
setupFbo()
{
glGenBuffers(fbo1, etc..)
bindTexture1, bindTexture2, etc.
glFrameBufferTexture2DEXT(... GL_COLOR_ATTACHMENT0...etc. )
}
render()
{
glBindFramebufferEXT(fbo1);
// Pass 1
glClear(COLOR | DEPTH);
shader1->enable();
render scene
shader1->disable();
glBindFramebufferEXT(0);
// pass 2
glClear(COLOR | DEPTH);
glBindFramebufferEXT(fbo2);
glActiveTextureARB(0);
glBindTexture(TEXTURE_2D, fbo1_texHandle);
shader2->enable();
render scene ??????
shader2->disable();
// pass 3
...
shader3->enable();
render scene ??????
shader3->disable();
glBindTexture(TEXTURE_2D, fbo3_texHandle);
create quad size of window
draw it
}
Is that it generally the way to do it? Anything else I'm missing? Do I have to render the scene each time? Also, are there any coding GLSL practices that I need to do so that my project can run decently on both ati/nvidia hardware? The reason I ask is that I've got an ati 3850 card at home and when I render my scene everything runs great. The university machines are more powerful quad machines with GTX 260 but I ran it on them and it's like a slideshow. After coming home and thinking about it, I think there is one part that is the culprit where I used 1 shader for all my objects, e.g.
phongShader->enable();
drawObjects()
{
cube.draw();
sphere.draw();
}
phongShader->disable();
The phong shader makes use of texture unit 0 to apply textures and so each object has a glActiveTexture(0), bindTexture... in their draw methods. I'm wondering whether nvidia doesnt like it and prefers to do:
phongShader->enable();
cube.draw()
phongShader->disable();
phongShader->enable();
sphere.draw();
phongShader->disable();
I might have to do this anyway because I'll be moving the shaders into the materials for each object but would this be causing the slowdown? I'm also wondering if I'll need to structure my code differently so that it runs good on both ati/nvidia hardware, especially when it comes to multi-pass stuff. Any advice on the matter would be appreciated. Thanks in advance everyone.