Trouble Building my First Pixel Shaders

I want to start using pixel shaders in my 2D Monogame project, but even the simplest one I find refuses to build in my Monogame Pipeline project. Here’s the FX file:
float4 PixelShaderFunction(float2 coords: TEXCOORD0) : COLOR0
{
return float4(1, 0, 0, 1);
}

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

And my build-error:

I’m targeting Windows 7.

I have no idea what’s wrong because I’m new to graphics programming and Monogame. Can anyone tell me where to look to try and fix this?

What MG version r u on (the version of MG you have installed using the .exe since that’s where the pipeline tool will get run from)?
What machine are you compiling on?
What are the properties of your content-file?

Here are mine:


As you see your code is compiling fine on my setup. (I just copy-pasted it into the file ps_4_0_level_9_1_register.fx.)
I’m using MG v3.6.0.1598.
I’m on a Windows machine.

After reading your message again…
You are absolutely sure that you’ve compiled the right file, since the error message says: Invalid Profile "", Pixes shader 'Pix... where the level you actually declared should be within the quotes, but these are empty in your error message.
So it suggests that the file you compiled looked something like this:
PixelShader = compile vs_4_0_level_9_1 PixelShaderFunction(); or some other invalid string (here it is the declaration for the vertex-shader instead the pixel-shader) instead of that:
PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();
I get your error with that.
But of course it could be a bug in MG.

have you tried using a higher one? It shouldn’t work in theory, but why not

try ps_4_0

According to the paths on my C drive I’m running Monogame 3.0.

I tried updating to the latest Visual Studio Monogame package but that didn’t help. I also started a new project and tried to build the file and it worked - I don’t know what that means, but I guess it leaves open the option of porting everything over :stuck_out_tongue:

Near as I can tell I compiled the right file. Just in case I excluded and re-added the same files, and I also double checked the “ps_4_0_level_9_1” part.

Hmmm. Only explanation I have for that is that maybe you referenced an odd version of the pipeline tool you’ve installed somewhere else in your project file… Maybe cross-check the two project files for differences…
But I’m glad that it works now :slight_smile: