Course list http://www.c-jump.com/bcc/

Cube mapping and skyboxes


  1. Introduction
  2. Cube map examples
  3. Uploading cube map textures
  4. Texture parameters
  5. What is a skybox?
  6. Skybox shader code
  7. Further reading

1. Introduction


  • Cube-map textures are used for

    • making skyboxes

    • faking reflections on objects

  • A cube-map is comprised of 6 individual texture images

  • OpenGL treats them as one texture

  • It can be mipmapped:

    
        glGenerateMipmap( GL_TEXTURE_CUBE_MAP );
    
    
  • Cube-map requires 3 texture coordinates: S, T, and R

  • The R coordinates identifies a specific image among the 6 provided

  • cube map


2. Cube map examples



3. Uploading cube map textures



4. Texture parameters


  1. Use GL_TEXTURE_CUBE_MAP target texture

  2. Continue using magnification and minification filters

  3. Specify how to wrap each texture coordinate. For example,

    
    glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
    glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
    glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE );
    
    

     


5. What is a skybox?



6. Skybox shader code

  • Vertex shader

    
    #version 150
    
    in vec4 vPosition; // vertex pos
    uniform mat4 mP;   // perpsective
    uniform mat4 mV;   // view
    uniform mat4 mM;   // model
    
    out vec3 texCoords;
    
    void main( void )
    {
        texCoords = normalize( vPosition.xyz );
        gl_Position = mP*mV*mM*vPosition;
    }
    
    
  • Fragment shader

    
    #version 150
    
    out vec4 vFragColor;
    uniform samplerCube cubeMap;
    in vec3 texCoords;
    
    void main( void )
    {
        vFragColor = texture( cubeMap, texCoords );
    }
    
    

7. Further reading