Hello,
I’m very new to the whole shader business, but I’ve looked everywhere and could not find the problem with my code.
I’m trying to create a shader which overrides the transparency original texture with another texture.
My shader code is:
sampler s0;
texture IceTexture;
sampler ice_sampler = sampler_state
{
Texture = <IceTexture>;
};
float4 PixelShaderFunction(float4 position : SV_Position, float4 color : COLOR0, float2 coords : TEXCOORD0) : COLOR0
{
return tex2D(ice_sampler, coords);
}
technique Technique1
{
pass Pass1
{
PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();
}
}
I then applied the shader in my C#:
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
_iceShader.Parameters["IceTexture"].SetValue(iceTexture);
_iceShader.CurrentTechnique.Passes[0].Apply();
And here’s where the weirdness begins. Any function I write in PixelShaderFunction works on the base texture (i.e. if I change the shader to inverse the pixel color, or set everything to red), but when I use tex2D(ice_sampler, coords);, the result is still taken from the texture from the spritebatch, not the IceTexture I set value to in C#.
Is there something I’m doing wrong? Many thanks for any help!
SgtMook