Default shader won't work

I’ve been tearing my hair out with trying to get shaders working in my game. I created a new .fx shader using the Monogame Pipeline tool, but even leaving it in its default state it won’t work with my game. It’s loading in, but all it does is cause a blank screen.

I load it in with Effect effect = game.Content.Load(@“shaders/Test”);

And then I implement it like this:

spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, effect, screenShakeMatrix);

It’s actually a render target that I am drawing to the screen buffer, but I’ve tried it when I’ve been drawing to the render target with the same outcome. Any help would be greatly appreciated!

The content of the shader (Test.fx) is:

#if OPENGL
	#define SV_POSITION POSITION
	#define VS_SHADERMODEL vs_3_0
	#define PS_SHADERMODEL ps_3_0
#else
	#define VS_SHADERMODEL vs_4_0_level_9_1
	#define PS_SHADERMODEL ps_4_0_level_9_1
#endif

matrix WorldViewProjection;

struct VertexShaderInput
{
	float4 Position : POSITION0;
	float4 Color : COLOR0;
};

struct VertexShaderOutput
{
	float4 Position : SV_POSITION;
	float4 Color : COLOR0;
};

VertexShaderOutput MainVS(in VertexShaderInput input)
{
	VertexShaderOutput output = (VertexShaderOutput)0;

	output.Position = mul(input.Position, WorldViewProjection);
	output.Color = input.Color;

	return output;
}

float4 MainPS(VertexShaderOutput input) : COLOR
{
	return input.Color;
}

technique BasicColorDrawing
{
	pass P0
	{
		VertexShader = compile VS_SHADERMODEL MainVS();
		PixelShader = compile PS_SHADERMODEL MainPS();
	}
};

Just a thought, try a different name?

You mean instead of “effect”? I tried that. Didn’t work :frowning:

I’ve tried making the simplest possible shader in the hope that I can get to the bottom of this, but still it just creates a blanks screen.

sampler inputTexture;

float4 MainPS(float2 textureCoordinates: TEXCOORD0): COLOR0
{
	float4 color = tex2D(inputTexture, textureCoordinates);
	return color;
}

technique Techninque1
{
	pass Pass1
	{
		PixelShader = compile ps_4_0_level_9_1 MainPS();
		AlphaBlendEnable = TRUE;
		DestBlend = INVSRCALPHA;
		SrcBlend = SRCALPHA;
	}
};

Try this one all the instructions are there.
I put the full copy paste code at the bottom with notes.

Then this one.

There is lots of examples if you search on the forum of working shaders.

1 Like

Consider trying the simplest drawing code.
What is screenShakeMatrix? Perhaps you translate things offscreen or scale them down to zero?

Thanks so much! The first of your suggestions worked!