Texture Arrays

Good Morning.

I’m using the current stable Panda3d 1.9.1 and struggling to load and set texture arrays to a given model/node;
Would anyone happen to have some boilerplate code to load and set them up correctly?

Thank you.

Assuming your files are named 1.png, 2.png, 3.png …, you can load the texture with:

from panda3d.core import TexturePool
tex_array = TexturePool.load2dTextureArray("#.png")

(There are further options like also including mipmaps and so on, also see [url]Texture Arrays])

If you want to use the texture with the shader generator, you will have to use 3-component texture coordinates instead of 2-component - basically the third component is the index in the texture array. For that you will have to create a custom GeomVertexFormat I believe.

If you want to use the texture in a custom shader, you would do:

uniform sampler2DArray my_tex;
...
vec4 color = texture(my_tex, vec3(uv_coordinate.xy, layer_index)));
1 Like

Thanks for the great support.