简体   繁体   中英

Assigning texture to an object using multiple textures

在此处输入图片说明

I'm making a object loader, and all the texture parts are in different texture files. What is the best solution of having it mapped on the model? Do I need to treat every part that has it's own texture as 1 model, so that the final body has many separate drawing calls with one texture each?

With the advent of the programmable rendering pipeline (ie: shaders ) you can now apply and combine multiple textures to meshes without the need for multiple draw calls.

Modern GPUs have several texture units ( glActiveTexture ) and shaders can read from may units at a time. The model on the right that you showed in the picture, for example, probably uses a variation of the Phong lighting model with a diffuse texture, a normal map texture and probably a specular map texture for the highlights. All these three textures are certainly applied each to a texture unit and the whole model is rendered in one draw call. The fragment shader then reads this textures and combines them to produce the final image.

Your question is not very specific, so this is all I can say for now. If you have more specific questions, please fell free to ask.

Making separate draw calls for each part that needs a different texture (or set of textures, if you need stuff like normal maps, as @glampert suggested) is one possibility. You seem to have fairly complex geometry, so that might not be horribly inefficient because your draw calls would still be reasonably large. You could still have all your vertices/indices for the model in a single buffer, so at least you wouldn't have to switch vertex buffers for each call. If you want realistic materials, you might need a different shader for each material anyway, which means that you have to split the model into separate draw calls.

Not sure if people really do this, but one approach I would be tempted to try would be to use a texture array, where the texture for each material is stored as one layer. Make the material index a vertex attribute, pass it from the vertex shader through to the fragment shader, and then use is as the layer when sampling the texture array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM