Assigning texture to an object using multiple textures

北城以北 提交于 2019-12-11 03:24:35

问题


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?


回答1:


With the advent of the programmable rendering pipeline (i.e.: 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.




回答2:


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.



来源:https://stackoverflow.com/questions/23233005/assigning-texture-to-an-object-using-multiple-textures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!