Texture Arrays

Hello,

In these days we have been adding 2D texture arrays to the Texture Class and we have committed this new feature today into the CVS.

[size=150]1. Overview[/size]
I found the Overview Paragraph of the OpenGL specification for EXT_texture_arrays pretty clear, so it follows an edited “copy and paste” of it:

more details at: developer.download.nvidia.com/op … _array.txt

[size=150]2. Usage[/size]
As stated in the specification texture arrays must be used in conjunction with a fragment shader. The gp4 Fragment Program (gp4fp) profile must be used to compile the fragment shader source code.
To create a 2D texture array:

mtex_0 = TexturePool.load_2d_texture_array("textures/south00#.jpg");
model.setShaderInput('mtex_0', mtex_0)

To access the texture array within the fragment program:

//Cg
//Cg profile gp4fp

void fshader(float3 l_texcoord:TEXCOORD0
             uniform sampler2DArray mtex_0:TEXUNIT0)
  o_color = tex2DARRAY(mtex_0,l_texcoord);
}


[size=150]3. Why texture arrays?[/size]

The motivation for the texture arrays technique is performance. 2D texture arrays can be used to draw a multi-textured model in one pass (reducing state changes), or can be used in conjunction with hardware instancing to render different instances of a model with a different texture.

Great work! Thanks for your contributions!

Do images inside a texture array have to be same size?

Yes.

Sounds usable. Did you measure how big the performance boost is in practice?

ps: it’s called array textures (call me smart-ass =D)

Thanks a lot! :smiley:

No I didn’t measure the performances boost. But I believe it should have a strong impact especially when drawing multi textured models or if used in conjunction with Hardware Based Instancing.

ps: it's called array textures (call me smart-ass =D)

I have seen calling it both ways: 2D texture array developer.download.nvidia.com/wh … errain.pdf or 2D array texture.

The PDF speaks about DirectX 10 and the initial spec file about OpenGL 2.0. What is actually the requirement for this new feature?

I hate to be pedantic, but issues 9 and 10 from the spec paper make it clear.

That’s just OpenGL. In DirectX and nVidia terminology, and in the broader CG world, both terms are used interchangeably.

David

Ok, thanks :slight_smile:

I wanted to show that they can be called in both ways. Texture arrays are available in panda3D only for OpenGL.

Some may call me slow here but is it possible to have a small zip file to see what’s this texture array is realy doing and how to use it ?

You can download this,

etc.cmu.edu/projects/pandase … 20Demo.rar

It comes in a .rar file and it showcases texture arrays(16 different textures) applied to the models that you see on screen. The demo is also amply commented and should be self sufficient.

Got this error when I tried it.

DirectStart: Starting the game.
Known pipe types:
  osxGraphicsPipe
(all display modules loaded.)
False
Traceback (most recent call last):
  File "Tut-AdvacedShaderInputs.py", line 170, in <module>
    w = World()
  File "Tut-AdvacedShaderInputs.py", line 38, in __init__
    assert base.win.getGsg().getSupportsCgProfile("gp4vp"),\
AttributeError: 'libpanda.GraphicsStateGuardian' object has no attribute 'getSupportsCgProfile'

And if I comment the lines which check my hardware, I got this:

DirectStart: Starting the game.
Known pipe types:
  osxGraphicsPipe
(all display modules loaded.)
False
:gobj(error): /Users/tallmystcarpet/Desktop/PandaSE Flocking-Instancing Demo/shaders/groundShader.cg: unrecognized parameter name (varying in float4 vIN.o_position)
:gobj(error): /Users/tallmystcarpet/Desktop/PandaSE Flocking-Instancing Demo/shaders/groundShader.cg: unrecognized parameter name (varying in float2 vIN.o_texcoord0)
:gobj(error): /Users/tallmystcarpet/Desktop/PandaSE Flocking-Instancing Demo/shaders/advancedInputs.cg: (37) : error C5108: unknown semantics "INSTANCEID" specified for "l_id"
:gobj(error): /Users/tallmystcarpet/Desktop/PandaSE Flocking-Instancing Demo/shaders/advancedInputs.cg: (70) : error C1115: unable to find compatible overloaded function "tex2DARRAY(sampler2DARRAY, float3)"
Traceback (most recent call last):
  File "Tut-AdvacedShaderInputs.py", line 170, in <module>
    w = World()
  File "Tut-AdvacedShaderInputs.py", line 94, in __init__
    self.ralph.setInstanceCount(NUMBER_OF_RALPHS)
AttributeError: 'Actor' object has no attribute 'setInstanceCount'

And this is the setInstanceCount rdb was talking about in the blog…
Is it an extra attrib that appear with Panda1.7 ? (I still using 1.6.2)

You need the latest CVS version of Panda3D to run it, apparently. getSupportsCgProfile is only available on the CVS head, setInstanceCount only in 1.7.0 and up.

it must have same size