Skip to content

6.3.0

Choose a tag to compare

@BenMakesGames BenMakesGames released this 27 Sep 21:21
· 46 commits to main since this release
  • Added method overloads related to MonoGame's Rectangle class (for rectangle-drawing and .Contains checks)
  • Added an API for applying shaders to groups of .Draw* calls (see below)

Shader API

As an example, suppose you have loaded a shader called "subtractive_plasma", which uses a time-based plasma effect (via a gameTime parameter) to omit parts of drawn objects:

public void DrawLayeredMonochromePlasma(GraphicsManager graphics, GameTime gameTime)
{
    graphics.Clear(Color.Black);

    // draw a blue rectangle, with plasma "holes" (via the subtractive_plasma shader)
    using (graphics.WithShader("subtractive_plasma", s => {
        s.Parameters["gameTime"].SetValue((float)gameTime.TotalGameTime.TotalSeconds);
    }))
    {
        graphics.DrawFilledRectangle(0, 0, graphics.Width, graphics.Height, Color.DarkBlue);
    }

    // draw a dark gray rectangle, with plasma "holes" (via the subtractive_plasma shader)
    using (graphics.WithShader("subtractive_plasma", s => {
        s.Parameters["gameTime"].SetValue((float)gameTime.TotalGameTime.TotalSeconds * 1.5f);
    }))
    {
        graphics.DrawFilledRectangle(0, 0, graphics.Width, graphics.Height, Color.DarkGray);
    }
}

of course, any number of .Draw* calls may be inside a using-.WithShader block; all will have the shader applied.