I have a problem I’ve been working on for a few days porting my current work to Android, I have quite a few shaders that I’ve tested on Windows 10, Windows Phone, and Windows GL projects, and I have them all working correctly:
Windows Version with DirectX
Windows Version with OpenGL
However, I’ve had multiple issues porting these shaders onto Android. My first attempt in porting resulted in all of my graphics turning bright red, as referenced in Second spriteBatch.Draw() always turns textures Red to which I was able to fix this issue by explicitly writing my own pass-through vertex shader (I have no idea why this worked). However, my new issue is that either the vertex shader or the pixel shader is not operating on Android, as seen here:
Android Version, Platform 5.0.1, API Level 21, background not working
The shader responsible for managing this background work is a fairly simple Gaussian blur with a few settings (simplified to cut down on reading):
#define pixelX (10.0 / 1300)
#define pixelY (10.0 / 740)
#define reduction 0.22
float2 Viewport;
void SpriteVertexShader(inout float4 position : SV_Position, inout float4 color : COLOR0, inout float2 texCoord : TEXCOORD0)
{
// Correction for texel centering.
position.xy -= 0.5;
// Viewport fix.
position.xy = position.xy / Viewport;
position.xy *= float2(2, -2);
position.xy -= float2(1, -1);
}
sampler TextureSampler : register(s0);
float4 HorizontalGaussianBlur(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
float4 tex1 = tex2D(TextureSampler, texCoord + float2(pixelX * 6, 0));
...
float4 result = (0.7 * tex1 + 0.9 * tex2 + tex3 + 1.1 * tex4 + 1.2 * tex5 + 1.3 * tex6 + 1.4 * tex7 + 1.3 * tex8 + 1.2 * tex9 + 1.1 * texA + texB + 0.9 * texC + 0.7 * texD);
return float4(result.r * reduction, result.r * reduction, result.r * reduction, 1);
}
...
float4 EffectOff(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
float4 tex = tex2D(TextureSampler, texCoord);
return tex * color;
}
technique BlurTechnique
{
pass HorizontalGaussianBlurPass
{
#if HLSL
VertexShader = compile vs_4_0_level_9_3 SpriteVertexShader();
PixelShader = compile ps_4_0_level_9_3 HorizontalGaussianBlur();
#else
VertexShader = compile vs_2_0 SpriteVertexShader();
PixelShader = compile ps_2_0 HorizontalGaussianBlur();
#endif
}
...
}
So my primary question is: Am I doing something wrong when working with Android, such as missing a step when preparing my shaders, or do I have some underlying bug in my shaders that I’m not seeing?