Sign in to follow this  
VanillaSnake21

[HLSL] How to use arrays of textures in hlsl?

Recommended Posts

I'm trying to load bunch of similar textures on to the gpu, and then access them from the cpu.
SSo in my .fx file I have
[code]
Texture2D letters[26];
[/code]
But when it comes time to map that to the ShaderResourceVariable, which is declared like this:
[code]
ID3D10EffectShaderResourceVariable* pShaderLetters[26];
[/code]

I get an error saying something like can't convert * to an array (even though both are arrays).

Any suggestions?

Share this post


Link to post
Share on other sites
[quote name='Asesh' timestamp='1330222705' post='4916639']
use Texture2DArray instead
[/quote]
Now it's saying can't conver implicitly from float 2 to float3? Can you give me an example of how this is done. The line where I get the error is this (in .fx file):
[code]
if(letterCode == 1) color = letterTextures[0].Sample(linearSampler, input.t); return color;
[/code]

Share this post


Link to post
Share on other sites
With a Texture2DArray, you index into the texture array with the z coordinate when calling .Sample - you don't [] index.

e.g.

Texture2DArray myTextures : register(t0);

then later..

float4 color = myTextures.Sample( sampler, float3( u, v, textureIndex ) );

A Texture2DArray is created differently though. You have to give it an array size in the texture desc, and when creating the SRV set the TEXTURE2DARRAY view dimension and Texture2DArray.* variables.

Share this post


Link to post
Share on other sites
[quote name='VanillaSnake21' timestamp='1330212265' post='4916604']
I'm trying to load bunch of similar textures on to the gpu, and then access them from the cpu.
SSo in my .fx file I have
Texture2D letters[26];
But when it comes time to map that to the ShaderResourceVariable, which is declared like this:
ID3D10EffectShaderResourceVariable* pShaderLetters[26];

I get an error saying something like can't convert * to an array (even though both are arrays).

Any suggestions?
[/quote]

Paste some more code please, for example the place where you try to bind the texture.

Cheers!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this