   Program not using shaders properly (or other errors)
  Hi there. Once again I'm back with a new problem. I'm doing a multipass rendering where I'm trying to implement depth of field. The shaders I use are directly taken from a finished working(!) project in depth of field so as far as I know there shouldn't be anything wrong with the vertex and fragment shaders provided as they are already shown to work in that project.The shaders that I use can be downloaded from the following website: http://encelo.netsons.org/programming/openglfrom the GLSL_DoF2 project. In any way I will post all of them here for the time being.I've almost implemented this project in the same way done in the GLSL_DoF2 project, the only difference being the objects I use (teapots, skybox). I also create a function for each pass I want to do which is later called in the display function. Some other minor differences exist as well.I'll try to explain this as good as I can, let's go through what each pass does first:The first pass attach the scene to a framebuffer objectThe second pass downsample the image to 1/4th of the original sizeThe third and fourth are supposed to implement the Gaussian blurThe fifth pass is where the final image is renderedThe sixth pass (called blurTestPass in the code) is used to see where the focus is on the scene. In other words the parts in the scene covered in black will be on focus i.e they will be sharp while the rest of the scene is blurred.In any way here's the PROBLEM. What seems to work so far for me is only the first pass (not entirely sure but it seems that way) and the sixth pass. In the fifth pass I'm supposed to activate two textures (img0 and img1). From what I've understood these textures are supposed to be the one I get from the first pass (img0) and the one I get from pass 2-4 (img1). However only the first pass seem to work properly (I get the scene back)..but there is no blur effect which pass 2-4 should be responsible for. Changing the focal distance doesn't create any blur either on the scene. While I'm not entirely sure my guess is that pass 2-4 are not working as they are supposed to. I've made sure to check and see if each shader is actually read by typing some random letters in them and the program complained each time it tried to read them so they are actually all used and as I mentioned they are already used in a working project of DoF so the problem shouldn't lie in the shaders themselves from what I understand. I also follow the way each pass is supposed to be done very closely (with minor difference) compared to the person I took the shaders from.I'll post part of my codes which seem most relevant to this problem, however if anyone need other parts of the code or the whole code let me know.Also to avoid having anyone (that will be kind enough to help me out) having to scroll down through alot of different source tags I will put all the shader code in the same source tag and indicate when a new shader start by some comment. Of course as usual these should all be divided into vertex and fragment shaders.If you prefer to have every shader by itself then let me know so I can modify my post.Here's the code for the initialization of fbo, functions for the different passes, the display and main function:void initFbo(){//Create a framebuffer objectglGenFramebuffersEXT(1, &fbo); //Frame bufferglGenRenderbuffersEXT(1, &depthbuffer); //render bufferglGenTextures(1, &img0); //texture 1glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fbo);//initialize textureglBindTexture(GL_TEXTURE_2D, img0);glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA16F_ARB,windowWidth,windowHeight,0,GL_RGBA,GL_FLOAT,NULL);//Parameters for texture 1glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);  glGenerateMipmapEXT(GL_TEXTURE_2D);//attach texture to framebuffer color bufferglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D, img0,0);///////////////initialize second texture (img1)   ///////////////initialize third texture  (img 2)   //Done in the same way as the initialization of the first texture   //with different GL_COLOR_ATTACHMENT   //initialize depth renderbufferglBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthbuffer);glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,GL_DEPTH_COMPONENT24,windowWidth,windowHeight);//attach renderbuffer to framebuffer depth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT,depthbuffer);}void initUniformVariables(){glUseProgram(programObj3);loc = glGetUniformLocation(programObj3, "Width");if(loc == -1) fprintf( stderr, "Binding warning: Failed to locate uniform variable 'Wi'.\n");glUniform1i(loc, windowWidth*2);glUseProgram(programObj4);loc = glGetUniformLocation(programObj4, "Height");if(loc == -1) fprintf( stderr, "Binding warning: Failed to locate uniform variable 'He'.\n");glUniform1i(loc, windowHeight*2);glUseProgram(programObj5);loc = glGetUniformLocation(programObj5, "Tex0");if(loc == -1) fprintf( stderr, "Binding warning: Failed to locate uniform variable 'Tex0'.\n");glUniform1i(loc, 0);loc = glGetUniformLocation(programObj5, "Tex1");if(loc == -1) fprintf( stderr, "Binding warning: Failed to locate uniform variable 'Tex1'.\n");glUniform1i(loc, 1);}void firstPass(){glEnable(GL_DEPTH_TEST);glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glActiveTexture(GL_TEXTURE0);glUseProgram(programObj1);loc = glGetUniformLocation(programObj1, "focalDistance");if(loc == -1) fprintf( stderr, "Binding warning: Failed to locate uniform variable 'focaldistance'.\n");glUniform1f(loc, focalDistance);if(loc == -1) fprintf( stderr, "Binding warning: Failed to locate uniform variable 'focalRange'.\n");loc = glGetUniformLocation(programObj1, "focalRange");glUniform1f(loc, focalRange);skybox();teapots();}void secondPass(){glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glBindTexture(GL_TEXTURE_2D, img0);glUseProgram(programObj2);glViewport(0, 0, windowWidth/2, windowHeight/2);drawQuad();}void thirdPass(){glDrawBuffer(GL_COLOR_ATTACHMENT2_EXT);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glBindTexture(GL_TEXTURE_2D, img1);glUseProgram(programObj3);drawQuad();}void fourthPass(){glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glBindTexture(GL_TEXTURE_2D, img2);glUseProgram(programObj4);drawQuad();}void fifthPass(){glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);glDrawBuffer(GL_BACK);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glActiveTexture(GL_TEXTURE0);glBindTexture(GL_TEXTURE_2D, img0);glActiveTexture(GL_TEXTURE1);glBindTexture(GL_TEXTURE_2D, img1);glOrtho(0.0,1.0,0.0,1.0,0.0,1.0);glUseProgram(programObj5);glViewport(0, 0, windowWidth, windowHeight);glBegin(GL_QUADS);glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0.0f);glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 0.0f);glVertex3f(0.0, 0.0,0.368);glMultiTexCoord2f(GL_TEXTURE0, 1.0f, 0.0f);glMultiTexCoord2f(GL_TEXTURE1, 1.0f, 0.0f);glVertex3f(1.0, 0.0,0.368);glMultiTexCoord2f(GL_TEXTURE0, 1.0f, 1.0f);glMultiTexCoord2f(GL_TEXTURE1, 1.0f, 1.0f);glVertex3f(1.0, 1.0,0.368);glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 1.0f);glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 1.0f);glVertex3f(0.0, 1.0,0.368);glEnd();}void blurTestPass(){glEnable(GL_TEXTURE_2D);glDisable(GL_LIGHTING);glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);glDrawBuffer(GL_BACK);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  glOrtho(0.0,1.0,0.0,1.0,0.0,1.0); //Testa ta bort senglBindTexture(GL_TEXTURE_2D, img0);glUseProgram(programObj6);drawQuad();glDisable(GL_TEXTURE_2D);}void display(){glClearColor(0.0,0.0,0.0,0.0);glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glClearDepth(1);glLoadIdentity();firstPass();if(focusCheck){secondPass();thirdPass();fourthPass();fifthPass();}else{blurTestPass();}glutSwapBuffers(); //Swap between the two buffers}void reshape(int w, int h){glViewport(0,0,(GLsizei)w,(GLsizei)h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(60.0,(GLfloat)w/(GLfloat)h,0.1,10000.0);glMatrixMode(GL_MODELVIEW); }int main(int argc, char **argv){glutInit(&argc, argv); //Initialize GLUTglutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA| GLUT_DEPTH); //Use a double buffer when displaying frames.glutInitWindowSize(windowWidth, windowHeight); glutInitWindowPosition(100, 100); glutCreateWindow("Test"); glewInit();glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);initFbo();createShaders();//initUniformVariables();glutDisplayFunc(display); glutIdleFunc (display);glutReshapeFunc(reshape); glutKeyboardFunc(keyboard);glutMouseFunc(processMouse);glutMotionFunc(processMouseActiveMotion);texture[0] = LoadTexture( "skylf.raw", 512, 512 );texture[1] = LoadTexture( "skyft.raw", 512, 512 );texture[2] = LoadTexture( "skyrt.raw", 512, 512 );texture[3] = LoadTexture( "skybk.raw", 512, 512 );texture[4] = LoadTexture( "skydn.raw", 512, 512 );texture[5] = LoadTexture( "skyup.raw", 512, 512 );texture[6] = LoadTexture( "tea.raw", 500, 500 );glutMainLoop(); //Start the OpenGL loop-cyclefor(int i=0; i<6; i++){FreeTexture(texture);}return 0;}Here's the code for all shaders (can be downloaded otherwise by the URL mentioned above)//Name: first.vert//Vertex shader used for the first pass//-------------------------------------uniform float focalDistance, focalRange;varying float Blur;void main(void){vec4 PosWV = gl_ModelViewMatrix * gl_Vertex;Blur = clamp(abs(-PosWV.z - focalDistance) / focalRange, 0.0, 1.0);gl_Position = ftransform();gl_TexCoord[0] = gl_MultiTexCoord0;}//-------------------------------------//Name: first.frag//Fragment shader used for the first pass//-------------------------------------varying float Blur;uniform sampler2D Tex0;void main (void){gl_FragData[0] = vec4(texture2D(Tex0, gl_TexCoord[0].st).rgb, Blur);}//-------------------------------------//Name: second.vert//Second vertex shader used for the second pass//-------------------------------------void main(void){gl_Position = ftransform();gl_TexCoord[0] = gl_MultiTexCoord0;}//-------------------------------------//Name: second.frag//Second fragment shader used for the second pass//-------------------------------------uniform sampler2D Tex0;void main (void){gl_FragData[0] = texture2D(Tex0, gl_TexCoord[0].st);}//-------------------------------------//Name: third.vert//Third vertex shader used for the third pass//-------------------------------------varying vec2 Tap[4], TapNeg[3];uniform int Width;void main(void){vec2 horzTapOffs[7];vec2 TexCoord = gl_MultiTexCoord0.st;float dx = 1.0/float(Width);horzTapOffs[0] = vec2(0.0, 0.0);horzTapOffs[1] = vec2(1.3366 * dx, 0.0);horzTapOffs[2] = vec2(3.4295 * dx, 0.0);horzTapOffs[3] = vec2(5.4264 * dx, 0.0);horzTapOffs[4] = vec2(7.4359 * dx, 0.0);horzTapOffs[5] = vec2(9.4436 * dx, 0.0);horzTapOffs[6] = vec2(11.4401 * dx, 0.0);Tap[0] = TexCoord;Tap[1] = TexCoord + horzTapOffs[1];Tap[2] = TexCoord + horzTapOffs[2];Tap[3] = TexCoord + horzTapOffs[3];TapNeg[0] = TexCoord - horzTapOffs[1];TapNeg[1] = TexCoord - horzTapOffs[2];TapNeg[2] = TexCoord - horzTapOffs[3];gl_Position = ftransform();gl_TexCoord[0] = gl_MultiTexCoord0;}//-------------------------------------//Name: third.frag//Third fragment shader used for the third pass//-------------------------------------varying vec2 Tap[4], TapNeg[3];uniform sampler2D Tex0;uniform int Width;void main (void){vec2 horzTapOffs[7];vec2 Tap4[3], TapNeg4[3];// Thresholds for computing sample weightsconst vec4 Thresh0 = vec4(0.1, 0.3, 0.5, -0.01);const vec4 Thresh1 = vec4(0.6, 0.7, 0.8, 0.9);// Samplesvec4 s[7], Weights4;vec3 Weights3, ColorSum;float WeightSum;float dx = 1.0/float(Width);horzTapOffs[0] = vec2(0.0, 0.0);horzTapOffs[1] = vec2(1.3366 * dx, 0.0); horzTapOffs[2] = vec2(3.4295 * dx, 0.0);horzTapOffs[3] = vec2(5.4264 * dx, 0.0);horzTapOffs[4] = vec2(7.4359 * dx, 0.0);horzTapOffs[5] = vec2(9.4436 * dx, 0.0);horzTapOffs[6] = vec2(11.4401 * dx, 0.0);// Sample taps with coordinates from VSs[0] = texture2D(Tex0, Tap[0]);s[1] = texture2D(Tex0, Tap[1]);s[2] = texture2D(Tex0, Tap[2]);s[3] = texture2D(Tex0, Tap[3]);s[4] = texture2D(Tex0, TapNeg[0]);s[5] = texture2D(Tex0, TapNeg[1]);s[6] = texture2D(Tex0, TapNeg[2]);// Compute weights for 4 first samples (including center tap)// by thresholding blurriness (in sample alpha)Weights4.x = clamp(s[1].a - Thresh0.x, 0.0, 1.0);Weights4.y = clamp(s[2].a - Thresh0.y, 0.0, 1.0);Weights4.z = clamp(s[3].a - Thresh0.x, 0.0, 1.0);Weights4.w = clamp(s[0].a - Thresh0.w, 0.0, 1.0);// Accumulate weighted samplesColorSum = vec3(s[0] * Weights4.x + s[1] * Weights4.y + s[2] * Weights4.z + s[3] * Weights4.w);// Sum weights using DOTWeightSum = dot(Weights4, vec4(1.0));// Compute weights for 3 remaining samplesWeights3.x = clamp(s[4].a - Thresh0.x, 0.0, 1.0);Weights3.y = clamp(s[5].a - Thresh0.y, 0.0, 1.0);Weights3.z = clamp(s[6].a - Thresh0.z, 0.0, 1.0);// Accumulate weighted samplesColorSum += vec3(s[4] * Weights3.x + s[4] * Weights3.y + s[6] * Weights3.z);// Sum weights using DOTWeightSum += dot(Weights3, vec3(1.0));// Compute tex coords for other tapsTap4[0] = Tap[0] + horzTapOffs[4];Tap4[1] = Tap[0] + horzTapOffs[5];Tap4[2] = Tap[0] + horzTapOffs[6];TapNeg4[0] = Tap[0] - horzTapOffs[4];TapNeg4[1] = Tap[0] - horzTapOffs[5];TapNeg4[2] = Tap[0] - horzTapOffs[6];// Sample the tapss[0] = texture2D(Tex0, Tap4[0]);s[1] = texture2D(Tex0, Tap4[1]);s[2] = texture2D(Tex0, Tap4[2]);s[3] = texture2D(Tex0, TapNeg4[0]);s[4] = texture2D(Tex0, TapNeg4[1]);s[5] = texture2D(Tex0, TapNeg4[2]);// Compute weights for 3 samplesWeights3.x = clamp(s[0].a - Thresh1.x, 0.0, 1.0);Weights3.y = clamp(s[1].a - Thresh1.y, 0.0, 1.0);Weights3.z = clamp(s[2].a - Thresh1.z, 0.0, 1.0);// Accumulate weighted samplesColorSum += vec3(s[0] * Weights3.x + s[1] * Weights3.y + s[2] * Weights3.z);// Sum weights using DOTWeightSum += dot(Weights3, vec3(1.0));// Compute weights for 3 samplesWeights3.x = clamp(s[3].a - Thresh1.x, 0.0, 1.0);Weights3.y = clamp(s[4].a - Thresh1.y, 0.0, 1.0);Weights3.z = clamp(s[5].a - Thresh1.z, 0.0, 1.0);// Accumulate weighted samplesColorSum += vec3(s[3] * Weights3.x + s[4] * Weights3.y + s[5] * Weights3.z);// Sum weights using DOTWeightSum += dot(Weights3, vec3(1.0));// Divide weighted sum of samples by sum of all weightsColorSum /= WeightSum;// Color and weights sum outputgl_FragData[0] = vec4(ColorSum, WeightSum);}//-------------------------------------//Name: fourth.vert//Fourth vertex shader used for the fourth pass//-------------------------------------varying vec2 Tap[4], TapNeg[3];uniform int Height;void main(void){vec2 vertTapOffs[7];vec2 TexCoord = gl_MultiTexCoord0.st;float dy = 1.0/float(Height);vertTapOffs[0] = vec2(0.0, 0.0);vertTapOffs[1] = vec2(0.0, 1.3366 * dy);vertTapOffs[2] = vec2(0.0, 3.4295 * dy);vertTapOffs[3] = vec2(0.0, 5.4264 * dy);vertTapOffs[4] = vec2(0.0, 7.4359 * dy);vertTapOffs[5] = vec2(0.0, 9.4436 * dy);vertTapOffs[6] = vec2(0.0, 11.4401 * dy);Tap[0] = TexCoord;Tap[1] = TexCoord + vertTapOffs[1];Tap[2] = TexCoord + vertTapOffs[2];Tap[3] = TexCoord + vertTapOffs[3];TapNeg[0] = TexCoord - vertTapOffs[1];TapNeg[1] = TexCoord - vertTapOffs[2];TapNeg[2] = TexCoord - vertTapOffs[3];gl_Position = ftransform();gl_TexCoord[0] = gl_MultiTexCoord0;}//-------------------------------------//Name: fourth.frag//Fourth fragment shader used for the fourth pass//-------------------------------------varying vec2 Tap[4], TapNeg[3];uniform sampler2D Tex0;uniform int Height;void main (void){vec2 vertTapOffs[7];vec2 Tap4[3], TapNeg4[3];const vec4 Weights0 = vec4(0.080, 0.075, 0.070, 0.100);const vec4 Weights1 = vec4(0.065, 0.060, 0.055, 0.050);// Samplesvec4 s[7];// Acumulated color and weightsvec4 ColorWeightSum;float dy = 1.0/float(Height);vertTapOffs[0] = vec2(0.0, 0.0);vertTapOffs[1] = vec2(0.0, 1.3366 * dy);vertTapOffs[2] = vec2(0.0, 3.4295 * dy);vertTapOffs[3] = vec2(0.0, 5.4264 * dy);vertTapOffs[4] = vec2(0.0, 7.4359 * dy);vertTapOffs[5] = vec2(0.0, 9.4436 * dy);vertTapOffs[6] = vec2(0.0, 11.4401 * dy);// Sample taps with coordinates from VSs[0] = texture2D(Tex0, Tap[0]);s[1] = texture2D(Tex0, Tap[1]);s[2] = texture2D(Tex0, Tap[2]);s[3] = texture2D(Tex0, Tap[3]);s[4] = texture2D(Tex0, TapNeg[0]);s[5] = texture2D(Tex0, TapNeg[1]);s[6] = texture2D(Tex0, TapNeg[2]);// Modulate sampled color values by the weights stored// in the alpha channel of each samples[0].rgb = s[0].rgb * s[0].a;s[1].rgb = s[1].rgb * s[1].a;s[2].rgb = s[2].rgb * s[2].a;s[3].rgb = s[3].rgb * s[3].a;s[4].rgb = s[4].rgb * s[4].a;s[5].rgb = s[5].rgb * s[5].a;s[6].rgb = s[6].rgb * s[6].a;// Aggregate all samples weighting them with pre-defined// kernel weights, weight sum in alphaColorWeightSum = s[0] * Weights0.w + (s[1] + s[4]) * Weights0.x + (s[2] + s[5]) * Weights0.y + (s[3] + s[6]) * Weights0.z;// Compute tex coords for other tapsTap4[0] = Tap[0] + vertTapOffs[4];Tap4[1] = Tap[0] + vertTapOffs[5];Tap4[2] = Tap[0] + vertTapOffs[6];TapNeg4[0] = Tap[0] - vertTapOffs[4];TapNeg4[1] = Tap[0] - vertTapOffs[5];TapNeg4[2] = Tap[0] - vertTapOffs[6];// Sample the tapss[0] = texture2D(Tex0, Tap4[0]);s[1] = texture2D(Tex0, Tap4[1]);s[2] = texture2D(Tex0, Tap4[2]);s[3] = texture2D(Tex0, TapNeg4[0]);s[4] = texture2D(Tex0, TapNeg4[1]);s[5] = texture2D(Tex0, TapNeg4[2]);// Modulate sampled color values by the weights stored// in the alpha channel of each samples[0].rgb = s[0].rgb * s[0].a;s[1].rgb = s[1].rgb * s[1].a;s[2].rgb = s[2].rgb * s[2].a;s[3].rgb = s[3].rgb * s[3].a;s[4].rgb = s[4].rgb * s[4].a;s[5].rgb = s[5].rgb * s[5].a; // Aggregate all samples weighting them with pre-defined// kernel weights, weight sum in alphaColorWeightSum += (s[1] + s[3]) * Weights1.x + (s[1] + s[4]) * Weights1.y + (s[2] + s[5]) * Weights1.z;// Average combined sample for all samples in the kernelColorWeightSum.rgb /= ColorWeightSum.a;// Final sum outputgl_FragData[0] = ColorWeightSum;}//-------------------------------------//Name: fifth.vert//Fifth vertex shader used for the fifth pass//-------------------------------------void main(void){gl_Position = ftransform();gl_TexCoord[0] = gl_MultiTexCoord0;gl_TexCoord[1] = gl_MultiTexCoord1;}//-------------------------------------//Name: fifth.frag//Fifth fragment shader used for the fifth pass//-------------------------------------uniform sampler2D Tex0, Tex1;void main (void){vec4 Fullres = texture2D(Tex0, gl_TexCoord[0].st);vec4 Blurred = texture2D(Tex1, gl_TexCoord[1].st);// HLSL linear interpolation functiongl_FragColor = Fullres + Fullres.a * (Blurred - Fullres);}//-------------------------------------//Name: renderblur.frag//Sixth fragment shader used for the blurTestPass pass-function. //IMPORTANT: This one use the fifth vertex shader as well so there is no sixth vertex shader, only five!//-------------------------------------uniform sampler2D Tex0;void main (void){vec4 Fullres = texture2D(Tex0, gl_TexCoord[0].st);gl_FragColor = vec4(vec3(Fullres.a), 1.0);}//-------------------------------------[Edited by - Zaftwave on May 18, 2010 3:51:57 PM]
