Game Development Reference
In-Depth Information
Cubemap coordinates
We do not provide the cubemap coordinates to the shader. In fact, the cubemap
colors are sampled using the vertex normals using the following function:
textureCube(uCubeSampler, transformedNormal);
The textureCube function samples the color from the location where the normal
from the object surface intersects the cubemap. The uCubeSampler uniform
references the cubemap texture.
Multi-texturing
So far, we have been rendering using a single texture. However, there are times
where we may want to have multiple textures that contribute to a fragment to create
more complex effects. For such cases, we use WebGL's ability to access multiple
textures in a single draw call. This is known as multi-texturing. In this chapter, we
earlier read that WebGL can refer 32 active textures and each texture is represented
by TEXTURE0 through TEXTURE32 . We can assign these textures to sampler uniforms
in our fragment shader and use them simultaneously to color a fragment.
Loading cubemaps
In our code, we will show how to use cubemaps and discuss multi-texturing.
So far, we have used a single texture in our code examples. However, in this code,
we will load two textures. The first will be our 2D texture and the second will be
our cubemap applied to the same object.
The following figure shows the different images used for the cubemaps and the
corresponding object on which they are applied:
 
Search WWH ::




Custom Search