Jump to content

Emulating Texture Arrays


ofer

Recommended Posts

Hi,

What is the best way to emulate texture arrays in a shader? I mean, I have a lot of textures, and I want to sample one of them based on an index to this array.

I though about several options:

1. Create a big 3D texture, and use the index as a third coordinate. But I might have sampling problems between layers.

2. Use a texture atlas, but then I will have mip-mapping issues.

3. Create the index as an integer point attribute, and then use this attribute inside and embedded expression in the texture's name parameter, eg.

$HIP/textures/V_`ch("./index")`.png

This is the easiest method, but I don't know how to use a point attribute inside a shader.

What I'm trying to do is to implement the rain streak rendering algo from siggraph 06, which uses a database of rain textures.

Thanks.

Link to comment
Share on other sites

Not really sure if I got your point.

You want to vary textures per frame on one surface? Then you can prepare expression in SOP to do it. You don't need any arrays. Similarly you can save attribute on face or point to vary texture on per point bases.

Shaders are time independent. Mantra ifd describes your scene in discreet point in time - once per frame. There is no sense to build in" texture sequencer" (your arrays) ability in shader since creating a proper set of *.ifd files with varying texture's strings brings to you similar results with no big effort. Unless I missed the point ;).

cheers,

sy.

EDIT:

3. Create the index as an integer point attribute, and then use this attribute inside and embedded expression in the texture's name parameter, eg.

$HIP/textures/V_`ch("./index")`.png

Sorry, I didn't notice that. This is usual way to do such things. All you need is to create in shader body a parameter of the same name as primitive attribute in geometry. Shader will use those instead of a values specified initially. Mantra overrides shader parameter with attributes found on geometry.

Edited by SYmek
Link to comment
Share on other sites

The easiest way I can think of is to (like Symek said) to create an integer attribute on your geometry and vary it with any method you want -random, etc (just limit it's value to the max number of textures you have there). Then in your shader create an instance variable of the same type and name, and Mantra will pick up it's values. The actual texture name you should create with a sprintf() format call and pass it to the texture() call.

Cheers

Link to comment
Share on other sites

OK, I added a parameter, and used its value in an expression inside the texture's name. But even though I created an attribute with the same name, the shader always takes the parameter's default value.

I referenced the parameter in the expression like that:

$HIP/textures/tex`ch("../param_name")`.png

the attribute and the parameter's name is param_name.

Are there any example files with this trick?

Thanks.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...