Quote:In any way here's the PROBLEM. What seems to work so far for me is only the first pass (not entirely sure but it seems that way) and the sixth pass. In the fifth pass I'm supposed to activate two textures (img0 and img1). From what I've understood these textures are supposed to be the one I get from the first pass (img0) and the one I get from pass 2-4 (img1). However only the first pass seem to work properly (I get the scene back)..but there is no blur effect which pass 2-4 should be responsible for. Changing the focal distance doesn't create any blur either on the scene.While I'm not entirely sure my guess is that pass 2-4 are not working as they are supposed to. I've made sure to check and see if each shader is actually read by typing some random letters in them and the program complained each time it tried to read them so they are actually all used and as I mentioned they are already used in a working project of DoF so the problem shouldn't lie in the shaders themselves from what I understand. I also follow the way each pass is supposed to be done very closely (with minor difference) compared to the person I took the shaders from.I'm going to suggest that you try to narrow down your problem a little bit more into something manageable. You've got a mountain of code there and its going to require a very ambitious/generous helper to sift through all that, and I'll suggest that you not wait for this mythical person :)You should do some more shader debugging to narrow down the problem. If you suspect that pass 2 is not doing anything, then change the shader to just output yellow for every fragment. You'll find out pretty quick if that shader is active or not. Also try to just add in one pass at a time. Render your first pass only, does it look correct? Check it off. Add the second pass, does that look correct? I know this is frustrating without a proper debugger, but that just means you have to be very thorough and methodical about what you're testing. Don't just throw everything in together try to guess at whats happening. Don't just try adding random debugging steps hoping that you'll hit on the problem. Every debugging trick you try should take more "unknowns" and make them "knowns", so you'll narrow down bit by bit what could be failing.  Validate the output of every stage before you connect it to the next stage.I know its probably not the answer you're looking for, but I hope that helps :)   ;  Yeah I'll take your hint and do some more debugging on each shader instead and see whether its correct or not. I'll also modify my previous post and remove some unneccesary parts of the code in the main file where I doubt the problem lies in to make it shorter :)If anyone would want to run the whole code though then just let me know.   ;  ***********************UPDATE************************So I've tried a few things now. The first thing was that I asked around a bit and was told to use multiple framebuffer objects for each pass I wanted to go through. So I made a total of four framebuffer objects for four passes. It did not work so I made sure that there didn't exist any problems in my whole FBO setup so I put all possible error checks (all I could find in the OpenGL documentation) in a method I created and then used this method for each FBO I created and none of them complained when they were checked so I concluded that my error did not exist there.Now for my shaders. The first thing I did was to output a red color in the very first fragment shader I use (gl_FragColor(1.0,0.0,0.0,0.0) or something alike) and used it in my first pass and instead of the first pass being responsible for drawing my scene I just got red color so I confirmed that it worked. I then tried the exact same approach for my second, third and fourth fragment shaders (each used for the second, third and fourth pass) but I got no change whatsoever when I rendered the texture from the first pass and putted it together with the the texture affected by pass 2-4. I still just had the red color. At first I thought there might be something wrong in my shaders used from pass 2-4 however I checked my fifth fragment shader which looks like the following way:Fifth fragment shader---------------------uniform sampler2D Tex0, Tex1;void main (void){vec4 Fullres = texture2D(Tex0, gl_TexCoord[0].st);vec4 Blurred = texture2D(Tex1, gl_TexCoord[1].st);//vec4 Blurred = vec4(1.0,0.0,0.0,0.0); <------------ **// HLSL linear interpolation function//gl_FragColor = Fullres + Fullres.a * (Blurred - Fullres);//GLSL linear interpolation function.gl_FragColor = mix(Fullres,Blurred,Fullres.a);}The point is that the final fragment shader is supposed to take the original scene which was attached to the first texture (done in the first pass, the 'Fullres' variable) and take the 1/4th downsampled blurred texture (done in pass 2-4, the 'Blurred' variable) and then use a linear interpolation for them. As you can see this is done in the fragment but only the Fullres variable is used..I just get my original scene back without any blur effect whatsoever. I figured out that this meant that the following part of the code above:vec4 Blurred = texture2D(Tex1, gl_TexCoord[1].st);is never used or something alike. To make sure of this I simply putted the 'Blurred' variable to a red output (as seen on the line of code below it marked by an arrow and **) and then tried a linear interpolation with the two variables (Fullscreen and the red output Blurred variable) and this worked. I got a red scene with my objects (belonging to the original scene) behind this red color (well something like that..it worked regardless.)Once I checked that the linear interpolation worked properly I just simply commented that line of code above and the result was that I just got my scene back with no blur effect (which isn't strange at all). If I putted that code back then the effect was that my screen became black instead (which is the result I had from the beginning). However my object would still be visible if I changed the focal distance (the calculation and use of focal distance and other things is done in the first pass with the first shaders and they work as they should).So simply put the texture I apply that goes through pass 2-4 gives me a black color effect, its supposed to give me a blur effect...not a black effect. Unfortunately(?) this is how much I've been able to limit this problem. I'll post the section of my code where I perform the multipass rendering:Multipass rendering:---------------------void firstPass(){glEnable(GL_DEPTH_TEST);glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo0);glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glActiveTexture(GL_TEXTURE0);glUseProgram(programObj1);loc = glGetUniformLocation(programObj1, "focalDistance");if(loc == -1) fprintf( stderr, "Binding warning: Failed to locate uniform variable 'focaldistance'.\n");glUniform1f(loc, focalDistance);if(loc == -1) fprintf( stderr, "Binding warning: Failed to locate uniform variable 'focalRange'.\n");loc = glGetUniformLocation(programObj1, "focalRange");glUniform1f(loc, focalRange);skybox();teapots();}void secondPass(){//glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo1);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glBindTexture(GL_TEXTURE_2D, img0);glUseProgram(programObj2);glPushAttrib(GL_VIEWPORT_BIT);glViewport(0, 0, windowWidth/2, windowHeight/2);drawQuad();}void thirdPass(){//glDrawBuffer(GL_COLOR_ATTACHMENT2_EXT);glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo2);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glBindTexture(GL_TEXTURE_2D, img1);glUseProgram(programObj3);drawQuad();}void fourthPass(){//glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo3);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glBindTexture(GL_TEXTURE_2D, img2);glUseProgram(programObj4);drawQuad();}void fifthPass(){glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);glDrawBuffer(GL_BACK);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glActiveTexture(GL_TEXTURE0);glBindTexture(GL_TEXTURE_2D, img0);glActiveTexture(GL_TEXTURE1);glBindTexture(GL_TEXTURE_2D, img3);glOrtho(0.0,1.0,0.0,1.0,0.0,1.0);glUseProgram(programObj5);glPopAttrib();glViewport(0, 0, windowWidth, windowHeight);glBegin(GL_QUADS);glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0.0f);glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 0.0f);glVertex3f(0.0, 0.0,0.368);glMultiTexCoord2f(GL_TEXTURE0, 1.0f, 0.0f);glMultiTexCoord2f(GL_TEXTURE1, 1.0f, 0.0f);glVertex3f(1.0, 0.0,0.368);glMultiTexCoord2f(GL_TEXTURE0, 1.0f, 1.0f);glMultiTexCoord2f(GL_TEXTURE1, 1.0f, 1.0f);glVertex3f(1.0, 1.0,0.368);glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 1.0f);glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 1.0f);glVertex3f(0.0, 1.0,0.368);glEnd();}void blurTestPass(){glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);glDrawBuffer(GL_BACK);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  glOrtho(0.0,1.0,0.0,1.0,0.0,1.0);glBindTexture(GL_TEXTURE_2D, img0);glUseProgram(programObj6);drawQuad();}void display(){glClearColor(0.0,0.0,0.0,0.0);glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glClearDepth(1);glLoadIdentity();firstPass();if(focusCheck){secondPass();thirdPass();fourthPass();fifthPass();}else{blurTestPass();}glutSwapBuffers(); //Swap between the two buffers} [Edited by - Zaftwave on May 23, 2010 2:48:31 AM];  No one that knows what the problem is or perhaps where the problem might be?   