I am working with an effect file that I do have building properly in Windows. The problem is that it randomly flashes the background color which should be the “fog of war” that I created. It is supposed to be a lighting effect that uses the mask to uncover parts of the shaded area or the fog of war. I was using monogame 3.2 for building in android and it works perfectly. I am using monogame 3.4 for Windows and I get nothing. Any thoughts on this would be awesome as I use monogame for all of my development and want to port my game to Windows
Here is the code for the effect
texture lightMask;
sampler mainSampler : register(s0);
sampler lightSampler = sampler_state{ Texture = <lightMask>; };
struct PixelShaderInput
{
float4 TextureCoords: TEXCOORD0;
};
float4 PixelShaderFunction(PixelShaderInput input) : COLOR0
{
float2 texCoord = input.TextureCoords;
float4 mainColor = tex2D(mainSampler, texCoord);
float4 lightColor = tex2D(lightSampler, texCoord);
lightColor.rgb * float3(1.2f, 1.2f, 1.2f);
mainColor.rgb /= mainColor.a;
return saturate(mainColor * lightColor) * 4;
}
technique Technique1
{
pass Pass1
{
PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();
}
}
Here is the code for drawing
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.SetRenderTarget(mainScene);
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
spriteBatch.Draw(Primitives.line, new Vector2(0, 0), scale: new Vector2(ScreenSize.X, ScreenSize.Y), color: new Color(1, 1, 1, 20));
Grid.Draw(spriteBatch, new Vector2(graphics.GraphicsDevice.Viewport.Width * 1.5f, graphics.GraphicsDevice.Viewport.Height * 1.5f));
ObjectManager.DrawBelowMask(spriteBatch);
GraphicsDevice.Clear(Color.Black);
spriteBatch.End();
GraphicsDevice.SetRenderTarget(null);
GraphicsDevice.SetRenderTarget(lightMask);
GraphicsDevice.Clear(new Color(15, 15, 15));
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
ObjectManager.DrawLight(spriteBatch);
spriteBatch.End();
GraphicsDevice.SetRenderTarget(null);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
Assets.light.Parameters["lightMask"].SetValue(lightMask);
Assets.light.CurrentTechnique.Passes[0].Apply();
spriteBatch.Draw(mainScene, new Vector2(0, 0), Color.White);
spriteBatch.End();
spriteBatch.Begin();
ObjectManager.DrawUI(spriteBatch);
spriteBatch.End();
ObjectManager.player.Draw(spriteBatch);
base.Draw(gameTime);
}