Shader Porting to Linux MonoGame

One of the things which I wanted to implement in the Vertices Engine were Crepuscular Rays, more commonly known as God Rays. These have become ubiquitous in games within the last 5 years. Some games get it right, and add it lightly in to add a sense of depth and atmosphere to a game. Others over do it and wash out the screen (Looking at you Dishonored).

Crepuscular Rays in Metric Racer

The other post processing effect that’d been on my wishlist was Depth of Field.

Depth of Field Post Processing Shader under XNA

It wasn’t too difficult to get them running individually on their own  in little test projects, but integrating them into the engine was something I’d been putting off for a while.

After a weekend of tweaking, i managed to finally get them both integrated into the engine and working under XNA, but the true test of the simplicity of any code is being able to port it over to another platform.

Porting into Linux

MonoGame is great, but there’s a few nuances too porting shader code over well. One of the biggest is making sure global variables are initialised. In XNA if you have a *.fx file with a globalvariable such as:

float SpecularIntensity = 1

In MonoGame, you’ll need to re-initialise that value of of 1 in your *.cs file from C#.

part.Effect.Parameters[SpecularIntensity].SetValue(_specularIntensity);

This was a big head ache of chasing problems when I was porting over Bloom.

After a few tweaks in the *.fx files, they ported over too OpenGL without much more fuss than what I’d mentioned already. MonoGame has gotten to the level now where porting over is becoming easier and easier with each release.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s