Texture Arrays

Return to Panda Features in Development

Texture Arrays

Postby memecss » Thu Apr 29, 2010 3:41 pm

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.

1. Overview
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:

... A 2d array texture is a collection of two-dimensional images of identical size and format, arranged in layers ... The depth specify the number of layers in the image. An array texture is accessed as a single unit in a programmable shader, using a single coordinate vector. A single layer is selected, and that layer is then accessed as though it were a two-dimensional texture. The layer used is specified using the "t" or "r" texture coordinate for 2D array textures, respectively. The layer coordinate is provided as an unnormalized floating-point value in the range [0,<n>-1], where <n> is the number of layers in the array texture. Texture lookups do not filter between layers, though such filtering can be achieved using programmable shaders. When mipmapping is used, each level of an array texture has the same number of layers as the base level; the number of layers is not reduced as the image size decreases. This extension does not provide for the use of array textures with fixed-function fragment processing.
more details at: http://developer.download.nvidia.com/op ... _array.txt

2. Usage
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:
Code: Select all
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:
Code: Select all
//Cg
//Cg profile gp4fp

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


3. Why texture arrays?

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.
memecss
 
Posts: 148
Joined: Mon Jan 25, 2010 8:29 pm
Location: ETC, Carnegie Mellon University - Pittsburgh

Postby rdb » Fri Apr 30, 2010 1:35 am

Great work! Thanks for your contributions!
rdb
 
Posts: 8545
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Postby treeform » Fri Apr 30, 2010 1:27 pm

Do images inside a texture array have to be same size?
User avatar
treeform
 
Posts: 2106
Joined: Sat May 05, 2007 5:15 pm
Location: SF, CA

Postby drwr » Fri Apr 30, 2010 2:16 pm

Yes.
drwr
 
Posts: 11253
Joined: Fri Feb 13, 2004 12:42 pm
Location: Glendale, CA

Postby Nemesis#13 » Sun May 02, 2010 6:42 am

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






ps: it's called array textures (call me smart-ass =D)
User avatar
Nemesis#13
 
Posts: 1040
Joined: Mon Aug 04, 2008 8:09 pm
Location: Germany

Postby memecss » Mon May 03, 2010 1:26 pm

Great work! Thanks for your contributions!

Thanks a lot! :D
memecss
 
Posts: 148
Joined: Mon Jan 25, 2010 8:29 pm
Location: ETC, Carnegie Mellon University - Pittsburgh

Postby memecss » Mon May 03, 2010 1:32 pm

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

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.
Code: Select all
ps: it's called array textures (call me smart-ass =D)

I have seen calling it both ways: 2D texture array http://developer.download.nvidia.com/wh ... errain.pdf or 2D array texture.
memecss
 
Posts: 148
Joined: Mon Jan 25, 2010 8:29 pm
Location: ETC, Carnegie Mellon University - Pittsburgh

Postby Nemesis#13 » Mon May 03, 2010 5:53 pm

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


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

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

I hate to be pedantic, but issues 9 and 10 from the spec paper make it clear.
User avatar
Nemesis#13
 
Posts: 1040
Joined: Mon Aug 04, 2008 8:09 pm
Location: Germany

Postby drwr » Mon May 03, 2010 6:08 pm

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
drwr
 
Posts: 11253
Joined: Fri Feb 13, 2004 12:42 pm
Location: Glendale, CA

Postby Nemesis#13 » Mon May 03, 2010 6:31 pm

Ok, thanks :)
User avatar
Nemesis#13
 
Posts: 1040
Joined: Mon Aug 04, 2008 8:09 pm
Location: Germany

Postby memecss » Mon May 03, 2010 8:25 pm

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 wanted to show that they can be called in both ways. Texture arrays are available in panda3D only for OpenGL.
memecss
 
Posts: 148
Joined: Mon Jan 25, 2010 8:29 pm
Location: ETC, Carnegie Mellon University - Pittsburgh

Postby tallmystcarpet » Wed May 05, 2010 11:28 am

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 ?
User avatar
tallmystcarpet
 
Posts: 222
Joined: Sun Aug 30, 2009 8:53 pm

Postby sorcus » Sat May 08, 2010 9:04 pm

tallmystcarpet wrote: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,

http://www.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.
sorcus
 
Posts: 23
Joined: Thu Jun 04, 2009 1:31 pm
Location: ETC_Carnegie Mellon

Postby tallmystcarpet » Sun May 09, 2010 3:02 am

Got this error when I tried it.
Code: Select all
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:
Code: Select all
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)
User avatar
tallmystcarpet
 
Posts: 222
Joined: Sun Aug 30, 2009 8:53 pm

Postby rdb » Sun May 09, 2010 4:12 am

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.
rdb
 
Posts: 8545
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands


Return to Panda Features in Development

Who is online

Users browsing this forum: No registered users and 0 guests