I'm create a simple shader for drawing progress bar in XNA.
Idea is simple: there are two textures and value and if X texture coord less then value use pixel from foreground texture, else use background texture.
/* Variables */
texture BackgroundTexture;
sampler2D BackgroundSampler = sampler_state
{
Texture = (BackgroundTexture);
MagFilter = Point;
MinFilter = Point;
AddressU = Clamp;
AddressV = Clamp;
};
texture ForegroundTexture;
sampler2D ForegroundSampler = sampler_state
{
Texture = (ForegroundTexture);
MagFilter = Point;
MinFilter = Point;
AddressU = Clamp;
AddressV = Clamp;
};
float Value;
/* Pixel shaders */
float4 PixelShader1(float4 pTexCoord : texcoord0) : color0
{
float4 texColor =
pTexCoord.x <= Value ?
tex2D(ForegroundSampler, pTexCoord) :
tex2D(BackgroundSampler, pTexCoord);
return texColor;
}
/* Techniques */
technique Technique1
{
pass Pass1
{
PixelShader = compile ps_2_0 PixelShader1();
}
}
But correct only ForegroundTexture. BackgroundSampler is simply white. I found that correct shown only texture that was declared in shader in last.
Please help me understand why so?