Skip to main content
GameDev.net gamedev.net
🔒 Locked

3D textures / texture array questions

Started by spek Aug 24, 2008 at 9:15 AM 3 replies 4.5k views
Original Post
spek
spek
Hi, I need to blend between quite alot of textures, so instead of passing each and every texture to my shader, I would like to send them into 1 package. Either a 3D texture, or a texture array. So, the logical first question would be, what's the best choice? I need to tileable textures for terrain kinda-like stuff:

color1 = tex3D/Array( tileMap, vec3( u,v, tileIndex1) ) * weight1;
color2 = tex3D/Array( tileMap, vec3( u,v, tileIndex2) ) * weight2;
...
Second question, can you construct these textures from other 2D textures that are already loaded into the video memory? Otherwise I would need to read x image files, combine them into 1 big array, and then upload the whole thing. The first option seems to be faster/more friendly, in case I have varying settings. Greetings, Rick
MARS_999
MARS_999
FYI the difference between 3D textures and the new texture array are as follow off the top of my head.

3D textures
Supported on older hardware.
Filtering will take place between layers.

Texture arrays
Only Geforce 8 series and newer aka DX10 hardware
Filtering isn't done between layers.
You can use them with FBOs

Your 3rd option is use a texture atlas. This gives you all your textures in 1 2d Texture, and can be used on all hardware that has a fragment shader. Only issue is filtering can be a headache, unless you have borders around you textures or limit it to point sampling.

Unless you use .dds files, which I think have texture array support and 3d texture support, you will have to load each 2d texture into memory

e.g.
unsigned char[w][h][d][channels]; array

and then upload that to GL. I myself use PBO to make it a tad bit faster, but since I am targeting DX10 hardware its ok to assume PBO will be there.

Be warned I have 16 textures in a texture array and it still kills performance on my terrain, as you still have to access the texture sampler 16x...
spek
spek
Now I've implemented 3D textures, just by loading each slice apart. Well, it works. It would be nice if there was options to use already loaded 2D textures. But I guess I'll have to setup a FBO for that, and render the 2D textures on quads into the 3D/Array Texture. That's not worth the effort for me now.

Filtering between the layers is indeed not needed here. I'm not targeting for old hardware, because *IF* my stuff will ever release, we live in the year 2059. Do array's have any other benefit over 3D textures (performance)?

BTW, 3D textures can also be used for FBO's as well. I use them alot for probes :)

Thanks for the tips!
Rick
MARS_999
MARS_999
Well if you want to just use glGetTexImage and grab the imageData, and upload that data back into a 3D texture... I don't know why you would do this? Is this data created after the app is running? Otherwise I can't see why you just don't load the textures into the 3D texture vs. a 2D texture.
spek
spek
So glGetTexImage was the command I was looking for... thanks! Textures used in a set (3D texture in this case) are often also loaded as a normal 2D texture for other purposes in my case. So I thought maybe it was faster to load them from an existing source. But I'm not sure if its really faster than just loading it from the hard-drive.

Rick

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.