Reputation: 642
float4x4 WVP;
texture cubeTexture;
sampler TextureSampler = sampler_state
{
texture = <cubeTexture>;
MipFilter = Point;
MagFilter = Point;
MinFilter = Point;
AddressU = Wrap;
AddressV = Wrap;
MaxAnisotropy = 16;
};
So if I'm not mistaken this tells the sampler state what texture I'm using. I'm using one effect file for many many sprites, therfor this allows me to use one texture (atlas). And I could combine all my texture atlases into one grand daddy atlas but I fear the complications.
Is there a way to tell the pixel shader to use a certain texture by its parameter? I'm new to HLSL and it's very confusing to me.
Upvotes: 2
Views: 1789
Reputation: 868
You can write a shader that contains several textures and samplers, but that is not very effective. A texture-atlas is much more preferrable, as it is easier to avoid branching.
I would suggest, for using 4 different textures, having an extra Color on each vert where each part of the color (r,g,b,a) can be used to blend the textures. You would then set the value of this extra color in C#, and use it in the shader.
This is not optimal, as it does 4 * the number of texture samplings, but it might do the trick, depending on situation.
var c1 = Tex2D(texture1, texcoords) * extracolor.r;
var c2 = Tex2D(texture2, texcoords) * extracolor.g;
var c3 = Tex2D(texture3, texcoords) * extracolor.b;
var c4 = Tex2D(texture4, texcoords) * extracolor.a;
output.color = c1 + c2 + c3 + c4;
Upvotes: 0
Reputation: 2851
If you give your shader a semantic to reference a register, like so
// HLSL
sampler TextureSampler : register(s1);
Then you can assign the texture in code using the GraphicsDevice.Textures
property in your game code
// C#
Texture2D texture2D = Content.Load<Texture2D>("contentfile");
graphicsDevice.Textures[1] = texture2D;
I used register 1 rather than 0 because the texture argument in Spritebatch.Draw()
uses register 0. If you aren't spritebatching, feel free to use register 0;
Upvotes: 5