Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: shaders with samplerCube -> all is black

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2009
    Posts
    14

    shaders with samplerCube -> all is black

    hi all! I have a problem, all shaders that use a samplerCube map look totally black, I donīt know if it is a problem of my opengl version (2.1.2), my drivers, the compiler (NVIDIA 1.2 Cg compiler) or what...

    thanks!

  2. #2
    Member Regular Contributor DmitryM's Avatar
    Join Date
    Mar 2009
    Location
    Toronto
    Posts
    436

    Re: shaders with samplerCube -> all is black

    The problem is in your mind: what do you expect to hear giving so little information?

    As you seem to have more than one shader, did any of them work before you changed the platform?

    Anyway, post your shader CG code plus textures & shader initialization code.

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2009
    Posts
    14

    Re: shaders with samplerCube -> all is black

    none of them works, for example, the simplest shader:

    [vertex]
    varying vec3 vnorm;

    void main ()
    {
    vnorm = gl_NormalMatrix * gl_Normal;
    gl_Position = ftransform();
    }


    [fragment]
    varying vec3 vnorm;
    uniform samplerCube texcube;

    void main ()
    {
    vec3 norm = normalize(vnorm);
    vec4 frag = textureCube(texcube, norm);

    gl_FragColor = frag;
    }

    ....

    glUniform1i(getUniLoc(progBolas, "texcube"), bola[0].material.idMapaCubico);


    getUniformLocation inside getUniLock returns 0, so i thinks it is ok.

    also i initialize cube map as follows

    glEnable(GL_TEXTURE_CUBE_MAP);
    glGenTextures(1, &idMapaCubico);

    glBindTexture(GL_TEXTURE_CUBE_MAP,idMapaCubico);


    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    //glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_MODULATE);


    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT, 0, GL_RGB8,
    tx.getWidth(), tx.getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, tx.getData(1));

    glBindTexture(GL_TEXTURE_CUBE_MAP,idMapaCubico);
    glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT, 0, GL_RGB8,
    tx.getWidth(), tx.getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, tx.getData(2));

    glBindTexture(GL_TEXTURE_CUBE_MAP,idMapaCubico);
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT, 0, GL_RGB8,
    tx.getWidth(), tx.getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, tx.getData(3));

    glBindTexture(GL_TEXTURE_CUBE_MAP,idMapaCubico);
    glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT, 0, GL_RGB8,
    tx.getWidth(), tx.getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, tx.getData(4));

    glBindTexture(GL_TEXTURE_CUBE_MAP,idMapaCubico);
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT, 0, GL_RGB8,
    tx.getWidth(), tx.getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, tx.getData(5));

    glBindTexture(GL_TEXTURE_CUBE_MAP,idMapaCubico);
    glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT, 0, GL_RGB8,
    tx.getWidth(), tx.getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, tx.getData(6));
    glDisable(GL_TEXTURE_CUBE_MAP);

  4. #4
    Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    258

    Re: shaders with samplerCube -> all is black

    glEnable(GL_TEXTURE_CUBE_MAP);
    this is relevant to fixed function only, you dont need it

    glUniform1i(getUniLoc(progBolas, "texcube"), bola[0].material.idMapaCubico);
    you are supposed to initialize sampler with the number of the texture unit your texture is bound to, not name of the texture itself

  5. #5
    Member Regular Contributor DmitryM's Avatar
    Join Date
    Mar 2009
    Location
    Toronto
    Posts
    436

    Re: shaders with samplerCube -> all is black

    1) What is in the logs for shaders compilation & linking?
    2) Show your shader activation code (where you bind this texture, activate the shader & drawing something)
    3) Try just writing vnorm to the output color in the fragment shader. Do you see anything in this case?

    minor: you don't need to glEnable/Disable (GL_TEXTURE_CUBE_MAP) when using shaders

  6. #6
    Junior Member Newbie
    Join Date
    Sep 2009
    Posts
    14

    Re: shaders with samplerCube -> all is black

    Quote Originally Posted by kyle_
    glEnable(GL_TEXTURE_CUBE_MAP);
    this is relevant to fixed function only, you dont need it

    glUniform1i(getUniLoc(progBolas, "texcube"), bola[0].material.idMapaCubico);
    you are supposed to initialize sampler with the number of the texture unit your texture is bound to, not name of the texture itself
    idMapaCubico is the value returned by glGenTextures() so it is ok

  7. #7
    Junior Member Newbie
    Join Date
    Sep 2009
    Posts
    14

    Re: shaders with samplerCube -> all is black

    Quote Originally Posted by DmitryM
    1) What is in the logs for shaders compilation & linking?
    2) Show your shader activation code (where you bind this texture, activate the shader & drawing something)
    3) Try just writing vnorm to the output color in the fragment shader. Do you see anything in this case?

    minor: you don't need to glEnable/Disable (GL_TEXTURE_CUBE_MAP) when using shaders
    1. Logs are ok, no error or warning is displayed

    2.I draw simply calling a list:

    glUseProgram(progBolas);
    glCallList(lista);
    glUseProgram(0);

    do i need glBindTexture(GL_TEXTURE_CUBE_MAP_EXT, material.idMapaCubico) before calling the list?? i thought not, i have tested it and the result is the same...


    3.
    varying vec3 vnorm;
    uniform samplerCube texcube;

    void main ()
    {
    vec3 norm = normalize(vnorm);
    vec4 frag = textureCube(texcube, norm);

    gl_FragColor = vec4(vnorm, 1.0);
    }

    the result is this one:




    the cube map used is the first here:
    http://www.codemonsters.de/home/cont...?show=cubemaps

  8. #8
    Member Regular Contributor DmitryM's Avatar
    Join Date
    Mar 2009
    Location
    Toronto
    Posts
    436

    Re: shaders with samplerCube -> all is black

    2. Your cubemap texture has to be bound to the GL_TEXTURE_CUBE_MAP_EXT binding point when draw command is executed. So, in general case, you should bind it every time you draw something using it. Alternatively, you can include this binding into the display list you use for drawing.

    minor: AFAIK, you don't need to bind it each time before a side is filled with data.

    Try the following:
    -disable filtering (set nearest in both)
    -set wrapping to CLAMP

    Also, we somehow have to be sure you load correct data into the cubemap. Check your image loading routine at least...

  9. #9
    Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    258

    Re: shaders with samplerCube -> all is black

    glUniform1i(getUniLoc(progBolas, "texcube"), bola[0].material.idMapaCubico);
    idMapaCubico is the value returned by glGenTextures() so it is ok
    This is exactly what is incorrect.
    You should do following:

    Code :
    glActiveTexture(GL_TEXTURE3)
    glBindTexture(GL_TEXTURE_CUBE_MAP, idMapaCubico);
    glUniform1i(getUniLoc(progBolas, "texcube"), 3)

    third tex unit picked arbitrarily in the example

  10. #10
    Member Regular Contributor DmitryM's Avatar
    Join Date
    Mar 2009
    Location
    Toronto
    Posts
    436

    Re: shaders with samplerCube -> all is black

    You are correct, kyle.
    I wonder how I missed it in discussion...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •