using this code I can send one texture to the shader:
devcon->PSSetShaderResources(0, 1, &pTexture);
Of course i made the pTexture by: D3DX11CreateShaderResourceViewFromFile
Shader:
Texture2D Texture;
return color * Texture.Sample(ss, texcoord);
I’m currently only sending one texture to the shader, but I would like to send multiple textures, how is this possible?
Thank You.
By using Texture Arrays. When you fill out your
D3D11_TEXTURE2D_DESClook at theArraySizemember. This desc struct is the one that gets passed toID3D11Device::CreateTexture2D. Then in your shader you use a 3rd texcoord sampling index which indicates which 2D texture in the array you are referring to.Update: I just realised you might be talking about doing it over multiple calls (i.e. for different geo), in which case you update the shader’s texture resource view. If you are using the effects framework you can use ID3DX11EffectShaderResourceVariable::SetResource, or alternatively rebind a new texture using
PSSetShaderResources. However, if you are trying to blend between multiple textures, then you should use texture arrays.You may also want to look into 3D textures, which provide a natural way to interpolate between adjacent textures in the array (whereas 2D arrays are automatically clamped to the nearest integer) via the 3rd element in the texcoord. See the HLSL
sampleremarks.