I have been trying to make the transition from XNA over to Monogame and custom shaders have been kicking my ass. I’ve read a fair number of posts here and different things around the internet but as much as I try and I cannot seem to get even the simplest of custom shader to work. All other content assets seem to be working fine.
My environment is
Windows 8.1 x64
VS2013 Ultimate
Monogame 3.2
My solution consists of 3 projects.
Primary MonoGame Project (Using the Monogame Windows dll)
Proxy XNA 4 Project
XNA 4 Content Project (Monogame Content Process has been added as a reference, inside the csproj I have MonoGamePlatform set to Windows)
I have the effect file setup as follows
Build Action Compile
Content Importer: Effect - XNA Framework
Content Processor: MonoGame Effect
Below is a simple shader that I ported over to MonoGame (I updated the POSITION0 as I had read about that in certain places). This works fine in XNA.
float4x4 View;
float4x4 Projection;
int Time;
texture PhotoTexture;
sampler PhotoSampler = sampler_state
{
texture = <PhotoTexture>;
AddressU = Wrap;
AddressV = Wrap;
MinFilter = Anisotropic;
MagFilter = Anisotropic;
MipFilter = Point;
};
struct VertexShaderInput
{
float4 Position : SV_POSITION;
float3 Normal : NORMAL0;
float2 UV : TEXCOORD0;
};
struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float3 Normal : NORMAL0;
float2 UV : TEXCOORD0;
};
VertexShaderOutput VertexShaderFunction(VertexShaderInput Input)
{
VertexShaderOutput Output;
Output.Position = mul(Input.Position, mul(View, Projection));
Output.Normal = Input.Normal;
Output.UV = Input.UV;
return Output;
}
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
float4 Color = tex2D(PhotoSampler, input.UV);
float Alpha = clamp((Time - input.Normal.x) * input.Normal.y / 255, 0, 1);
return float4(Color.x, Color.y, Color.z, Alpha);
}
technique Technique1
{
pass Pass1
{
VertexShader = compile vs_3_0 VertexShaderFunction();
PixelShader = compile ps_3_0 PixelShaderFunction();
}
}
The content compiles without error but when loading it I get the
An exception of type 'System.Exception' occurred in MonoGame.Framework.dll but was not handled in user code
Additional information: The MGFX file is corrupt!
Problem
I really love the concept of MonoGame and would love to be able to continue some of my XNA projects in it. I know there probably is information that is needed that I have left out so just ask away if you need more details. I only need this to work for traditional windows desktop applications, and would like to target DX11.
Any help would be greatly appreciated.
Thanks