XNA Effect port not working

Hi,

There is this GaussianBlur Effect :
http://www.dhpoware.com/demos/xnaGaussianBlur.html

It works really well in the provided XNA sample, but as soon as i try to
port it to monogame this happens when i activate the effect:


(instead of the blurred image i just get a colored Rectangle)

I really need this effect, please help :frowning:

Edit: The only change i’ve made is chaning

PixelShader = compile ps_2_0 PS_GaussianBlur();

to

PixelShader = compile ps_4_0 PS_GaussianBlur();

… does this have any effect?

Edit2: This seems to apply to any shader i try

Edit3: Okay, just wrote the most simple Pixel shader, thats just gets the color and returns it as it is. Still not working. My guess is that the TEXCOORD0 is not working, and always returns the first pixel

Sorry for the doublepost, but still waiting for an answer here. Creating a game without effects would be pretty strange :frowning:

Even if you can’t help, please give me informations like if the example works on your system and stuff

I know almost nothing about shaders but I will try to help.
Can you show your code? (How you begin your spriteBatch how you apply your effect and how your .fx file looks like).

Hi, thanks for trying to help!
My code is really complicated atm, but please try to create a basic effect in Monogame (current version, no opengl) and check if it works! (it doesn’t here)

Of course effects are working in Monogame.
In my current project I use a simple effect and it is working fine.

Sounds like you are not exactly matching the output of the vertex shader to the inputs of the pixel shader. The pixel shader inputs must match exactly… even parameters you do not use in the pixel shader.

Be sure to read the effect writing tips in the docs too…

http://www.monogame.net/documentation/?page=Custom_Effects

@thecrow34: Could you be so kind and upload me a simple Test game? Woudl be super awesome
@Tom: I’m don’t have any experience in shader programming - but I do not use a vertex shader so i just use float2 coords: TEXCOORD0 as pixel shader function parameter

I think i’m doing something very basic wrong here. If someone could upload a DirectX sample i would really appreciate it!

Yes… the basic thing you are missing is that there is always a vertex shader. In this case I assume you are rendering with SpriteBatch. When you provide SpriteBatch with a custom effect with only a pixel shader, the vertex shader from the stock SpriteBatch effect is used.

You can see here how the pixel shader for the stock SpriteBatch effect is defined:

https://github.com/mono/MonoGame/blob/develop/MonoGame.Framework/Graphics/Effect/Resources/SpriteEffect.fx#L41

… you can see how it takes a position a color and a tex coord. You need your pixel shader signature to look something like that:

float4 MyPixelShader( float4 position : SV_Position, 
                                    float4 color : COLOR0, 
                                    float2 texCoord : TEXCOORD0)
{
1 Like

Thanks!

This is how my effect looks now:

float4 MyPixelShader( float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
    return float4(color.r,color.g,color.b,1);
}


technique PostProcess
{
    pass P0
    {
        PixelShader = compile ps_4_0_level_9_1 MyPixelShader();
    }
} 

→ should just display the image. I’m getting a grey rectangle instead :confused: (just like in the old one, see first post)

How i use the effect:

                    spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
                    effect.CurrentTechnique.Passes[0].Apply();
                    spriteBatch.Draw(...);
                    spriteBatch.End();

Edit: Ok, now it doesn’t work at all. i guess i’ll just go to sleep, if someone could upload a simple, working sample with any effect that would be super nice.

Are you using the latest development build? There was a bug introduced a few days ago that might be causing that. See Fix logic for applying texture effect parameters by tgjones · Pull Request #3554 · MonoGame/MonoGame · GitHub.

1 Like

IT WORKS!!
Thanks for helping guys!

1 Like

I ran into this issue, too.

Make sure the pixel shaders inputs exactly match the vertex shader
outputs so the parameters are passed in the correct registers.

It think it would help a lot to have a compiler warning when this happens - especially for people porting from XNA where these shaders used to work.

I’m new to the community, so I’m not sure if I should create an issue for this.

1 Like

Please do! It is the best way to get feature requests to us.

Done: https://github.com/mono/MonoGame/issues/4721

1 Like