Binding Parameters to custom effect

I’m writing a custom effect which applies in SpriteBatch. I have got it all running, drawing the input texture given along with the call, however there seems to be a problem when you want to provide arguments other than the standard registered SpriteEffect arguments.

For example, my shader:

#include "Shading.fxh"

sampler s0;

float4 PixelShaderFunction(
float4 position : SV_Position, 
float4 color : COLOR0, 
float2 TexCoordsUV : TEXCOORD0) : COLOR0
   float4 input = tex2D(s0, TexCoordsUV);
   return input + float4(, 1.0f);

In which the float3 LightColor is defined in Shading.fxh. I have no problem binding it from C#, all the parameters exist. The draw call merely returns a black color where it should be white though. (The LightColor should be (1,1,1), it is not)

I have read another discussion which had a similar problem with a Texture binding, do these problems relate?

What does the definition of float3 LightColor look like? Are you maybe not setting it from C# and instead just giving it a default value from HLSL?

That in particular does not work on OpenGL platforms.

In Shading.fxh:

float4 LightColor;

Which is set from C#:


And it is made to function as DirectX application


If you just do…

return float4(, 1.0f);

Does it return white or does it fail? This can help narrow your debugging down to being an issue with LightColor or an issue with the texture.

I have already tried that, It just returned black as if the LightColor was never set in the shader, so outputting black as result. If I return:

return float4(1,1,1,1);

It draws a white square as promised

When are you calling Parameters["LightColor"].SetValue()? What does the SpriteBatch call look like?

Ah, that solves it.

I had two copies of the effect running:

spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, null, null, null, e, Global.Map.Camera.ViewMatrix);
// e is the effect being applied.
// After which another copy of this effect is instanced at the Light draw:

These effects were however the same shared resource, but I guess they were separate copies anyway. Thanks for your time though!