Cubemap Texture: Difference between revisions
Cubemaps contain images, not textures. |
→Cubemap array textures: Clearing up how to upload to cubemap arrays. |
||
Line 59: | Line 59: | ||
[[Array Texture|Array textures]] can also come in cubemap flavors, in addition to 1D and 2D. They use the texture type {{enum|GL_TEXTURE_CUBE_MAP_ARRAY}}. | [[Array Texture|Array textures]] can also come in cubemap flavors, in addition to 1D and 2D. They use the texture type {{enum|GL_TEXTURE_CUBE_MAP_ARRAY}}. | ||
Layers also have to be dealt with in an unusual way. Cubemap array textures have, for each mipmap, some number of cubemaps. That number of cubemaps is the number of layers. But since each cubemap is composed of 6 2D faces, array cubemaps also have a number of ''layer-faces'', which is 6 times the number of layers. Some interfaces count by layers, and others count by layer-faces. | |||
The order of the faces within a layer is the standard order: | |||
<div style="font-size: 60%;">{{cubemap layer face ordering}}</div> | |||
Every OpenGL API call that operates on cubemap array textures takes ''layer-faces'', not array layers. For example, when you allocate storage for the texture, you would use {{apifunc|glTexStorage3D}} or {{apifunc|glTexImage3D}} or similar. However, the {{param|depth}} parameter will be the number of layer-faces, not layers. So it must be divisible by 6. | |||
Similarly, when uploading texel data to the cubemap array, the parameters that represent the Z component are layer-faces. So if you want to upload to the positive Z axis of the second layer in the array, you would use index 10 (layer 1 * 6 faces per layer + face index 4). | |||
Cubemap arrays can have mipmaps. They are uploaded in the same way as for other kinds of array textures. Remember that the number of layer-faces does not change. | Cubemap arrays can have mipmaps. They are uploaded in the same way as for other kinds of array textures. Remember that the number of layer-faces does not change for mipmaps. | ||
=== Samplers === | === Samplers === | ||
The [[GLSL Sampler|sampler]] type for cubemap arrays is {{code|''g''samplerCubeArray}}. {{code|''g''samplerCubeArrayShadow}} can be used for comparison lookups. The texture coordinates are 4D values; the first three values are the vector direction, and the fourth value is the layer to use. Note that this is the ''layer'' to use, not the layer-face. | The [[GLSL Sampler|sampler]] type for cubemap arrays is {{code|''g''samplerCubeArray}}. {{code|''g''samplerCubeArrayShadow}} can be used for comparison lookups. The texture coordinates are 4D values; the first three values are the vector direction, and the fourth value is the layer to use. Note that this is the ''actual layer'' to use, not the layer-face. | ||
For comparison modes, the texture functions take an additional parameter for the comparison value. The comparison parameter always comes immediately after the texture coordinate. | For comparison modes, the texture functions take an additional parameter for the comparison value. The comparison parameter always comes immediately after the texture coordinate. | ||
[[Category:Textures]] | [[Category:Textures]] |
Revision as of 20:57, 30 April 2015
Core in version | 4.6 | |
---|---|---|
Core since version | 1.3 | |
ARB extension | ARB_texture_cube_map |
A Cubemap Texture is a texture, where each mipmap level consists of six 2D images. The images are arranged in a cube-shape, hence the name. Cubemaps can have multiple mipmap levels.
Creation
Cubemaps are a texture type, using the type GL_TEXTURE_CUBE_MAP.
If OpenGL 4.3 or ARB_texture_storage is available, then immutable storage for a cubemap texture can be allocated with glTexStorage2D. The width and height must be identical, but need not be powers of two.
To allocate mutable storage for the 6 faces of a cubemap's mipmap chain, bind the texture to GL_TEXTURE_CUBE_MAP. Then call glTexImage2D 6 times, using the same size, mipmap level, and internalformat. The target parameter is not GL_TEXTURE_CUBE_MAP; instead, it specifies which of the 6 faces of the cubemap to specify. These faces are:
- GL_TEXTURE_CUBE_MAP_POSITIVE_X
- GL_TEXTURE_CUBE_MAP_NEGATIVE_X
- GL_TEXTURE_CUBE_MAP_POSITIVE_Y
- GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
- GL_TEXTURE_CUBE_MAP_POSITIVE_Z
- GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
Cubemaps may have mipmaps, but each face must have the same number of mipmaps. Cubemaps can use any of the filtering modes and other texture parameters.
Texture Access
The sampler type for cubemaps is gsamplerCube. gsamplerCubeShadow can also be used for shadow lookups. The fourth component of the texture coordinate for shadow lookups is the comparison value.
The texture coordinates for cubemaps are 3D vector directions. These are conceptually directions from within the cube defined by the cubemap, pointing in a particular direction. The vectors do not have to be normalized.
Filtering does not usually take place across cubemap face boundaries. So a visible seam can appear between cubemap face boundaries regardless of the texture filtering modes. Though a setting can permit filtering between faces.
Layered Rendering
Cubemaps can be bound to framebuffer objects for layered rendering. The 6 faces are given a specific order:
Layer number | Cubemap face |
---|---|
0 | GL_TEXTURE_CUBE_MAP_POSITIVE_X |
1 | GL_TEXTURE_CUBE_MAP_NEGATIVE_X |
2 | GL_TEXTURE_CUBE_MAP_POSITIVE_Y |
3 | GL_TEXTURE_CUBE_MAP_NEGATIVE_Y |
4 | GL_TEXTURE_CUBE_MAP_POSITIVE_Z |
5 | GL_TEXTURE_CUBE_MAP_NEGATIVE_Z |
Seamless cubemap
Core in version | 4.6 | |
---|---|---|
Core since version | 3.2 | |
Core ARB extension | ARB_seamless_cube_map |
Under the standard filtering rules for cubemaps, filtering does not work across faces of the cubemap. This results in a seam across the faces of a cubemap. This was a hardware limitation in the past, but modern hardware is capable of interpolating across a cube face boundary.
To globally enable this, use glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS).
Cubemap array textures
Core in version | 4.6 | |
---|---|---|
Core since version | 4.0 | |
ARB extension | ARB_texture_cube_map_array |
Array textures can also come in cubemap flavors, in addition to 1D and 2D. They use the texture type GL_TEXTURE_CUBE_MAP_ARRAY.
Layers also have to be dealt with in an unusual way. Cubemap array textures have, for each mipmap, some number of cubemaps. That number of cubemaps is the number of layers. But since each cubemap is composed of 6 2D faces, array cubemaps also have a number of layer-faces, which is 6 times the number of layers. Some interfaces count by layers, and others count by layer-faces.
The order of the faces within a layer is the standard order:
Layer number | Cubemap face |
---|---|
0 | GL_TEXTURE_CUBE_MAP_POSITIVE_X |
1 | GL_TEXTURE_CUBE_MAP_NEGATIVE_X |
2 | GL_TEXTURE_CUBE_MAP_POSITIVE_Y |
3 | GL_TEXTURE_CUBE_MAP_NEGATIVE_Y |
4 | GL_TEXTURE_CUBE_MAP_POSITIVE_Z |
5 | GL_TEXTURE_CUBE_MAP_NEGATIVE_Z |
Every OpenGL API call that operates on cubemap array textures takes layer-faces, not array layers. For example, when you allocate storage for the texture, you would use glTexStorage3D or glTexImage3D or similar. However, the depth parameter will be the number of layer-faces, not layers. So it must be divisible by 6.
Similarly, when uploading texel data to the cubemap array, the parameters that represent the Z component are layer-faces. So if you want to upload to the positive Z axis of the second layer in the array, you would use index 10 (layer 1 * 6 faces per layer + face index 4).
Cubemap arrays can have mipmaps. They are uploaded in the same way as for other kinds of array textures. Remember that the number of layer-faces does not change for mipmaps.
Samplers
The sampler type for cubemap arrays is gsamplerCubeArray. gsamplerCubeArrayShadow can be used for comparison lookups. The texture coordinates are 4D values; the first three values are the vector direction, and the fourth value is the layer to use. Note that this is the actual layer to use, not the layer-face.
For comparison modes, the texture functions take an additional parameter for the comparison value. The comparison parameter always comes immediately after the texture coordinate.