I am having trouble using .fx shaders when porting content to Android (everything works on Windows). When I use the shaders to draw vertexes I get the error “System.InvalidOperationException: ‘Shader Compilation Failed’”. Does anyone know what I am doing wrong?
— More Details–
I use the content pipeline tool to to build my .fx shaders into xnb files. However, they still fail to load using the Content.load() method (textures work). Only when I add a built *.xnb file to the Content Folder in visual studio do they properly load and my program “works”, as long as I don’t use the shader. However when I apply the shader and try to draw vertexes, I get the above error.
I suppose I should be building my shaders differently, but I don’t know how.
Thanks for your help!
–edit–
If anyone can help me get any vertex shader effect to load in Android, that will probably do,
Here is the very simple effect I am trying to get working:
#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
texture Texture;
sampler TextureSampler = sampler_state
{
Texture = <Texture>;
};
struct VertexShaderInput
{
float4 Position : SV_POSITION0;
float3 Normal : NORMAL0;
float2 UV : TEXCOORD0;
};
struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float2 UV : TEXCOORD0;
float4 Color : COLOR0;
float Depth : FOG;
};
struct PixelShaderOutput
{
float4 Color : COLOR0;
float Depth : SV_Depth;
};
VertexShaderOutput MainVS(in VertexShaderInput input)
{
VertexShaderOutput output = (VertexShaderOutput)0;
output.UV = input.UV;
output.Position = input.Position;
output.Color = float4(1, 0, 1, 1);
output.Depth = 0.5f;
return output;
}
PixelShaderOutput MainPS(VertexShaderOutput input)
{
PixelShaderOutput output = (PixelShaderOutput)0;
output.Color = input.Color;
output.Depth = input.Depth;
return output;
}
technique BasicColorDrawing
{
pass P0
{
VertexShader = compile VS_SHADERMODEL MainVS();
PixelShader = compile PS_SHADERMODEL MainPS();
}
};