I wrote a shader in XNA and I want to use it in a Monogame Windows Phone 8 project. I converted my Effect1.fx file to Effect1.mgfxo. But the program doesn't work correctly. The screen of my emulator is always black if I run this code and I get no error message. Why is the code not working? Why is the screen always black if I try to run my shader? Am I loading the shader correctly?
How can I use a custom shader in my Monogame Windows Phone 8 project?
My shader code:
float4x4 World;
float4x4 View;
float4x4 Projection;
sampler finalImage : register(s0);
sampler displacementMap : register(s1);
float4 main(float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
float displacement = tex2D(displacementMap, texCoord);
texCoord += displacement * 0.2;
return tex2D(finalImage, texCoord);
}
technique Refraction
{
pass pass_0
{
PixelShader = compile ps_4_0_level_9_3 main();
}
}
Code:
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
private Texture2D back;
public Texture2D shockwave;
private RenderTarget2D finalImage;
private RenderTarget2D distortionMap;
private Effect distortionEffect;
private Vector2 Touchpoint;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
TouchPanel.EnabledGestures = GestureType.Tap;
spriteBatch = new SpriteBatch(GraphicsDevice);
back = Content.Load<Texture2D>("background");
shockwave = Content.Load<Texture2D>("shockwavesprite");
finalImage = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
distortionMap = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
distortionEffect = Content.Load<Effect>("Effect1.mgfxo");
}