Shader Effect fx file gives me an error on compiling

Hey guys !

Im totally new to monogame. My first game im working on should be an neon shooter. So i decided to use some neon shaders or bloom effects. I Put them into the content pipeline and then i click on build. But usually everything works fine except this time. It gives me the following error :

E:/Programming/Xamarin/Xamarin/TestGame/TestGame/Content/Shaders/BloomCombine.fx E:/Programming/Xamarin/Xamarin/TestGame/TestGame/Content/Shaders/BloomCombine.fx: E:\Programming\Xamarin\Xamarin\TestGame\TestGame\Content\Shaders\BloomCombine.fx(49,68) : Unexpected token 'f' found. Expected CloseParenthesis E:\Programming\Xamarin\Xamarin\TestGame\TestGame\Content\Shaders\BloomCombine.fx(49,68) : Unexpected token 'f' found. Expected CloseBracket E:\Programming\Xamarin\Xamarin\TestGame\TestGame\Content\Shaders\BloomCombine.fx(49,68) : Unexpected token 'f' found. Expected CloseBracket

I really have no idea what that means and how to solve this any ideas ? Heres the BloomCombine.fx file :

//----------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------//

// Pixel shader combines the bloom image with the original
// scene, using tweakable intensity levels and saturation.
// This is the final step in applying a bloom postprocess.

sampler BloomSampler : register(s0);
sampler BaseSampler : register(s1);

float BloomIntensity;
float BaseIntensity;

float BloomSaturation;
float BaseSaturation;


// Helper for modifying the saturation of a color.
 float4 AdjustSaturation(float4 color, float saturation)
 {
// The constants 0.3, 0.59, and 0.11 are chosen because the
// human eye is more sensitive to green light, and less to blue.
float grey = dot(color, float3(0.3, 0.59, 0.11));

return lerp(grey, color, saturation);
}


float4 PixelShaderFunction(float2 texCoord : TEXCOORD0) : COLOR0
{
// Look up the bloom and original base image colors.
float4 bloom = tex2D(BloomSampler, texCoord);
float4 base = tex2D(BaseSampler, texCoord);

// Adjust color saturation and intensity.
bloom = AdjustSaturation(bloom, BloomSaturation) * BloomIntensity;
base = AdjustSaturation(base, BaseSaturation) * BaseIntensity;

// Darken down the base image in areas where there is a lot of bloom,
// to prevent things looking excessively burned-out.
base *= (1 - saturate(bloom));

// Combine the two images.
return base + bloom;
}


technique BloomCombine
{
pass Pass1
{
    PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction(float4 pos : SV_POSITION, float4 color1 : COLOR0, float2 coords: TEXCOORD0);
}
}

//----------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------//

1 Like

You specify a wrong pixelshader in your technique/pass.

Use this

technique BloomCombine
{
pass Pass1
{
    PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();
}
}

then report back

Hey there ! Thanks for the tipp but it wont compile :confused: Now i got this error here :

E:/Programming/Xamarin/Xamarin/TestGame/TestGame/Content/Shaders/BloomCombine.fx
E:\Programming\Xamarin\Xamarin\TestGame\TestGame\Content\Shaders\BloomCombine.fx(20,18): warning X3206: ‘dot’: implicit truncation of vector type

well there is your solution

Change

float grey = dot(color, float3(0.3, 0.59, 0.11));

to

float grey = dot(color.rgb, float3(0.3, 0.59, 0.11));

what was the problem? -> ‘dot’: implicit truncation of vector type
which means we use some math on vectors of different sizes and one of them has been truncated to make it work.
color by default is a float4, the other is a float3. The monogame compiler doesn’t like that.

1 Like

Thanks mate ! It worked :smiley:. I also wanna run this on my school pc. Will it work ? Or do i need to install directX for it ?

most likely will just work, if not you probably need to install .net 3.5 runtime environment

1 Like