The shader must switch between multiple textures depending on the Alpha value of the original texture for each pixel. Now this would word fine if I didn't have to worry about SamplerStates. I have created my array of textures and can select a texture based on the Alpha value of the pixel. But how do I create an Array of SamplerStates and link it to my array of textures? I attempted to treat the SamplerState as a function by adding the (int i) but that didn't work. Also I can't use Texture.Sample since this is shader model 2.0.

//shader model 2.0 (DX9)    
texture subTextures[255];
SamplerState MeshTextureSampler(int i)
    Texture = (subTextures[i]);

float4 SampleCompoundTexture(float2 texCoord, float4 diffuse)
    float4 SelectedColor = SAMPLE_TEXTURE(Texture, texCoord);
    int i = SelectedColor.a;
    texture SelectedTx = subTextures[i];
    return tex2D(MeshTextureSampler(i), texCoord) * diffuse;

1 Answer 1


I'm a newb to DirectX myself, but from what I've read, in HLSL, this:

Texture textures[3];

Will actually be compiled like this:

Texture textures0;
Texture textures1;
Texture textures2;

So indexing into the array won't work.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .