Ruslan
Ruslan

Reputation: 98

How to use or make "Effects" in monogame?

I've been studing how to use monogame. So far the only thing I can't understand is what are effects. I just can't find any complete tutorials on how to make or use them.

I know that they are stored in .fx files and they are writen on some sort of language.

Can you please give me some directions. Where I can download effects? What should I use to make them? Can I use these effects in other languages? What should I google to learn more?

Upvotes: 2

Views: 4382

Answers (1)

Optimistic Peach
Optimistic Peach

Reputation: 4273

Wow, what a broad question... You should start by googling it.
Then, read some of the tutorials, I recommend the one by RB Whitaker.
Then, afterwards, using some knowledge of C# or C++ or C or Java (HLSL is similar to those), look up how to write effects for MonoGame. Try to look up examples. Also, looking at the MonoGame and BasicEffect source code isn't a bad idea if you're stuck on something. Also, most XNA stuff still applies to MonoGame, so researching XNA along with MonoGame is a great idea.

As for how to use it in an application that uses MonoGame, use this in a LoadContent function:

var effect = Content.Load<Effect>("EffectNameHere");

Now to answer your questions specifically:

So far the only thing I can't understand is what are effects.

Effects are basically just a MonoGame/XNA wrapper for shaders. Shaders are basically a small program that's run on the GPU. Shaders can have different stages depending on what api you are targeting with the shading language (glsl for OpenGL, hlsl for DirectX, metal for, well Metal etc.). Note that you can only target hlsl with MonoGame and not glsl. This is because when MonoGame tries to use the code in an OpenGL context, the shader's bytecode is directly translated into glsl bytecode. Look at this page for the stages of hlsl.

Where I can download effects?

You usually don't, and write them yourself. Either way, finding hlsl shaders is harder than finding glsl shaders (OpenGL is kind of a universal thing...) which can then be ported to hlsl.

What should I use to make them?

It's really your choice, be it notepad, VSCode, notepad++ or any of the like. I personally recommend to use the hlsl editor that comes with Visual Studio (Note: you have to install a package to get the graphics and shaders tools). Then, it's just trial and error until either you get it to compile, or until it works.

Can I use these effects in other languages?

Effects are mainly just for MonoGame/XNA, but, the same hlsl code is usable by any language that has access to a DirectX wrapper/native implementation (I.E. C++). The DirectX api can then compile it in a similar fashion.

Another note of advice, if you're looking to use not just the Pixel shader stage and the Vertex shader stage with MonoGame, then you're out of luck. You will have to implement it, or just wait until a release that supports

Edit: I also forgot to give you the most important link of them all! The MonoGame Community

Upvotes: 5

Related Questions