Skip to content

This is a PCL library for MonoGame. It uses your local MG installation and provides an easy way to render a bloom-post-process-effect from and to any RenderTarget you like.

License

Notifications You must be signed in to change notification settings

UnterrainerInformatik/BloomEffectRenderer

Repository files navigation

NuGet NuGet Build Status license Twitter Follow

General

This section contains various useful projects that should help your development-process.

This section of our GIT repositories is free. You may copy, use or rewrite every single one of its contained projects to your hearts content.
In order to get help with basic GIT commands you may try the GIT cheat-sheet on our homepage.

This repository located on our homepage is private since this is the master- and release-branch. You may clone it, but it will be read-only.
If you want to contribute to our repository (push, open pull requests), please use the copy on github located here: the public github repository

Icon BloomEffectRenderer

This class is a PCL library for MonoGame that implements a bloom effect.
If you'd like your game to truly shine, you can use this little beauty without much hassle.
The problem with that brute-force-approach is, that the number of checks grow very fast (N² for N sprites)

If you like this repo, please don't forget to star it. Thank you.

Getting Started

This project is based on the following blog posts:

You don't have to mess with shaders since those are included in the distribution.

Attributions

Thx to the MonoGame.Extended project for their excellent work and teaching me how to embed shaders into a DLL.

Thx to Jjagg for reviewing the shaders.

Image by Michael Beckwith from Inside St Kentigerns RC Church.

Example

private Point Resolution { get; } = new Point(1920, 1080);
private Renderer Renderer { get; } = new Renderer();

protected override void LoadContent()
{
  ...
  Renderer.LoadContent(GraphicsDevice);
  ...
}

protected override void UnloadContent()
{
  ...
  Renderer?.UnloadContent();
  ...
}

protected override void Initialize()
{
  base.Initialize();
  Renderer.Initialize(graphics.GraphicsDevice, Resolution);
}

protected override void Draw(GameTime gameTime)
{
  // Image is some Texture2D that will be drawn to the backbuffer in this example.
  // (hence the <null>).
  // To bloom your game in a post-process step, draw all your assets to a
  // RenderTarget2D first and then pass that rendertarget to this method.
  Renderer.Render(graphics.GraphicsDevice, spriteBatch, "image", Image, null, Settings.PRESET_SETTINGS[1]);
  base.Draw(gameTime);
}

Debugging

You may access any of the intermediate images produced by the renderer.

For that you'll have to pass a delegate when calling Render() like so:

// Your delegate. This one saves the images with some unique name, but you
// could also render them directly onto another RenderTarget, for example.
private void BloomDebugDelegate(string name, RenderTarget2D t, RenderPhase phase)
{
  FileStream fs = new FileStream($"{((int)phase)+1}{name}_{phase}.png", FileMode.OpenOrCreate);
  t.SaveAsPng(fs, texture2D.Width, texture2D.Height);
  fs.Flush();
  fs.Close();
}

// And call the renderer like so:
Renderer.Render(graphics.GraphicsDevice, spriteBatch, "image", Image, null, Settings.PRESET_SETTINGS[1], BloomDebugDelegate);

This will call your delegate once for every render-phase.

[PublicAPI]
public enum RenderPhase
{
  /// <summary>
  /// The original texture is processed and all values above
  /// the bloomthreshold are kept.
  /// </summary>
  EXTRACT,
  /// <summary>
  /// The extract-texture is blured horizontally via a gaussian
  /// blur and resized to half the size.
  /// </summary>
  BLUR_HORIZONTAL,
  /// <summary>
  /// The horizontally blurred texture is blurred again 
  /// vertically (size is kept at half).
  /// </summary>
  BLUR_VERTICAL,
  /// <summary>
  /// This step re-combines the original texture and the 
  /// two-times-blurred texture to a new image.
  /// </summary>
  COMBINE
}

TestGame

A test-project is included. You can manipulate the values of the shaders directly and see what happens.

Here are a few screenshots:

Bloom Off

Bloom 1

Bloom 2

Bloom 3

References

About

This is a PCL library for MonoGame. It uses your local MG installation and provides an easy way to render a bloom-post-process-effect from and to any RenderTarget you like.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published