I’ve been tearing my hair out over this! I have a game that works fine as a Windows-only project, but I have been trying to covert it to a DesktopGL project so that I can run it on Windows and Linux. I think I’ve almost completed the task, but I’ve hit a problem that I just can’t figure out. My shaders throw up errors with DesktopGL. Here’s one such shader:
#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 SpriteTexture;
sampler s0;
bool blurApply = true;
float blurAmount = 1.0f;
float blurScaledAmount;
sampler2D SpriteTextureSampler = sampler_state
{
Texture = <SpriteTexture>;
};
struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
float2 TextureCoordinates : TEXCOORD0;
};
float4 MainPS(VertexShaderOutput input) : COLOR
{
float4 color = tex2D(s0, input.TextureCoordinates);
if (blurApply)
{
blurScaledAmount = blurAmount * 0.0006f;
color += tex2D(s0, input.TextureCoordinates + float2(blurScaledAmount, 0.00f));
color += tex2D(s0, input.TextureCoordinates + float2(-blurScaledAmount, 0.00f));
color += tex2D(s0, input.TextureCoordinates + float2(2.0f * blurScaledAmount, 0.00f) * 0.5f);
color += tex2D(s0, input.TextureCoordinates + float2(-2.0f * blurScaledAmount, 0.00f) * 0.5f);
color += tex2D(s0, input.TextureCoordinates + float2(3.0f * blurScaledAmount, 0.00f) * 0.25f);
color += tex2D(s0, input.TextureCoordinates + float2(-3.0f * blurScaledAmount, 0.00f) * 0.25f);
color += tex2D(s0, input.TextureCoordinates + float2(0.00f, blurScaledAmount));
color += tex2D(s0, input.TextureCoordinates + float2(0.00f, -blurScaledAmount));
color += tex2D(s0, input.TextureCoordinates + float2(0.00f, 2.0f * blurScaledAmount) * 0.5f);
color += tex2D(s0, input.TextureCoordinates + float2(0.00f, -2.0f * blurScaledAmount) * 0.5f);
color += tex2D(s0, input.TextureCoordinates + float2(0.00f, 3.0f * blurScaledAmount) * 0.25f);
color += tex2D(s0, input.TextureCoordinates + float2(0.00f, -3.0f * blurScaledAmount) * 0.25f);
color += tex2D(s0, input.TextureCoordinates + float2(blurScaledAmount, blurScaledAmount) * 0.75f);
color += tex2D(s0, input.TextureCoordinates + float2(-blurScaledAmount, blurScaledAmount) * 0.75f);
color += tex2D(s0, input.TextureCoordinates + float2(-blurScaledAmount, -blurScaledAmount) * 0.75f);
color += tex2D(s0, input.TextureCoordinates + float2(blurScaledAmount, -blurScaledAmount) * 0.75f);
color /= 17.0f;
}
return color;
}
technique SpriteDrawing
{
pass P0
{
PixelShader = compile PS_SHADERMODEL MainPS();
}
};
And here’s how I access the shader in my C# code:
gaussianBlur.Parameters["blurApply"].SetValue(info.gaussianBlurApply); gaussianBlur.Parameters["blurAmount"].SetValue(info.gaussianBlurAmount);
And here’s the error that I get:
The command ""C:\Program Files (x86)\MSBuild\MonoGame\v3.0\Tools\MGCB.exe" /quiet /platform:DesktopGL /@:"D:\Work\Games\PACAdventure\PACAdventure\Content\Content.mgcb" /outputDir:"bin\DesktopGL\Content" /intermediateDir:"obj\DesktopGL\Content"" exited with code 2.
And here’s the console output:
1> D:/Work/Games/PACAdventure/PACAdventure/Content/shaders/GaussianBlur.fx: D:\\Work\\Games\\PACAdventure\\PACAdventure\\Content\\shaders\\GaussianBlur.fx(34,3-41): error X3025: global variables are implicitly constant, enable compatibility mode to allow modification
I have cobbled this shader together from pieces of other shaders, and I don’t know enough about them to be able to work out what’s wrong. From digging around in the forums I think I’ve worked out that the variables I define at the top need to be static constants, which seems to be what the output above is trying to tell me, but when I try to make them so, I get other errors. I’m not sure I need the #if/else stuff at the top anymore either. I wondered if anyone might be kind enough to point out the places in which I’m going wrong as I’m just randomly changing things without knowing what I’m doing!