Help Converting ps_2_0 -> ps_4_0 ... XNA -> MonoGame

Its not a prefect piece of code (I realize that, so dont hate to hard). That being said is works and looks great in XNA, now I am trying to move this to MonoGame and its not going so well. Basically its drawing things right on the camera, and I have no idea why. Im sure it something simple, but im not the most shader knowledgeable. Please help!

also I did try Level_9_1 also and it did not fix it…

Here is my code:

// XNA 4.0 Shader Programming #4 - Normal Mapping

// Matrix
float4x4 World;
float4x4 View;
float4x4 Projection;

float4x4 xLightsWorldViewProjection;

// Light related
float4 AmbientColor;
float AmbientIntensity;
float2 UvChange;
float2 WaveSize;
float2 WaveChange;

float4 FilterColor;
float3 LightDirection;
float4 DiffuseColor;
float DiffuseIntensity;
float alpha;

float4 SpecularColor;
float3 EyePosition;


texture2D ColorMap;
sampler2D ColorMapSampler = sampler_state
{
    Texture = <ColorMap>;
    MinFilter = linear;
    MagFilter = linear;
    MipFilter = linear;
};

texture2D NormalMap;
sampler2D NormalMapSampler = sampler_state
{
    Texture = <NormalMap>;
    MinFilter = linear;
    MagFilter = linear;
    MipFilter = linear;
};

texture2D SpecularMap;
sampler2D SpecularMapSampler = sampler_state
{
    Texture = <SpecularMap>;
    MinFilter = linear;
    MagFilter = linear;
    MipFilter = linear;
};

float ShadowMapUniform;
texture2D ShadowMap;
sampler2D ShadowMapSampler = sampler_state
{
    texture = <ShadowMap>; 
    magfilter = LINEAR; 
    minfilter = LINEAR; 
    mipfilter= LINEAR; 
    AddressU = clamp; 
    AddressV = clamp;
};

// The input for the VertexShader
struct VertexShaderInput
{
    float4 Position : POSITION0;
    float2 TexCoord : TEXCOORD0;
    float3 Normal : NORMAL0;
    float3 Binormal : BINORMAL0;
    float3 Tangent : TANGENT0;


};

// The output from the vertex shader, used for later processing
struct VertexShaderOutput
{
    float4 Position : POSITION0;
    float4 Pos2DAsSeenByLight    : TEXCOORD0;
    float2 TexCoord : TEXCOORD1;
    float3 View : TEXCOORD2;
    float3x3 WorldToTangentSpace : TEXCOORD3;
    
};

// The VertexShader.
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);
    output.TexCoord = input.TexCoord;

    output.WorldToTangentSpace[0] = mul(normalize(input.Tangent), World);
    output.WorldToTangentSpace[1] = mul(normalize(input.Binormal), World);
    output.WorldToTangentSpace[2] = mul(normalize(input.Normal), World);
    
    output.View = normalize(float4(EyePosition,1.0) - worldPosition);

    output.Pos2DAsSeenByLight = mul(input.Position, xLightsWorldViewProjection);

    return output;
}

