Thanks for the answers. Here is the scanline shader that i use.
#define SV_POSITION POSITION
#define VS_SHADERMODEL vs_3_0
#define PS_SHADERMODEL ps_3_0
#define VS_SHADERMODEL vs_4_0_level_9_1
#define PS_SHADERMODEL ps_4_0_level_9_1
sampler2D SpriteTextureSampler = sampler_state
Texture = <SpriteTexture>;
float4 Position : SV_POSITION;
float4 Color : COLOR0;
float2 TextureCoordinates : TEXCOORD0;
float4 MainPS(VertexShaderOutput input) : COLOR
float4 color = tex2D(TextureSampler, input.TexCoords);
int a = saturate((input.Position.y * 1080) % 4);// I just hardocde 1080 in here because that is the height of the screen. I can't really pass a texture height because there are different sprites with different heights.
int b = saturate((input.Position.y * 1080 + 1) % 4);// I would expect the scanlines to then line up over the different textures.
float m = min(a,b);
color.rgb *= m;
PixelShader = compile PS_SHADERMODEL MainPS();
This gives me the following error:
myEffect.fx(26,34): error X4502: Shader model ps_4_0_level_9_1 doesn't allow reading from position semantics.
This forum post says that this is simply a limitation of the older version of that pixel shader. He advises to pass the position again from the vertex shader so that you can use it in the pixel shader. That's why I wanted a vertex shader that does the same as the default but also passes the position through another variable.
I have tried passing the WorldViewProjection to the effect with the vertex shader like so:
myEffect = Content.Load<Effect>("effect");
I don't do anything fancy. This is the main game class.
spriteBatch.Begin( transformMatrix: camera.GetViewMatrix(),effect: myEffect);
And the player then draws various rectangles like so:
Rectangle destinationRectangle = new Rectangle((int)position.X, (int)position.Y, 16, 16);
spriteBatch.Draw(square, destinationRectangle, color:Color.Yellow);