Shader is lacking two texture effect parameters in MonoGame

I have a shader which compiles in both XNA 4.0 and MonoGame. I get a NullPointerException when trying to set two effectParameters which both target texture (the effectParameters are null). I debugged the shaders in XNA and MonoGame and in XNA there are 33 Parameters and in MonoGame 31. So the parameters don’t make it in the compiled shader in MonoGame. Is this a known bug? How to fix this?

first… sorry cuz my bad english

2mgfx will ignore [declared parameters but not used in any function…]

Most likely PumpkinPudding pointed you in the right direction. With xna you could declare textures and samplers in an fx without using them, setting these params in c#.
With mgfx, if these values (it seems it concerbs only textures) are not use in the path of the shader’s computation (even if you call tex2d on it but this value is not used anywhere before the return and not in the return) you wont be able to see it in c#
Try outputting the effect parameters in the console to see if they are there, or a blank fx and add texture and a tex2d call in the return, test, and move it after the retur’, you will understand :wink:

This is mentioned in the documentation here

The effect compiler is aggressive about removing unused paramters, be sure the parameters you are setting are actually used.

Parameters will be optimised out if you don’t use them.

Thank you guys, this is the solution. Although i used some of the texture effect parameters in the shader, they did not influence the return value. So they were “optimized” (removed) during compilation.

1 Like