Is there possible to use dynamic index in shader model 5.0?

Started by
2 comments, last by MJP 10 years, 5 months ago

I have an array of textures in the shader such as Texture2D pTextures[30], and I want to use a dynamic index instead of a specified index. Is there possible to do such thing? and how to do it?.

For example:

Use pTextures[ID] with ID is computed at runtime, instead of pTextures[x] with x is a specified value.

Advertisement

If you have a Texture2DArray in your shader, you can use the third component of the texture coordinate vector (parameter to Sample) to specify the array index. Even though the texture coordinate parameter of the Sample method is a vector of floats, the array index is effectively treated as an integer.

An array of texture references (as in Texture2D[ ]) is not equivalent to a Texture2DArray from the API or hardware point of view. The former is merely a list of unconnected textures, while the latter is a single resource which has multiple textures as subresources.

Niko Suni

However, a Texture2DArray does not allow multiple textures with different resolutions.

You can't dynamically index into different texture resources. The array syntax is just a convenience, the compiler has to generate hard-coded lookups for each fetch. If you want full dynamic access you either need to use texture arrays as Nik02 suggests, use a texture atlas, or use some combination of the two.

This topic is closed to new replies.

Advertisement