1
\$\begingroup\$

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"); 
} 
\$\endgroup\$
  • \$\begingroup\$ You could use this: xnadevru.codeplex.com/… or this: sourceforge.net/projects/xnbbuilder or if you can create a seperate XNA project and build the XNBs from there. \$\endgroup\$ – Battle_Pasture Apr 17 '14 at 17:24
  • \$\begingroup\$ How can I do it in a separate XNA project? I tried it in a separate project but it's not working. \$\endgroup\$ – Homer_Simpson Apr 17 '14 at 18:17
  • \$\begingroup\$ Take the xnb from the project folder, add them to your monogame project. Set the properties of the xnb to content and copy if newer \$\endgroup\$ – Battle_Pasture Apr 17 '14 at 18:20
  • \$\begingroup\$ 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? \$\endgroup\$ – Homer_Simpson Apr 24 '14 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.