Results 1 to 5 of 5

Thread: Texture not changed in the fragment shader.

  1. #1
    Member Contributor
    Join Date
    Oct 2015
    Posts
    60

    Texture not changed in the fragment shader.

    Hi, I need to change the texture of my FS but when I set the texture parameter :
    Code :
    Texture tmpDepthBufferTexture = Texture(depthBuffer.getTexture());
                    Texture tmpStencilBufferTexture = Texture (stencilBuffer.getStencilTexture());
                    depthBuffer.clear(sf::Color::Transparent);
                    stencilBuffer.clear(sf::Color::Transparent);
                    frameBufferGenerator.setParameter("haveTexture", 1);
                    for (unsigned int i = 0; i < m_instances.size(); i++) {
                        currentStates.texture = &tmpStencilBufferTexture;
                        stencilBuffer.draw(m_instances[i].getAllVertices(),currentStates);
                        frameBufferGenerator.setParameter("depthBuffer", tmpDepthBufferTexture);
                        depthBuffer.draw(m_instances[i].getAllVertices(),currentStates);
                    }

    The texture is not changed so it's the cleared one which is referenced in my FS.
    Code :
    const std::string frameBufferGenFragShader =
                    "#version 130 \n"
                    "uniform sampler2D depthBuffer;"
                    "uniform sampler2D texture;"
                    "uniform vec3 resolution;"
                    "uniform float haveTexture;"
                    "in mat4 projMat;"
                    "void main () {"
                        "vec2 position = ( gl_FragCoord.xy / resolution.xy );"
                        "float max_z = texture2D(depthBuffer, position).z;"
                        "vec4 texel = texture2D(texture, gl_TexCoord[0].xy);"
                        "vec4 colors[2];"
                        "colors[1] = texel * gl_Color;"
                        "colors[0] = gl_Color;"
                        "bool b = (haveTexture > 0.9);"
                        "vec4 color = colors[int(b)];"
                        "float z = (gl_FragCoord.w != 1.f) ? (inverse(projMat) * vec4(0, 0, 0, gl_FragCoord.w)).w : gl_FragCoord.z;"
                        "colors[1] = color;"
                        "colors[0] = vec4(0, 0, 0, 0);"
                        "b = (z < max_z);"
                        "gl_FragColor = colors[int(b)];"
                    "}";

  2. #2
    Member Contributor
    Join Date
    Oct 2015
    Posts
    60
    OpenGL gets me an error : (parameter depthBuffer not found in shader)

    But HE IS IN THE SHADER.

  3. #3
    Member Contributor
    Join Date
    Oct 2015
    Posts
    60
    I give up with this, opengl is full of bugs.

  4. #4
    Senior Member Regular Contributor
    Join Date
    Oct 2014
    Posts
    112
    Quote Originally Posted by laurent7601 View Post
    OpenGL gets me an error : (parameter depthBuffer not found in shader)

    But HE IS IN THE SHADER.
    It might be in your code, that does not mean it is in the shader. If you define a variable A and write something like that:

    Code :
    gl_FragColor = vec4(1,1,1, 1 - A*0);

    A would never end up being in the shader, since it does not contribute to the final result (A*0 is always 0 regardless what it stored in A) and is therefore optimized out! So check you operation flow of all variables that depend on "depthBuffer" and if it's contribution to that variables will have any effect on the final result. The OpenGL error suggests that you have done something that removes its influence on the frag color. So check every instruction and maybe visualize the result values.

    I give up with this, opengl is full of bugs.
    You not understanding how OpenGL works is not a bug.

  5. #5
    Senior Member Regular Contributor
    Join Date
    Oct 2014
    Posts
    112
    Quote Originally Posted by laurent7601 View Post
    OpenGL gets me an error : (parameter depthBuffer not found in shader)

    But HE IS IN THE SHADER.
    It might be in your code, that does not mean it is in the shader. If you define a variable A and write something like that:

    Code :
    gl_FragColor = vec4(1,1,1, 1 - A*0);

    A would never end up being in the shader, since it does not contribute to the final result (A*0 is always 0 regardless what it stored in A) and is therefore optimized out! So check you operation flow of all variables that depend on "depthBuffer" and if it's contribution to that variables will have any effect on the final result. The OpenGL error suggests that you have done something that removes its influence on the frag color. So check every instruction and maybe visualize the result values.

    Code :
    I give up with this, opengl is full of bugs.

    Not understanding how OpenGL works is not a bug.

Similar Threads

  1. Replies: 7
    Last Post: 09-15-2015, 04:00 AM
  2. Replies: 1
    Last Post: 03-10-2014, 12:51 PM
  3. handling 2 texture in fragment shader
    By asafc in forum OpenGL: GLSL
    Replies: 2
    Last Post: 08-02-2009, 07:58 AM
  4. Texture Access from Fragment Shader
    By Nithos in forum OpenGL: GLSL
    Replies: 1
    Last Post: 02-28-2005, 01:41 PM
  5. texture matrix + texture rect + fragment shader
    By vmh5 in forum OpenGL: GLSL
    Replies: 2
    Last Post: 02-09-2004, 06:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean