I am trying to implement a very simple pixel shader for some basic lighting using this tutorial http://www.xnahub.com/simple-2d-lighting-system-in-c-and-monogame/
My problem is that when the effect is applied the circular gradient ends up looking like an ellipse(left) instead of its circular shape(right).
The technique I use is to have two render targets in monogame and blend them together. The first one is all of the light masks textures, and the second is the render target I want to add the lighting effect to.
I believe the problem is related to the shader itself because when I use this code I get the ellipse(left picture)
//Blend both render targets together onto the backbuffer
GraphicsDevice.SetRenderTarget(null);
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
effect1.Parameters["lightMask"].SetValue(lightsTarget);
effect1.CurrentTechnique.Passes[0].Apply();
spriteBatch.Draw(mainTarget, Vector2.Zero, Color.White);
//spriteBatch.Draw(lightsTarget, Vector2.Zero, Color.White);
spriteBatch.End();
However, when I comment out the effect and just draw the light render target. I get a nice circle(right picture)
//Blend both render targets together onto the backbuffer
GraphicsDevice.SetRenderTarget(null);
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
//effect1.Parameters["lightMask"].SetValue(lightsTarget);
//effect1.CurrentTechnique.Passes[0].Apply();
//spriteBatch.Draw(mainTarget, Vector2.Zero, Color.White);
spriteBatch.Draw(lightsTarget, Vector2.Zero, Color.White);
spriteBatch.End();
This is my effect file
sampler s0;
texture lightMask;
sampler lightSampler : register(s1) = sampler_state {Texture = <lightMask>;};
float4 PixelShaderFunction(float4 pos : SV_Position, float4 color1 : COLOR0, float2 coords: TEXCOORD0) : COLOR0
{
float4 color = tex2D(s0, coords);
float4 lightColor = tex2D(lightSampler, coords);
return color * lightColor;
}
technique Technique1
{
pass Pass1
{
PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();
}
}
Thanks.