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:

	#define VS_SHADERMODEL vs_3_0
	#define PS_SHADERMODEL ps_3_0
	#define VS_SHADERMODEL vs_4_0_level_9_1
	#define PS_SHADERMODEL ps_4_0_level_9_1

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;
1 Like

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.


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!

i put up a project in case people wanna barebones test rig to share basic common use shaders for 2d Vector with zoom or fixed camera :

its all sooooooo touchy and weird. but i got clipping/ masking or whatever blending to work on desktopGL and DX… i draw the mask not the texture. the mask is white. however with rendertarget it still fails only on GL, blank…ill try to update the sample maybe its something wrong in my other code. what im doign is converting the game stuff to sprites, clipped with Mip maps so when i zoom out its looks as nice as silverlight/ wpf did, and when items with textures on them are cut in but the physics those textures need to get clipped to the polygon they are stuck to… took me an hour on silverlight wpf… this is day 11. I though id isolate , modernize and share this test rig cause even if painful its 10x faster than when i used retained mode graphics i get like 2000 fps not 100 so i should be worth it someday. I know there are blend modes and stencils and the like but tried all that and basically hacking blind.