Can anyone provide me with a Gaussian blur Effect Class?

I’m trying to use a gaussian blur effect, but I don’t want to load the shader from a file. Can anyone provide with a class which I can use as an Effect, because I don’t know how to convert an fx shader into a class?

Is there a particular reason you don’t want to load the shader from a file? The shader files are used by the GPU. The other options are to do it all in software or compile a shader on the fly and use it.

Well you can’t convert a shader into a class.
The only thing you could do is to have a class with the Shader-Code as a string and compile it at runtime.
But that’s horrible to maintain. You really should go with the shader-file

You could use this as a starting point (just blur all colors, not just above a threshold) or look for „xna Gaussian blur“ on google, there are a bunch of tutorials

1 Like

I agree that you are better off using a shader for anything that only affects how the screen is rendered.

There is a GLSL shader here that seems pretty legit.
Example Source

You will have to somehow convert it into HLSL so MonoGame can use it (you might not, I just started using it again, and maybe the functionality has been added).

You can convert it fairly easily manually, which if you don’t know a lot about shaders will be good for helping you see how they work.

Its easy to use a effect using the pipeline tool you basically just double click it (Content.mgcb) in visual studio to open it up. If you get a xml file that opens up instead of the tool executing then use “open with” or set the default visual studio uses to open it.

from there you should see the pipeline tool open up.

You want to edit → add a new item and pick effect.

From there using a hlsl effect is pretty simple here is a example i made a while back that uses a custom effect with spritebatch most of that is irrelevant but it shows how to load and use the effect as well as how to pass globals to it ect.

Using one of the shader examples posted by others above should be pretty intuitive from that point.

A bit late, but for people wanting a simple demo project (like I did), see this:

It is a conversion of this XNA project:

1 Like