/ShaderTools

A PCL library that helps with some useful tools when working with shaders in MonoGame, like a reflection helper that determines if the project gets used for OpenGL or DirectX.

Primary LanguageC#The UnlicenseUnlicense

NuGet NuGet 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 ShaderTools

A PCL library that helps with some useful tools when working with shaders in MonoGame, like a reflection helper that determines if the project gets used for OpenGL or DirectX.

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

Getting Started

GraphicsDeviceExtensions

public static void Clear(this GraphicsDevice graphicsDevice, RenderTarget2D renderTarget, Color? clearColor = null)
{
  graphicsDevice.SetRenderTarget(renderTarget);
  graphicsDevice.Clear(Color.Black);
}

SpriteBatchExtensions

Draw a fullscreen quad to the rendertarget of your choice.

spriteBatch.DrawFullscreenQuad(BloomRenderTarget2,
  BloomRenderTarget1,
  GaussianBlurEffect,
  null,
  SamplerState.AnisotropicClamp);

Begins the spriteBatch and draws the given texture on to the given RenderTarget using the given parameters. Tidies up your code a bit. Nothing more, nothing less.

SystemProbe

Probes your game upon start (static class constructor) via reflection for the graphics-profile you use (OpenGL or DirectX). After that you can get it using a static accessor, or you can get the file-extension a shader file would have (ogl or dx11) using another accessor.

GraphicsApi api = SystemProbe.CurrentGraphicsApi;
string name = resourceName + "." + SystemProbe.CurrentShaderExtension + ".mgfxo"

EmbeddedEffectManager

Loads effects that have been embedded in a DLL. Needs the Assembly that is this DLL of course and a fully qualified name to get the file.

private EmbeddedEffectsManager EmbeddedEffectsManager { get; } =
  new EmbeddedEffectsManager(typeof(Renderer), "BloomEffectRenderer.Effects.Resources");

public void LoadContent(GraphicsDevice graphicsDevice)
{
  ExtractEffect = EmbeddedEffectsManager.Load(graphicsDevice, "BloomExtract");
  GaussianBlurEffect = EmbeddedEffectsManager.Load(graphicsDevice, "GaussianBlur");
  CombineEffect = EmbeddedEffectsManager.Load(graphicsDevice, "BloomCombine");
}

public void UnloadContent()
{
  EmbeddedEffectsManager.UnloadContent();
}