Giter Site home page Giter Site logo

secretsquirrelbucket / bloomeffectrenderer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from unterrainerinformatik/bloomeffectrenderer

0.0 0.0 0.0 2.2 MB

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: The Unlicense

C# 93.82% Batchfile 0.50% HLSL 5.68%

bloomeffectrenderer's Introduction

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

bloomeffectrenderer's People

Contributors

gufalcon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.