multitexturing is the ability of a 3D engine and more precisely of a 3D graphics
board to render several textures in a single pass (i.e in the same time). In OpenGL, this is possible
since the 1.3 revision and today almost all graphics controllers are able to perform multitexturing
with at least 2 textures.
Multitexturing is fundamental in modern 3D applications and we find it almost everywhere:
- light-mapping: use of a second texture that contains the shadow and lighting of the scene
- bump-mapping: use of a texture that contains the relief of a surface
- gpgpu: several textures that hold mathematic or physic data and that are used in complex
scientific simulations (fractals, fluid mechanics, advanced particle system, etc.)
- and of course, the countless effects based on the use of several textures (reflection, water surface,
alpha maps and other gloss-maps, hdr, soft-shadows, etc.)
At the GLSL level, multitexturing is very simple since it is enough to add as many texture
samplers as you need. The following shader, from the DEMO_Multi_Texturing.xml demo, shows
the use of 4 textures: the base map (or color map) and three lightmaps (red, green and blue maps):
[Vertex_Shader]
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
[Pixel_Shader]
uniform sampler2D colorMap;
uniform sampler2D redMap;
uniform sampler2D greenMap;
uniform sampler2D blueMap;
void main (void)
{
vec4 color_map = texture2D( colorMap, gl_TexCoord[0].st);
vec4 red_map = texture2D( redMap, gl_TexCoord[0].st);
vec4 green_map = texture2D( greenMap, gl_TexCoord[0].st);
vec4 blue_map = texture2D( blueMap, gl_TexCoord[0].st);
gl_FragColor = color_map +
red_map*0.7 +
green_map*0.41 +
blue_map*0.89;
}
The result is visible in the figure 4:
Fig. 4 - the DEMO_Multi_Texturing.xml demo
This example shows us one of the biggest advantages of the use of shaders for multitexturing
compared to the fixed functions: the ability to combine (or mix) as we wish the different
texture units.