Hello,
i’m realativ new to HLSL and got some problems with it.
I’m trying to use a simple shader on a single sprite. The shader i use looks like:
sampler s0;
float4 PixelShaderFunction(float4 position : SV_Position, float4 color : COLOR0, float2 coords : TEXCOORD0) : COLOR
{
color = tex2D(s0, coords);
color.rgb = color.gbr;
return color;
}
technique SimpleEffect
{
pass Pass1
{
PixelShader = compile ps_3_0 PixelShaderFunction();
}
}
if i use the shader in an single spritebatch.begin() spritebatch.end() draw call everything works fine, but if i try to make a second call all pictures turn red.
without the shader all looks fine
The following code is used to draw the shader and the additional two Images:
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
SimpleEffect.CurrentTechnique.Passes[0].Apply();
spriteBatch.Draw(TestImage, new Rectangle(0, 0, (int)(GraphicsDevice.PresentationParameters.BackBufferWidth / 1.33f), GraphicsDevice.PresentationParameters.BackBufferHeight), Color.White);
spriteBatch.End();
spriteBatch.Begin();
spriteBatch.Draw(TestImage, new Rectangle(0, 0, (int)(GraphicsDevice.PresentationParameters.BackBufferWidth / 2), GraphicsDevice.PresentationParameters.BackBufferHeight), Color.Green);
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
spriteBatch.Draw(TestImage, new Rectangle(0, 0, (int)(GraphicsDevice.PresentationParameters.BackBufferWidth / 4), GraphicsDevice.PresentationParameters.BackBufferHeight), Color.Yellow);
spriteBatch.End();