2
votes


I am currently learning the language "HLSL" for effect files to my XNA game. However; I have ran into the issue of applying the effects to my SpriteBatch.

My effect file looks like this, and makes the rendered texture, white. :]

float4 PSFunction(float2 coord : TEXCOORD0) : COLOR0
{
    return float4(0, 0, 0, 1); // Return a white pixel
}

technique Sample
{
    pass pass0
    {
        PixelShader = compile ps_2_0 PSFunction();
    }
}

It is working as it should, when I begin my SpriteBatch with following arguments:

SpriteBatch.Begin(0, null, null, null, null, SampleEffect);

However; the SpriteBatch.Begin method does not accept multiple effects. Therefore I tried to do

SampleEffect.CurrentTechnique.Passes[0].Apply();

before calling

SpriteBatch.Begin();

But nothing happend, therefore I tried couple of diffrend methods. Such as

SampleEffect.CurrentTechnique.Passes["pass0"].Apply();

But it still did not work. So I verified the effect was attached to the correct GraphicsDevice using the object.ReferenceEquals function, but it was equaled to the correct graphicsDevice. What am I doing wrong? How would I attach multiple effects to my SpriteBatch?

Thanks in Advance, Rasmus :]

1

1 Answers

3
votes

You can't draw with multiple effect passes simultaneously. Instead, you need to draw the same thing multiple times, combining the results together.

As an example of this, imagine simulating lighting with 3 effects: ambient light, diffuse light, and specular light. Each of these would be represented by an effect pass. You would render them in order, additively combining the results together (just like light adds together).

If you want to combine several effects, you need to manually specify how they are to combine. You would usually do this by looping through the effect passes you want to use, and applying them one at a time, drawing your scene at each iteration.