In the first image below, you can see what is rendered if I set effect in the SpriteBatch.Begin() to null, basically how it should be, and the second image shows what happens if I apply my effect. Why does this happen? Does the SpriteBatch.Begin() method pass weird texture coordinates to the shader, cause it seems the origin is somehow centered. If I turn on wrap in the texture sampler in the shader, the image is also repeated four times.
The effect code:
#if OPENGL
#define SV_POSITION POSITION
#define VS_SHADERMODEL vs_3_0
#define PS_SHADERMODEL ps_3_0
#else
#define VS_SHADERMODEL vs_4_0_level_9_1
#define PS_SHADERMODEL ps_4_0_level_9_1
#endif
texture Tex;
sampler2D texSampler = sampler_state
{
Texture = <Tex>;
AddressU = clamp;
AddressV = clamp;
Filter = linear;
};
float4 MainPS(float2 TexCoord : TEXCOORD0) : COLOR0
{
float4 col = tex2D(texSampler, TexCoord);
float4 sub = { 0.5f, 0.5f, 0.5f, 0};
col -= sub;
return col;
}
technique BasicColorDrawing
{
pass P0
{
PixelShader = compile PS_SHADERMODEL MainPS();
}
};
The draw code:
GraphicsDevice.SetRenderTarget(_screenTarget);
foreach(EffectPass pass in _basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numTriangles);
}
GraphicsDevice.SetRenderTarget(null);
_spriteBatch.Begin(SpriteSortMode.Immediate,
BlendState.AlphaBlend,
SamplerState.PointClamp,
DepthStencilState.Default,
RasterizerState.CullNone,
_testEffect);
_spriteBatch.Draw(_screenTarget, new Rectangle(0, 0, _graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight), null, Color.White);
_spriteBatch.End();
base.Draw(gameTime);