float ShadowCalc(VertexShaderOutput input)
{
    int num = 4;
    float4 shadowColors[5]; 

    float2 ProjectedTexCoords, ProjectedTexCoords2;
    ProjectedTexCoords[0] = input.Pos2DAsSeenByLight.x/input.Pos2DAsSeenByLight.w/2.0f +0.5f;
    ProjectedTexCoords[1] = -input.Pos2DAsSeenByLight.y/input.Pos2DAsSeenByLight.w/2.0f +0.5f;

    float ShadowMapUniformX2 = ShadowMapUniform*2;
    shadowColors[0] = tex2D(ShadowMapSampler, ProjectedTexCoords);
    //ProjectedTexCoords += float2(ShadowMapUniformX2, ShadowMapUniformX2);
    shadowColors[1] = tex2D(ShadowMapSampler, ProjectedTexCoords + float2(ShadowMapUniformX2, ShadowMapUniformX2));
    shadowColors[2] = tex2D(ShadowMapSampler, ProjectedTexCoords + float2(-ShadowMapUniformX2, ShadowMapUniformX2));
    shadowColors[3] = tex2D(ShadowMapSampler, ProjectedTexCoords + float2(ShadowMapUniformX2, -ShadowMapUniformX2));
    //shadowColors[4] = tex2D(ShadowMapSampler, ProjectedTexCoords + float2(-ShadowMapUniformX2, -ShadowMapUniformX2));

    float shadowAmount = 0;
    float realDistance = input.Pos2DAsSeenByLight.z/input.Pos2DAsSeenByLight.w - 1.0f/750.0f;
    float depthStoredInShadowMap;
    //float originDepth = (shadowColors[0].r * 65536.0f + shadowColors[0].g * 256.0f)/(65536.0f);


    for(int i=0; i<num; i++)
    {
        
            depthStoredInShadowMap = (shadowColors[i].r * 65536.0f + shadowColors[i].g * 256.0f)/(65536.0f);
        
            if (realDistance > depthStoredInShadowMap)
            {
                shadowAmount += shadowColors[i].b;
            }
        
    }

    shadowAmount = shadowAmount/(float)num;

    return (1-(shadowAmount * .5f));
}

// The Pixel Shader
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{


    float4 color = tex2D(ColorMapSampler, input.TexCoord );
    float4 temp = color;


    float3 normalMap = 2.0 *(tex2D(NormalMapSampler, input.TexCoord)) - 1.0;
    normalMap = normalize(mul(normalMap, input.WorldToTangentSpace));
    float4 normal = float4(normalMap,1.0);

    float4 specMap = tex2D(SpecularMapSampler, input.TexCoord);
    

    float4 diffuse = saturate(dot(-LightDirection,normal));
    float4 reflect = normalize(2*diffuse*normal-float4(LightDirection,1.0));
    float4 specular = pow(saturate(dot(reflect, input.View)), 20);

    color = (color /* * DiffuseIntensity * DiffuseColor*/ * diffuse) * 1.4f  + ( specMap * specular) * 1.4f;

    color = color * FilterColor;

    //////////////////// SHADOWS ///////////////////////////////////////////////////////////////////////
    
    color *= ShadowCalc(input);

    //////////////////// END SHADOWS //////////////////////////////////////////////////////////////////

    color.a = temp.a * alpha;

    return color;
}




// Our Techinique
technique Technique1
{
    pass Pass1
    {
        VertexShader = compile vs_4_0 VertexShaderFunction();
        PixelShader = compile ps_4_0 PixelShaderFunction();
    }
}

Edit: I also realize it could but an issue with the VS, I just put ps only for simplicity…

Is your game supposed to be released under Win8 and DirectX 11? If so, check this link: https://github.com/mono/MonoGame/wiki/Getting-Effect-.fx-files-to-compile-and-run---Hints,-Tips-and-Gotchas#3-windows8-dx11-profile-switch-position0-to-sv_position-in-fx-file and try to change POSITION0 semantics to SV_POSITION.

Thanks! I will give it a look over, and see what I can do :smile:

Ok, well i tried that SV_POSITION, and read through the link that you provided and the same issue still persists (tho everything compiled just fine and what not).

I reduced the project down to showing 1 model, and this is what I see:

This is what XNA shows:

This is what MonoGame shows

That being said Sizaar, I want to thank you for trying to help. And if you will shoot me your email address I will send you a game key when its on steam :wink:

Lastly I wanted to mention that SV_POSITION works just fine in XNA as well…

I hate to bug @Tom , but i really need help here, im pretty sure im just messing something minor up, but I have spent days working on this and I cant seem to get it to work…

Sooooo…

Dont use VS2013…

Works in VS2010, I got some other issues to Iron out but now at least the 1 shader is working…