HLSL: An array of textures and sampler states

Posted by nate142 on Game Development See other posts from Game Development or by nate142
Published on 2014-08-20T14:49:42Z Indexed on 2014/08/20 16:37 UTC
Read the original article Hit count: 255

Filed under:
|
|
|

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;
}

© Game Development or respective owner

Related posts about textures

Related posts about shaders