My shader works on windows but not on Android?

I’m new to pixel shaders and I’ve created this very simple stencil shader that works as expected when run from a windows desktop client, but not on Android. Any idea what I am doing wrong?

Here’s the code for the shader:

Texture2D TextureBase;
sampler2D TextureSamplerBase = sampler_state
{
	Texture = <TextureBase>;
};

Texture2D Texture;
sampler2D TextureSampler = sampler_state
{
	Texture = <Texture>;
};

struct VertexShaderOutput
{
	float4 Position : TEXCOORD1;
	float4 Color : COLOR0;
	float2 TextureCordinate : TEXCOORD0;
};

float4 StencilShader(VertexShaderOutput input) : COLOR0
{
	float4 stencilColor = tex2D(TextureSampler, input.TextureCordinate);
	float4 baseColor = tex2D(TextureSamplerBase, input.TextureCordinate);

	return float4(baseColor.rgb, stencilColor.a);
}

technique StencilTechnique
{
	pass Pass0
	{
#if HLSL
		PixelShader = compile ps_4_0_level_9_3 StencilShader();
#else
		PixelShader = compile ps_2_0 StencilShader();
#endif
	}
}

First of all: Not an android dev, but maybe i can help.

before drawing do you change the blendstate of your graphicsDevice?

It should be AlphaBlend, Additive or NonPremultiplied, but maybe it’s not default on Android.

You could also change the pixelshader to 3_0 instead of 2_0, maybe that makes a difference, since it seems like the second texture overwrites the first one.

@Jjagg @KonajuGames any ideas?

@nebosite Can you try explicitly assigning a register to the textures? The texture you pass to the spritebatch call should be in t0. E.g. Texture2D TextureBase : register(t0); if that’s the texture you pass to spritebatch.

Jjagg, kosmonautgames,

Thanks for the tips - I changed the shader version 3_0 and I added this line to my Draw method:

GraphicsDevice.BlendState = BlendState.AlphaBlend;

and I changed my texture declarations like so:

Texture2D TextureBase : register(t1);
sampler2D TextureSamplerBase = sampler_state
{
	Texture = <TextureBase>;
};

Texture2D Texture : register(t0);
sampler2D TextureSampler = sampler_state
{
	Texture = <Texture>;
};

(I also tried switching the register assignments) The output is unchanged. This is true for windows too. This shader is working in windows, but not Android.

I’m not sure how MojoShader (which is what we use for GL shaders) assigns the samplers. Maybe it helps if you set sampler registers explicitly too?