7.5. Multitexturing

Concepts

Multitexture allows two or more textures to be applied to the same geometry. Similar effects could be obtained by drawing the geometry multiple times, each time with a different texture, but multitexture is much more efficient. Multitexture requires OpenGL 1.3 or the GL_ARB_multitexture extension. Without multitexture, there is only a single supported texture unit (SoTextureUnit SoTextureUnit SoTextureUnit ). Multitexture support allows every texture unit to maintain state that is independent of any other texture units. Each texture unit has its own texture image, texture coordinates (SoTextureCoordinate2 SoTextureCoordinate2 SoTextureCoordinate2 , SoTextureCoordinate3 SoTextureCoordinate3 SoTextureCoordinate3 , and SoTextureCoordinateFunction SoTextureCoordinateFunction SoTextureCoordinateFunction ), texture transform (SoTextureMatrix SoTextureMatrix SoTextureMatrix , SoTexture2Transform SoTexture2Transform SoTexture2Transform , and SoTexture3Transform SoTexture3Transform SoTexture3Transform ), texture enable state, and texture environment state. The texture coordinate generation is the same as with a single texture.

Multitexture and texture coordinates

Figure 7.19. Multitexture and texture coordinates



SoTextureUnit

An SoTextureUnit SoTextureUnit SoTextureUnit node specifies the current texture unit for subsequent 2D texture nodes and the way textures will be used.

The following table shows the SoTextureUnit SoTextureUnit SoTextureUnit fields:

mappingMethod (SoSFEnum)

Specifies the mapping method used for texture mapping. IMAGE_MAPPING is the classic mapping method. The other mapping method is BUMP_MAPPING (see the SoBumpMappingProperty class in FXViz).

unit (SoSFUInt32)

Specifies the texture unit identifier. Can range from 0 to the largest texture unit, which is getMaxTextureUnit() -1.

Example:

Two textures applied on the same shape

Figure 7.20. Two textures applied on the same shape



Texture Application

As in the usual texture case, there are three ways to map a texture in multitexture. You can:

  1. specify the texture coordinates yourself.

  2. allow Open Inventor to generate default texture coordinates.

  3. use a texture coordinate function (SoTextureCoordinateObject SoTextureCoordinateObject SoTextureCoordinateObject , SoTextureCoordinatePlane SoTextureCoordinatePlane SoTextureCoordinatePlane , etc.) to compute the texture coordinates.

As you can see in the following figure, each texture unit is rendered the same way a single texture unit would be. You can also program a combiner. But if you don’t, the specified texture mapping (SoTexture SoTexture SoTexture :: model) will be used for each texture. In fact, MODULATE is actually a combiner which combines the incoming fragment with the texture’s fetched color, but SoTextureCombiner SoTextureCombiner SoTextureCombiner offers many more possibilities to make more complex combinations.

SoTextureCombiner SoTextureCombiner SoTextureCombiner provides a number of operations that can be performed by each texture unit. If you are not working in multitexture, it will only use the texture unit 0. So it is more appropriate for multitexturing.

Texture combiner pipeline

Figure 7.21. Texture combiner pipeline



Example 7.5. Multitexture

Source code for a complete program can be found in:

$OIVHOME/src/Inventor/examples/Features/MultiTexturing/MultiTexture.cxx.

Multitexturing