I have been trying to load this custom FX file into a Monogame project, and everything I try fails. (code taken from http://www.david-gouveia.com/scrolling-textures-with-zoom-and-rotation/)

sampler TextureSampler : register(s0);
float2 ViewportSize;
float4x4 ScrollMatrix;

void SpriteVertexShader(inout float4 color : COLOR0, inout float2 texCoord : TEXCOORD0, inout float4 position : POSITION0)
   position.xy -= 0.5;

   position.xy = position.xy / ViewportSize;
   position.xy *= float2(2, -2);
   position.xy -= float2(1, -1);

   texCoord = mul(float4(texCoord.xy, 0, 1), ScrollMatrix).xy;

technique SpriteBatch
        VertexShader = compile vs_2_0 SpriteVertexShader();

If I convert it to an XNB file, and attempt to load it via the Content processor, it says "Could not load asset!", indicating that the file cannot be found. The XNB file is there along with the rest of the content, it is just not being loaded.

Next, I compiled the FX files into a MGFX file using 2MGFX. I included the MGFX files as an embedded resource and attempted to load the file by doing:

Effect test = new Effect(GraphicsDevice, Properties.Resources.parallax);

This crashed at Effect.cs saying argument out of range error.

What do I need to do to use this shader in Monogame?

  • 2
    \$\begingroup\$ Are you using the develop3d branch? I have an outstanding question on the MonoGame forums about this which no one has touched. Essentially as soon as I even modify one of the pre-built effects the content importer wont process the file correctly. I did every step that you did with similar results. \$\endgroup\$
    – RobCurr
    Feb 27, 2013 at 17:10
  • \$\begingroup\$ Yes, I am compiling the latest source from the develop3d branch. \$\endgroup\$
    – jgallant
    Feb 27, 2013 at 19:06
  • 1
    \$\begingroup\$ @Jon I've also been trying to convert David Gouveia's example to MonoGame. I was able to get the custom effect to load by using a MonoGameContent project to generate the xnb file, however, when I attempt to draw the background, _spriteBatch.End() throws this exception "Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection." \$\endgroup\$
    – Drew
    Aug 31, 2013 at 22:14
  • \$\begingroup\$ @Drew I got to the same error. It is essentially crashing while reading the data. \$\endgroup\$
    – jgallant
    Sep 1, 2013 at 16:29
  • \$\begingroup\$ I've started a thread over at MonoGame's CodePlex portal: monogame.codeplex.com/discussions/455139 \$\endgroup\$
    – Drew
    Sep 2, 2013 at 20:48


Browse other questions tagged .