Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use multiple texture units?

Tags:

opengl

When should I use multiple texture units via the glActiveTexture command (TEXTURE 0 and TEXTURE 1)? From the examples I've seen multiple textures can be used on the texture unit TEXTURE0.

like image 855
Xavier Avatar asked Aug 06 '11 22:08

Xavier


2 Answers

There is a difference between using multiple textures (draw object A with texture X, draw object B with texture Y) and multitexturing. Multitexturing means drawing object A with textures X and Y. The resulting color is based on various "texture environment" state (or shaders if you're using them); this state tells OpenGL how to combine the values from the two textures into one color.

If you're using fixed-function, then each texture has its own set of texture coordinates. The final color value computed is based on the colors fetched by those texture coordinates on their corresponding textures. These texture colors are fed through the texture environment, which is a sequence of operations applied to those colors that compute a final color.

If you're using shaders, then you can do pretty much whatever you want. Make up texture coordinates on the fly, use arbitrary operations to combine texture "colors", etc.

Texture units are for doing multitexturing.

like image 119
Nicol Bolas Avatar answered Oct 05 '22 06:10

Nicol Bolas


You need multi-texturing for example when you use: normal mapping, parallax mapping, terrain texturing.

In detail for normal mapping you need the diffuse texture unit for the model, but also the normal map and you need to sample both textures, however you can't activate the same channel for both textures, you need to activate TEXTURE0 and TEXTURE1 and bind them to the respective id textures.

After you activate them and drew the model using those textures in the color buffer you can use them for other textures.

Think of them as flags to activate different textures channels on the GPU.

like image 36
Cristina Avatar answered Oct 05 '22 06:10

Cristina