Hello All,
I’ve been working on a XNA game for about 3 years now and I just got to a good cut off point to start my conversion which I’m doing mainly to get my game into x64 so I can use more than 1.3gigs of ram and the mutliplatform is a large bonus as well.
I just started converting my game yesterday and I’m using the Monogame Pipline tool to convert all my assets over and check for any compile errors in my shaders. I’ve been reading posts for weeks in this community and as with most people porting over the shaders / custom effect are a real problem. I’ve gotten most my sharders to compile via the tool except my most complex one which is used to render my planets. You can see an example below of what the sharder does:
The code for the effect is below:
////////////////////////////////////////////////////////////////////////////////
// Varibles
////////////////////////////////////////////////////////////////////////////////
float4x4 world : WORLD;
float4x4 view : VIEW;
float4x4 projection : PROJECTION;
float2 cloudMove;
float2 cloudShadowOffSet;
float4 cameraPos;
float4 globalAmbient;
float4 lightDir;
float4 lightColor;
float4 materialAmbient;
float4 materialDiffuse;
float4 materialSpecular;
float materialShininess;
float cloudStrength;
////////////////////////////////////////////////////////////////////////////////
// Texture Maps
////////////////////////////////////////////////////////////////////////////////
texture2D landOceanColorGlossMap;
sampler landOceanColorGlossMapSampler = sampler_state
{
Texture = <landOceanColorGlossMap>;
MagFilter = Linear;
MinFilter = Anisotropic;
MipFilter = Linear;
MaxAnisotropy = 16;
};
texture2D cloudColorMap;
sampler cloudColorMapSampler = sampler_state
{
Texture = <cloudColorMap>;
MagFilter = Linear;
MinFilter = Anisotropic;
MipFilter = Linear;
MaxAnisotropy = 16;
};
texture2D LowAltCloudColorMap;
sampler lowAltCloudColorMapSampler = sampler_state
{
Texture = <LowAltCloudColorMap>;
MagFilter = Linear;
MinFilter = Anisotropic;
MipFilter = Linear;
MaxAnisotropy = 16;
};
texture2D highAltCloudColorMap;
sampler highAltCloudColorMapSampler = sampler_state
{
Texture = <highAltCloudColorMap>;
MagFilter = Linear;
MinFilter = Anisotropic;
MipFilter = Linear;
MaxAnisotropy = 16;
};
texture2D nightColorMap;
sampler nightColorMapSampler = sampler_state
{
Texture = <nightColorMap>;
MagFilter = Linear;
MinFilter = Anisotropic;
MipFilter = Linear;
MaxAnisotropy = 16;
};
texture2D normalMap;
sampler normalMapSampler = sampler_state
{
Texture = <normalMap>;
MagFilter = Linear;
MinFilter = Anisotropic;
MipFilter = Linear;
MaxAnisotropy = 16;
};
////////////////////////////////////////////////////////////////////////////////
// Vertex Shaders
////////////////////////////////////////////////////////////////////////////////
void ParticleVertexShader(in float4 inPosition : POSITION,
in float2 inTexCoord : TEXCOORD,
in float3 inNormal : NORMAL,
in float3 inTangent : TANGENT,
in float3 inBitangent : BINORMAL,
out float4 outPosition : POSITION,
out float2 outTexCoord : TEXCOORD0,
out float3 outLightDir : TEXCOORD1,
out float3 outViewDir : TEXCOORD2,
out float3 outNormal : TEXCOORD3)
{
float4 worldPos = mul(inPosition, world);
float3 n = mul(inNormal, (float3x3)world);
float3 t = mul(inTangent, (float3x3)world);
float3 b = mul(inBitangent, (float3x3)world);
float3x3 tbnMatrix = float3x3(t.x, b.x, n.x,
t.y, b.y, n.y,
t.z, b.z, n.z);
outPosition = mul(mul(worldPos, view), projection);
outTexCoord = inTexCoord;
outLightDir = mul(-lightDir.xyz, tbnMatrix);
outViewDir = mul((cameraPos - worldPos).xyz, tbnMatrix);
outNormal = n;
}
/////////////////////////////////////////////////////////////////////////////////
// Pixel Shaders
/////////////////////////////////////////////////////////////////////////////////
void ParticlePixelShader(in float2 inTexCoord : TEXCOORD0,
in float3 inLightDir : TEXCOORD1,
in float3 inViewDir : TEXCOORD2,
in float3 inNormal : TEXCOORD3,
out float4 outColor : COLOR,
uniform bool bClouds, uniform bool atmos)
{
// X Attribute = Alpha | Y Attrubte = Green | Z Attribute is computed.
// DXT5nm format is used for the normalMapSampler.
float3 n = tex2D(normalMapSampler, inTexCoord).agb * 2.0f - 1.0f;
n.z = sqrt(1.0f - n.x * n.x - n.y * n.y);
n = normalize(n);
float3 l = normalize(inLightDir);
l = normalize(inLightDir);
float3 v = normalize(inViewDir);
float3 h = normalize(l + v);
float nDotL = saturate(dot(n, l));
float nDotH = saturate(dot(n, h));
float power = (nDotL <= 0.0f) ? 0.0f : pow(nDotH, materialShininess);
float4 ambient = (materialAmbient * (globalAmbient + lightColor));
float4 diffuse = (materialDiffuse * lightColor * nDotL);
float4 specular = (materialSpecular * lightColor * power);
float selfShadow = saturate(2.0f * l.z);
if(atmos)
{
selfShadow = saturate(1.0f * l.z);
}
float4 landOceanSample = tex2D(landOceanColorGlossMapSampler, inTexCoord);
float4 day = float4(landOceanSample.rgb, 1.0f) * (ambient + selfShadow * (diffuse + specular * landOceanSample.a));
float4 night = tex2D(nightColorMapSampler, inTexCoord) * (ambient + selfShadow * diffuse);
if (bClouds)
{
float cloud = tex2D(cloudColorMapSampler, inTexCoord - cloudMove).r;
float cloudShadow = tex2D(cloudColorMapSampler, inTexCoord - cloudShadowOffSet).r;
float cloudLowAltShadow = tex2D(lowAltCloudColorMapSampler, inTexCoord - cloudShadowOffSet).r;
float cloudLowAlt = tex2D(lowAltCloudColorMapSampler, inTexCoord - (cloudMove)).r;
float cloudHiAlt = tex2D(highAltCloudColorMapSampler, inTexCoord - (cloudMove * 1.7)).r;
float cloudDiffuse = saturate(dot(normalize(inNormal), normalize(-lightDir.xyz)));
day = day * (1.0f - cloudLowAltShadow) + (cloudLowAltShadow * cloudDiffuse * .01);
day = day * (1.0f - cloudLowAlt) + (cloudLowAlt * cloudDiffuse * cloudStrength);
day = day * (1.0f - cloudHiAlt) + (cloudHiAlt * cloudDiffuse * cloudStrength);
night = night * (1.0f - cloud) * cloudStrength;
}
outColor = day;
if (nDotL < 0.1f)
{
outColor = MixDayNight(night, day, (nDotL + 0.1f) * 5.0f);
}
}
////////////////////////////////////////////////////////////////////////////////
// Function
////////////////////////////////////////////////////////////////////////////////
float4 MixDayNight(in const float4 x, in const float4 y, in const float a)
{
return x * (1.0f - a) + y * a;
}
////////////////////////////////////////////////////////////////////////////////
// Techniques
////////////////////////////////////////////////////////////////////////////////
technique Atmosphere
{
pass
{
VertexShader = compile vs_4_0_level_9_1 ParticleVertexShader();
PixelShader = compile ps_4_0_level_9_1 ParticlePixelShader(false, true);
}
}
technique PlanetWithoutClouds
{
pass
{
VertexShader = compile vs_4_0_level_9_1 ParticleVertexShader();
PixelShader = compile ps_4_0_level_9_1 ParticlePixelShader(false, false);
}
}
technique PlanetWithClouds
{
pass
{
VertexShader = compile vs_4_0_level_9_1 ParticleVertexShader();
PixelShader = compile ps_4_0_level_9_1 ParticlePixelShader(true,false);
}
}
The compile issue it has is sending parameters to the ParticlePixelShader method. For whatever reason it does not like me doing that and throws the following errors:
…\effects\planet.fx(198,62) : Unexpected token ‘f’ found. Expected CloseParenthesis
…\effects\planet.fx(198,62) : Unexpected token ‘f’ found. Expected CloseBracket
…\effects\planet.fx(198,62) : Unexpected token ‘f’ found. Expected CloseBracket
…etc there are error each time I send parameters
I’m guessing the syntax has changed from the XNA version; does anyone know what it needs to be so I can send the values correctly? And if anyone see other issues let me know so I can get those correct. I could simply make 3 different function with no parms but I would hate to duplicate code like that…
Any help is GREATLY Appreciated!!!
I’m sure I will run into a lot more issues during runtime but just need to get it compiling for now.
For fun here are some other pics of the game: