How to use 3d texture in opengl and cg shaders?

*爱你&永不变心* 提交于 2020-01-24 01:32:04

问题


I've got a problem with 3d texture mapping. If I have several 2d textures, and I want to build a 3d texture with these 2d textures. What can I do to put all these data together? The function glTexImage3D ends with a parameter const GLvoid *texels which leads to the data of the texture. But now I have 32 2D textures and want to get a 3D texture. How to do that?

The second question is about image space filtering method. Is there anyone who knows what it is? I should use this method to determine texture coordinate.


回答1:


Do you really need 3D textures? maybe the better way is to have texture Arrays?

here is a good info: http://www.opengl.org/wiki/Array_Texture

it is a bit simpler than 3D textures to use I think. They are very useful for instance in cascaded shadow mapping where each cascade goes to different element in the array of textures.




回答2:


But now I have 32 2D textures and want to get a 3D texture. How to do that?

At some point in your program you upload the textures. From your question I presume you already did upload them using glTexImage2D. It's difficult, cumbersome and not very robust to transfer texture data between texture objects, so asking how to combine 2D textures into a 3D texture is a bit off.

But what you can do perfectly well is building your 3D texture from slices of 2D data uploaded one after another to the block of 3D votexels. Just replace every call to glTexImage2D with a call of glTexSubImage3D. Before uploading any data you can initialize the texture using a call to glTexImage3D and a NULL pointer as data parameter (you can also use glTexStorage3D if you're using OpenGL-4).



来源:https://stackoverflow.com/questions/10617810/how-to-use-3d-texture-in-opengl-and-cg-shaders

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