Shader language / Compatibility?


I’m trying to decide which library to use for an upcoming university assignment regardings shader-based real time grass rendering. Since I’m already using HLSL in another course, I would like to use the same here. However, since MonoGame is cross-plattform, is it possible to only run/force DirectX using HLSL or will I run into any problems?

I already saw other topics regarding HLSL when running a DirectX MonoGame application, so it sounds like it is entirely possible. I do not need a detailed response, a simple “Yes, sure, no problems - it’s like using XNA” would suffice.

So far, I’m thinking about either using MonoGame or Unity - Unity however uses Nvidia Cg to support both DirectX and OpenGL.

Thank you.

I’ve written a raytracer in HLSL that I used in MonoGame and it ported with little to no issue. It was awhile ago so I don’t remember the details completely, but it worked well.

If I remember correctly, I had a problem with a built-in function, perhaps float3.Reflection or similar, but it was an easy fix. Just create a .FX file and set the content handler to build it as the proper shader.
The same shader worked in Windows 8 and Android

Thanks for the response! This sounds pretty good so far. I’ve already set up my MonoGame project using DirectX as well as the Content Processor (to try out the .fx). I’m pretty happy and will most certainly use MonoGame instead of Unity for this assignment/project.

monogame will process your HLSL shader through MOJOSHADER which will create a GLSL version as well, that’s how it’s cross-platform. It compiles your HLSL, translates into GLSL and bundles it all up in a .xnb file for loading.

Ah, I currently have a MonoGame Content Project to compile my content. I also have a .fx file in there, which I would like to load using ContentManager.Load<Effect>("Effects/Test"). However, when running the project, it tells me that

The MGFX file is corrupt!

I’ve read that I have to use the MGFX tool to compile the file. However, I thought that the MonoGame Content Project is already supposed to do that. I created and linked it like explained here:

I also have XNA installed, so it’s probably (most certainly) using the XNA build tools to create the .xnb file (which is not through the MGFX tool). Since I only want to run the project on Windows, I would not neccesarily need the compatibility to other plattforms. Is there an easy way to set it up, so that it will automatically compile the content files using the MonoGame Content Project? Having to run another tool whenever I change my shader, could be very annoying.

Update: I probably have to reference the C:\Program Files (x86)\MSBuild\MonoGame\v3.0, which is where the 2MGFX tool is located. I can change the “Content Processor” of the .fx file to “MonoGame Effect” instead of “XNA Effect”, but then it tells me

The MGFX effect is the wrong profile for this platform!

which happens because I’m using a MonoGame DirectX (Windows8) project. I read that I have to set the Shader Model to 4.0 or higher (because I’m using a DirectX project meaning Windows8 target). However, when I do that, it tells me that…

Vertex shader ‘VertexShaderFunction’ must be SM 3.0 or lower!

Which would only be correct for OpenGL targets, according to this: GitHub - MonoGame/MonoGame: One framework for creating powerful cross-platform games.

Final Update:
It’s working now. I did not actually set the target/configuration to Windows8, it was the default “Debug” option. Now, after setting the shader model for Pixel and Vertex shader to 4.0, it works correctly under Windows 8.