Need help converting this shader from unity

Hey guys, I have some shaders I would love to use in monogame that I have from unity, but I’m really struggling to understand how to do this. In unity shaders are much simpler than monogame. Any help at least pointing me in the right direction would be much appreciated.

Shaders have never looked much simpler in Unity to me… Just the manner to write them is different.

Nonetheless, you will have a lot of code to read and convert maybe (all the #include “*.cginc”) as Unity uses some “inhouse” methods like UnityMetaVertexPosition() etc.

To which language do you want to convert this code ? HLSL or GLSL ?
In both cases, the structure is more or less the same but semantics.

ShaderForge makes unity shaders really easy. You’ll need to translate to HLSL to use the shader in MG. Luckily HLSL is a lot like Cg.

You should remove the sections stuff like “Properties {” and “SubShader {” and also the Cg things like CGPROGRAM and ENDCG. Remove everything that is not within a CGPROGRAM-ENDCG block as well except for the properties, you’ll need to change those a bit. Then you can add the passes and compilation, check out a MonoGame template shader for this. The template also shows you how to add a texture with a sampler for it, use this for the two texture properties. The range is just a float. Then the hardest part will probably be replacing the stuff that’s built into Unity… Once you’ve done that, just try building the effect and the tool will tell you about any errors. You can also use HLSL Tools for VS, check out the VS gallery, this tool is awesome!