Shaders not compiling, ContentProcessor failure

Hey, I’m trying to create cross-platform game. My shaders running fine on Windows Phone, but it won’t compile for Android. Here is shortened source code:

float Shift;
float MaxShift;
float ExtraShiftScaleFactor;

struct VertexShaderOutput
{
    float4 position : SV_POSITION;
    float4 color : COLOR;
    float2 texCoords : TEXCOOR;
};

sampler TextureSampler;
    

// Input color (which comes from vertex shader output) - color specified in SpriteBatch.Draw() method.
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR
{
    const float4 originalColor = tex2D(TextureSampler, input.texCoords) * input.color;

    float4 newColor = tex2D(TextureSampler, float2(input.texCoords.x + sin(input.texCoords.x * Shift * ExtraShiftScaleFactor)*0.01, 
                            input.texCoords.y + sin(input.texCoords.y * Shift * ExtraShiftScaleFactor)*0.01)) * input.color;
    return newColor;
}

technique Technique1
{
    pass Pass1
    {
        PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();
    }
}

Any idea what’s wrong ? MGCB says that:
DX9-style intrinsics are disabled when not in dx9 compatibility mode.

I tried to change tex2D(…) to something like:

const float4 originalColor = texture2d,Sample(TextureSampler, input.texCoords) * input.color;

Also changed shader output from COLOR TO SV_Target, but finally I faced other problem (Content Processor unexpected failure)

PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();

to

PixelShader = compile ps_3_0 PixelShaderFunction();

I tried also this, but on Windows Phone target platform in MGCB it won’t compile with error:

Processor 'Effect Processor' had unexpected failure!
Invalid Profile ''. Pixel Shader 'PixelShaderFunction' must be SM 4.0 level 9.1 or higher.
...

and for Android platform target:

 invalid ps_3_0 input semantic TEXCOOR. 

-> I changed TEXCOOR to TEXCOORD and this shader compiles for Android (IDK if it works properly).

How to overcome this issue ? Is there some preprocessing like IF WINDOWS_PHONE use 4_0_9_1 else use 3_0

The monogame source code does that, not sure if they call it first though
https://github.com/MonoGame/MonoGame/blob/develop/MonoGame.Framework/Graphics/Effect/Resources/Macros.fxh

try

#ifdef SM4

#define TECHNIQUE(name, vsname, psname ) \ 
 	technique name { pass { VertexShader = compile vs_4_0_level_9_1 vsname (); PixelShader = compile ps_4_0_level_9_1 psname(); } } 

#else

#define TECHNIQUE(name, vsname, psname ) \ 
 	technique name { pass { VertexShader = compile vs_2_0 vsname (); PixelShader = compile ps_2_0 psname(); } } 

TECHNIQUE( BasicEffect, VSBasic, PSBasic );

Works like a charm, you saved my ass, thanks :slight_smile: It compiles fine both on Windows Phone and Android. So, on Android, is it necessary to use shader model 3.0 ? Or it also will be running fine on 4.0 if I fix shader code ? It’s just something I would like to know, if it works with macros it’s fine for me. Thanks again !

OpenGL can use up to 3_0, directX can use only 4_0_level_9_1 and up

1 Like