Graphics Reference
In-Depth Information
The vertex shader takes in a position and a normal as vertex inputs.
A normal is stored at each vertex of the sphere that will be used as a
texture coordinate. The normal is passed to the fragment shader. The
fragment shader then uses the built-in function texture to fetch from the
cubemap using the normal as a texture coordinate. The texture built-in
function for cubemaps takes the form shown here:
vec4 texture (samplerCube sampler , vec3 coord [,
float bias ])
sampler the sampler is bound to a texture unit specifying the texture
from which to fetch.
coord a 3D texture coordinate used to fetch from the cubemap.
bias
an optional parameter that provides a mipmap bias used for
the texture fetch. This allows the shader to explicitly bias the
computed LOD value used for mipmap selection.
The function for fetching a cubemap is very similar to a 2D texture. The
only difference is that the texture coordinate has three components
instead of two and the sampler type must be samplerCube . The same
method is used to bind the cubemap texture and load the sampler as is
used for the Simple_Texture2D example.
Loading 3D Textures and 2D Texture Arrays
As discussed earlier in the chapter, in addition to 2D textures and
cubemaps, OpenGL ES 3.0 includes 3D textures and 2D texture arrays.
The function to load 3D textures and 2D texture arrays is glTexImage3D ,
which is very similar to glTexImage2D .
void glTexImage3D (GLenum target , GLint level ,
GLenum internalFormat ,
GLsizei width , GLsizei height ,
GLsizei depth , GLint border ,
GLenum format , GLenum type ,
const void* pixels )
specifies the texture target; should be
GL_TEXTURE_3D or GL_TEXTURE_2D_ARRAY .
target
 
 
 
Search WWH ::




Custom Search