Jump to content
  • Advertisement
Sign in to follow this  
pnt1614

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

This topic is 2077 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Edited by Nik02

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!