Modern games use effects to improve visual quality as well as add gameplay values, like fog of war. Effects can be achieved by using textures with alpha blending but it is not efficient way and can dramatically drop FPS especially for full screen effects. Pixel shaders better way to do such things. It is quite easy to add pixel shaders in MonoGame application but not that easy as textures. So let’s try to add simple effect that has one input parameter.
First at all we need pixel shader that implements required processing. Let’s create simple fade effect.
There is one input argument ColorAmount which is used as weight for linear interpolation between original pixel and fully dark one.
Now we have to compile to binary format. So far we need Windows host to run 2MGFX tool shipped with MonoGame installation package. This tool generates binary effect file. So let’s assume that we have compiled it to fade.xnb binary effect file.
Now we need to add it into our project and set its properly as BundleResource.
Content processing is one of amazing XNA features but effects should be loaded manually. Open Game1.cs and add next code into LoadContent routine.
Now we can use our effect in Draw loop. To test it let’s add simple tile texture and try to fill our screen with tiles processed by our effect.
Adding a texture is extremely simple, here we can use content processing and load it as follows.
tile.png is also should be added into Content folder and configured in the same way as fade.xnb file. Since we use content processing and don’t load it directly as binary stream we skip Content folder in texture file path. The Content is already configured as root folder in Game constructor.
Cursor is hided by default in MonoGame 3.2 so we explicitly enabled it in last line.
Now modify Draw loop and add effect and tile.
Build and run it.