1

I have implemented a simple gaussian blur and combined it with deferred shading, and it works. When I'm trying to add another object to the scene the object is also affected by the blur, which is not what I'm looking for. Is it possible to make the blur only affect the image of the target object or is it supposed to affect the whole scene?

For the blur I'm using 2 vertex shaders, one which is calculating the horizontal texture coordinates and another which computes the vertical texture coordinates. Both of the vertex shaders is using the same fragment shader which just computes the gaussian-weighted average of the color of the texels on these pre-computed texture coordinates.

Fragment shader for the blur object:

vec3 color;
    color += texture(gColorSpec, v_blurTexCoords[ 0]).rgb *0.0044299121055113265;
    color += texture(gColorSpec, v_blurTexCoords[ 1]).rgb*0.00895781211794;
    color += texture(gColorSpec, v_blurTexCoords[ 2]).rgb*0.0215963866053;
    color += texture(gColorSpec, v_blurTexCoords[ 3]).rgb*0.0443683338718;
    color += texture(gColorSpec, v_blurTexCoords[ 4]).rgb*0.0776744219933;
    color += texture(gColorSpec, v_blurTexCoords[ 5]).rgb*0.115876621105;
    color += texture(gColorSpec, v_blurTexCoords[ 6]).rgb*0.147308056121;
    color += texture(gColorSpec, v_texCoord         ).rgb*0.159576912161;
    color += texture(gColorSpec, v_blurTexCoords[ 7]).rgb*0.147308056121;
    color += texture(gColorSpec, v_blurTexCoords[ 8]).rgb*0.115876621105;
    color += texture(gColorSpec, v_blurTexCoords[ 9]).rgb*0.0776744219933;
    color += texture(gColorSpec, v_blurTexCoords[10]).rgb*0.0443683338718;
    color += texture(gColorSpec, v_blurTexCoords[11]).rgb*0.0215963866053;
    color += texture(gColorSpec, v_blurTexCoords[12]).rgb*0.00895781211794;
    color += texture(gColorSpec, v_blurTexCoords[13]).rgb*0.0044299121055113265;
    ...

In this case gColorSpec is the color sample (image) for the deferred shading.

In the lightning pass of deferred shading I'm activating the first and second vertex shader.

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        //object without blur
        ShadersWithoutBlur.Use();
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, gPosition);
        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, gNormal);
        glActiveTexture(GL_TEXTURE2);
        glBindTexture(GL_TEXTURE_2D, gColorSpec);
        // Also send light relevant uniforms
        glUniform3fv(glGetUniformLocation(ShadersWithoutBlur.shaderProgram, "lightPos"), 1, &lightPos[0]);
        glUniform3fv(glGetUniformLocation(ShadersWithoutBlur.shaderProgram, "lightColor"), 1, &lightColor[0]);
        glUniform3fv(glGetUniformLocation(ShadersWithoutBlur.shaderProgram, "viewPos"), 1, &camera.Position[0]);
        glUniform3fv(glGetUniformLocation(ShadersWithoutBlur.shaderProgram, "kd"), 1, &kd[0]);

        //Blur object
        FirstLightningPass.Use();
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, gPosition);
        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, gNormal);
        glActiveTexture(GL_TEXTURE2);
        glBindTexture(GL_TEXTURE_2D, gColorSpec);
        // Also send light relevant uniforms
        glUniform3fv(glGetUniformLocation(FirstLightningPass.shaderProgram, "lightPos"), 1, &lightPos[0]);
        glUniform3fv(glGetUniformLocation(FirstLightningPass.shaderProgram, "lightColor"), 1, &lightColor[0]);
        glUniform3fv(glGetUniformLocation(FirstLightningPass.shaderProgram, "viewPos"), 1, &camera.Position[0]);
        glUniform3fv(glGetUniformLocation(FirstLightningPass.shaderProgram, "kd"), 1, &kd[0]);

        SecondLightningPass.Use();
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, gPosition);
        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, gNormal);
        glActiveTexture(GL_TEXTURE2);
        glBindTexture(GL_TEXTURE_2D, gColorSpec);
        glUniform3fv(glGetUniformLocation(SecondLightningPass.shaderProgram, "lightPos"), 1, &lightPos[0]);
        glUniform3fv(glGetUniformLocation(SecondLightningPass.shaderProgram, "lightColor"), 1, &lightColor[0]);
        glUniform3fv(glGetUniformLocation(SecondLightningPass.shaderProgram, "viewPos"), 1, &camera.Position[0]);
        glUniform3fv(glGetUniformLocation(SecondLightningPass.shaderProgram, "kd"), 1, &kd[0]);
        // Finally render quad
        RenderQuad();   

Already tried: As I'm using deferred shading I have tried to make another frame buffer to render the geometry into, which is then only used for the blur image object. This doesn't work though as I seem to only need one framebuffer which adds up the whole scene geometry. I have also tried adding another attachment which would replace the gColorSpec, simply to check if it had a connection with the other gColorSpec for the other image object.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Riggs
  • 99
  • 2
  • 9
  • you should provide some code – fartagaintuxedo Jul 08 '16 at 13:42
  • @fartagaintuxedo Done – Riggs Jul 08 '16 at 14:41
  • in the code, what are the 2 objects of the scene? – fartagaintuxedo Jul 08 '16 at 14:50
  • Well, above is for one object but if I would add another object the code would look the same. I can add a line to clarify @fartagaintuxedo. – Riggs Jul 08 '16 at 15:02
  • I think you are applying blur to the whole scene, as there is no line in the code where you assign the blur fragment shader to any object or buffer. – fartagaintuxedo Jul 08 '16 at 15:15
  • Or maybe you could tell us in which specific line of the code do you assign the shader to objects 1 and 2 – fartagaintuxedo Jul 08 '16 at 15:21
  • I am? There is a gColorSpec in the fragment shader for the blur object which is then combined with the blur effect. The other object which has no blur effect doesn't have that line so it shouldn't be affected. But as I stated above there might be interference with the gColorSpec as I used it for both the object but the solutions I have tried so far doesn't work. – Riggs Jul 08 '16 at 15:22
  • We don't put [solved] in titles. If you found a solution yourself, post it as an answer. – Nicol Bolas Jul 09 '16 at 17:09

0 Answers0