New to shaders....

Hello,

I had a question. Which shader model should be currently used?
There are vs_4_0_level_9_0 and vs_4_0_level_9_1 …
But most of the tutorials I found related to vs_1_1 or vs_3
I also read that there is a new syntax or new commands (a main method?) Is there somewhere a good DX9 to DX11 migration guide? (Or a good starter guide? Nothing good has been found on google yet :()

I don’t know about any good migration guides, but I can help with the shader profiles. Shader profiles differ between shaders compiled for DirectX and for OpenGL in MonoGame. You can use preprocessor directives to abstract that away.


Supported profiles

For DirectX projects:

  • [vp]s_4_0_level_9_1 => instead of [vp]s_2_0
  • [vp]s_4_0_level_9_1 => instead of [vp]s_3_0
  • [vp]s_4_0 (requires HiDef GraphicsProfile)
  • [vp]s_4_1 (requires HiDef GraphicsProfile)
  • [vp]s_5_0 (requires HiDef GraphicsProfile)

For OpenGL projects:

  • [vp]s_2_0
  • [vp]s_3_0

Note that DirectX shaders can be more complex because a higher profile can be used. That’s a limitation of the software MG uses to translate HLSL shaders to GLSL.


Here’s an example from the MG effect template:

#if OPENGL
    #define VS_SHADERMODEL vs_3_0
    #define PS_SHADERMODEL ps_3_0
#else
    #define VS_SHADERMODEL vs_4_0_level_9_1
    #define PS_SHADERMODEL ps_4_0_level_9_1
#endif
technique BasicColorDrawing
{
    pass P0
    {
        VertexShader = compile VS_SHADERMODEL MainVS();
        PixelShader = compile PS_SHADERMODEL MainPS();
    }
};
1 Like