Gorgon Shaders

So I got custom shaders up and running in Gorgon 2.0.  The new version has always had shader ability because it’s using Direct3D 11, so it’s required to use them.  However, up until now the shader code has been hardcoded to use 3 default shaders.  But after today, there’s an ability to use customized shaders:

In this little sample, there’s a new system at work.  It’s basically a mini effects framework that can do multi-pass rendering and in this video there’s a wave shader and an embossing shader at work on the sprite.  If you want to learn more, click the stupid link below

Shaders in this new version work a little differently than the previous version:

The first thing is that they’re Direct3D 11 shaders, so the use of constant buffers are required to send over your data to the shader.

The second thing is that shaders used in the 2D part of Gorgon require a little editing:

#GorgonInclude “Gorgon2DShaders”

That line should be at the top of the file so that Gorgon can import its own built in shaders (and so you can use them without trying to guess how I’ve laid everything out).

And finally, there’s the Effects system.  Which is still being worked out, but here’s the code I used to generate that video:

_2D.Target = _target2;
_2D.Effects.Wave.Amplitude = 0.01f;
_2D.Effects.Wave.Period += (50.0f / _target.Settings.Height) * timing.FrameDelta;
_2D.Effects.Wave.Length = 50.0f;
_2D.Effects.Wave.WaveType = WaveType.Both;
_2D.Effects.Wave.Render((int index) =>
{
   _2D.Drawing.Blit(_target, Vector2.Zero);
   _2D.Target = null;
   _2D.Effects.SharpenEmboss.Amount = 2.0f;
   _2D.Effects.SharpenEmboss.Area = _target.Settings.Size;
   _2D.Effects.SharpenEmboss.UseEmbossing = true;
   _2D.Effects.SharpenEmboss.Render((int innerIndex) =>
      {
         _2D.Drawing.Blit(_target2, position);
      });
   }
);

That’s the general gist of it anyway.  As you can see, there’s a SharpenEmboss and Wave effect, which are prepackaged with Gorgon under the Effects property.  I have several more prepackaged ones that I plan to implement, but, the user is also able to define their own by inheriting from one of Graphics.GorgonEffect or Renderers.Gorgon2DEffect.  The differences between the two are merely support.  The latter does a little more for you behind the scenes, while the former does barely anything at all for maximum control.

Anyway, that’s it.  I hope that’s of some use to someone.