4

EDIT: The issue is now solved, I'm including the details here to help anyone else who runs into this, as it's not that simple to solve.

Basically, it comes down to updating using the develop branch.

The first step is to checkout the monogame develop branch, this will not include the thirdparty/libs submodule, so you need to also update this in order to be able to compile the sources.

After this, you can compile MonoGame.Framework.Linux.sln, and update the references in your project to point to the new dll files.

This will still not load effect files, unless they are created using an up-to-date version of the content processors, so you need to go to a windows computer, checkout the develop branch (and libs) - or copy them from your linux system - then compile MonoGame.ContentPipeline/ContentProcessors/MonoGameContentProcessors.sln

You need to update the reference to MonoGameContentProcessors.dll in your content project, you also need to rename the MonoGame.ContentPipeline\ContentProcessors\bin\Release\libmojoshader_32.dll file to simply libmojoshader.dll.

Once all of this is done, you can finally use it as intended - build the .xnb files from your .fx files and add them to the linux project.

Hopefully this information will be useful to someone.

================================================= Original post:

I have just started out with MonoGame, and am trying to get a very simple application (rotating cube) to work on Windows and Linux - windows is not proving to be a problem, but I am having trouble getting my .fx files to work on Linux.

I have set up a "MonoGame Content Project", added the .fx file to it, selected the "MonoGame Effect" processor, set the build configuration to Linux - this all seems to work and i get a .xnb file in the output directory.

When I set up the Linux project, I copied the .xnb to the "Content" folder (the root directory is set accordingly) and used the following code to load the effect (same code as on windows):

CubeEffect = Content.Load<Effect>("Effect1");
CubeEffect.CurrentTechnique = CubeEffect.Techniques["Technique1"];

This then results in an application crash with this error:

Microsoft.Xna.Framework.Content.ContentLoadException: Could not load Effect1 asset!

Initially i assumed this to be a problem with file names, directory names, or some incorrect setting. However, i tried adding a .png file to the content folder and loading that:

Texture2D Tex = Content.Load<Texture2D>("bg.png");

This works perfectly well (checked the properties of the Texture2D in the debugger, and it has correct details for the file).

Have i missed a step somewhere when converting the shader file? Is there some really obvious thing that I'm not seeing?

If not, does anyone have any clue why it would act like this, or some way to get a more detailed error from it, like an actual reason for it not being able to load the asset?

EDIT: Having looked at the point in the disassembly where it actually throws the error, it seems that it finds the file, but doesn't recognise it as any valid resource type - could this be some kind of version/compatibility issue?

  • Normally you do not need to add the file extension for content, but if adding .png helped for the image file, perhaps adding .fx to the effect file will resolve the problem... – gareththegeek Jun 12 '13 at 14:43
  • The .png works fine with or without the extension, if I specify the effect as .fx it simply has the same error as before, if I specify as .xnb it says "Could not find matching content reader of type" instead. – George Quinn Jun 12 '13 at 15:17
  • I wish that MS would not have sacked XNA.. everything was so much simpler. Thinking of going back to XNA with the VS2013 refresh.. https://msxna.codeplex.com/releases/view/117230 – JensB Aug 31 '14 at 18:49

1 Answers1

2

This is a very common problem when trying to load shaders into Monogame. I tried, and failed to be able to load my custom shader into the Monogame framework.

You need to compile from the develop3d branch, and not the official release. You also need to convert your HLSL shader into a MojoShader compatible syntax. Then you need to either load the effect from the Monogame Content importer (which needs to be configured manually), or add your shader as an embedded resource and load it into your project in order to use it.

I have never been able to actually pull this off myself. From my readings online, this particular part of the Monogame framework is not quite ready for primetime yet.

Here is some information on it. They really didn't provide much information on this as I suspect they know it is very problematic:

https://github.com/mono/MonoGame/wiki/Effects-And-Shaders

jgallant
  • 11,143
  • 1
  • 38
  • 72
  • apparently I can't even get as far as compiling the sources.. seems to have some openTK issues. – George Quinn Jun 13 '13 at 14:42
  • some improvement - compiled the monogame framework for linux, now the error is "wrong MGFX file version", assuming that this means i need to compile the latest monogame.contentpipeline and use that in the VS2010 project used to create the .xnb files – George Quinn Jun 13 '13 at 14:56
  • for anyone with similar compile issue btw, you need to checkout the thirdparty/libs submodule from the repository to get the correct openTK dll. – George Quinn Jun 13 '13 at 14:57
  • Got it working now, thank you for the info - i'll modify my original post with details of what i did. – George Quinn Jun 13 '13 at 15:43
  • @GeorgeQuinn Glad you got it working. Thanks for providing the details on how you accomplished this. – jgallant Jun 13 '13 at 16:32