Reputation: 2812
If I am passing two textures into an HLSL shader, will I also need two SamplerState's? I am a little confused as to how the SamplerStates actually work. I never instantiate them or anything, I just call
Tex.Sample(sampler, pos);
I am compiling my shader for profile 9.3 (WP8 if that makes any difference)
Example Shader:
Texture2D InputTexture;
SamplerState Sampler;
float4 PSMain(float2 pos: TEXCOORD, float4 SVP : SV_POSITION) : SV_TARGET {
float4 image = InputTexture.Sample(Sampler, pos);
return image;
}
technique {
pass {
Profile = 9.3;
PixelShader = PSMain;
}
}
Upvotes: 2
Views: 3650
Reputation: 16623
What are you trying to do is called multitexturing.
A SamplerState object contains the sampling and filtering options and the sampler allows you to read the data from the texture with that options.
There are many sampler states you can set:
Filter
AddressU
AddressV
AddressW
MipLODBias
MaxAnisotropy
ComparisonFunc
BorderColor
MinLOD
MaxLOD
In Direct3D 10 the syntax is the following:
//example
SamplerState mySampler{
Filter = MIN_MAG_MIP_LINEAR; //sets min/mag/mip filter to linear
AddressU = Wrap;
AddressV = Wrap;
};
Here you can find the default values and here some meanings of the states.
After all I can say that the number of SamplerState
s you need depends on what kind of effect you want to achieve. But really simply your code could be like:
Texture2D InputTextures[2];
SamplerState Sampler;
float4 PSMain(float2 pos: TEXCOORD, float4 SVP : SV_POSITION) : SV_TARGET {
float4 color = InputTexture[0].Sample(Sampler, pos) * InputTexture[1].Sample(Sampler, pos);
return color;
}
Infact as you can see you just need to multiply the two color of the textures to get a multitextured object.
Upvotes: 3