Monogame: Effect parameter keys differ between directx and opengl builds

Created on 25 Dec 2017  路  2Comments  路  Source: MonoGame/MonoGame

using Monogame 3.6 a shader with the following form:

#if OPENGL
    #define SV_POSITION POSITION
    #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

Texture2D RoadTexture;
Texture2D TerrainTexture;
Texture2D MaskTexture;

SamplerState Sampler;

With a DESKTOPGL build the effect.Parameters key ends up being "Sampler+TerrainTexture" etc.
With a windows/directx build it ends up being "TerrainTexture"

MGFX OpenGL

Most helpful comment

That said, MG could abstract this away for the user... Worth thinking about!

All 2 comments

This is because of a limitation in GLSL and the implementation of MojoShader. The issue is that the newer HLSL syntax seperates sampler and texture state, while in GLSL (and the old HLSL syntax) the texture is part of the sampler state. I.e. there is no distinction between texture and sampler. Because you can use 1 sampler to sample different textures in HLSL the different combinations of texture+sampler need a seperate sampler in GLSL. So MojoShader creates a Texture+SamplerState sampler for each used combination in HLSL. I think it makes sense from the perspective of MojoShader to keep the naming rules consistent regardless of whether there are actually conflicts in translating to GLSL.

That said, MG could abstract this away for the user... Worth thinking about!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Grabiobot picture Grabiobot  路  5Comments

bjornenalfa picture bjornenalfa  路  5Comments

Legendree picture Legendree  路  3Comments

NET-D3v3l0p3r picture NET-D3v3l0p3r  路  3Comments

SenpaiSharp picture SenpaiSharp  路  3Comments