MonoGame Effects Compiler (MGFXC)
The MGFXC tool is used to compile DirectX Effect files (shaders) for usage with MonoGame. It will compile shaders into mgfxo files ready to be consumed by the
The MGCB Editor uses MGFXC to compile effects and wrap them into an xnb file, so they can be loaded using the
If you compile effects directly with MGFXC you can load effects using the
Microsoft.Framework.Xna.Graphics.Effect constructor that takes a byte array with the effect code.
Effects compiled directly are not content files and can not be loaded by the
In a terminal run
dotnet tool install -g dotnet-mgfxc to install MGFXC.
The command line options are:
mgfxc <SourceFile> <OutputFile> [/Debug] [/Profile:<DirectX_11,OpenGL,PlayStation4>]
The input effect file in typical FX format with samplers, techniques, and passes defined. This parameter is required.
The path to write the compiled effect to. This parameter is required.
NOTE: The generated file is not an XNB file for use with the ContentManager.
/Debug flag is passed the resulting compiled effect file will contain extra debug information and the fewest possible optimizations.
/Profile option defines the platform we're targeting with this effect file. It can be one of the following:
NOTE: PlayStation 4, Xbox One, and Switch support is only available to licensed console developers.
If you use
/help, or simply pass no parameters to MGFXC you will get information about these command-line options.
The resulting compiled effect file can be used from your game code like so:
byte bytecode = File.ReadAllBytes("mycompiled.mgfx"); var effect = new Effect(bytecode);
This is how the stock effects (BasicEffect, DualTextureEffect, etc) are compiled and loaded.