# Loading custom shader in Monogame [closed]

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
{
pass
{
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?

## closed as unclear what you're asking by Josh♦Dec 16 '13 at 17:22

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• 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. – RobCurr Feb 27 '13 at 17:10
• Yes, I am compiling the latest source from the develop3d branch. – jgallant Feb 27 '13 at 19:06
• @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." – Drew Aug 31 '13 at 22:14
• @Drew I got to the same error. It is essentially crashing while reading the data. – jgallant Sep 1 '13 at 16:29
• I've started a thread over at MonoGame's CodePlex portal: monogame.codeplex.com/discussions/455139 – Drew Sep 2 '13 at 20:48