I am trying to learn how to use Shaders for a 2D XNA project I am working on. To test them out, I was trying to make a white triangle become colored using a super simple Pixel Shader, and I can't get it to work.

float4 ThePixelShader(float4 texCoord : TEXCOORD0) : COLOR0
{
return(125,15,105,1);
}

technique MandelbrotSet
{
pass Pass0
{
}
}


And this is the code I was using to draw my Plain white triangle onto the screen, and trying to use the shader to change its color.

        GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
//MandelbrotEffect.Parameters[""].SetValue();
MandelbrotEffect.CurrentTechnique = MandelbrotEffect.Techniques["MandelbrotSet"];
foreach (EffectPass pass in MandelbrotEffect.CurrentTechnique.Passes)
{
pass.Apply();
spriteBatch.Draw(Dot, new Rectangle(10, 10, 200, 200), Color.White);
}
spriteBatch.End();


I'm guessing I am doing something dumb, but I can't figure out what. The triangle is drawn on screen as just a plain white triangle, what it would look like without a shader.

EDIT: Changed my drawing code to look like this.

        GraphicsDevice.Clear(Color.Black);
//MandelbrotEffect.Parameters[""].SetValue();
MandelbrotEffect.CurrentTechnique = MandelbrotEffect.Techniques["MandelbrotSet"];
spriteBatch.Begin(0, BlendState.Opaque, null, null, null, MandelbrotEffect);
spriteBatch.Draw(blank, Vector2.Zero, Color.White);
spriteBatch.End();


Now it does draws the box fullscreen, and I know the shader is working because changing the Alpha value does change the Alpha value of the full screen image, but still the colors don't change.

Thoughts?

After your edit it is unclear exactly what code you are using.

Replace the code in your question with the code that you are using (for example, we don't know what "the drawing part" is, since all of this code is "the drawing part").

The following code is all you need to draw a quad with the effect as desired:

GraphicsDevice.Clear(Color.Black);
MandelbrotEffect.CurrentTechnique = MandelbrotEffect.Techniques["MandelbrotSet"];
MandelbrotEffect.CurrentTechnique.Passes[0].Apply();
spriteBatch.Begin(0, BlendState.Opaque, null, null, null, MandelbrotEffect);
spriteBatch.Draw(blank, Vector2.Zero, Color.White);
spriteBatch.End();

• Your right, your code works great. It turns out my Shader was messed up, and then I edited my XNA code, then fixed the shader, but didn't know for a while because my XNA code was all over the place. I've got it fixed now. Thanks. – Woody Zantzinger May 3 '11 at 2:09

Direct3D colours are RGBA, which means you're passing 0 for the Alpha component, which is totally transparent.

• I fixed that, and still just get the white square. If that had been the problem, wouldn't I have not seen a square? – Woody Zantzinger May 1 '11 at 20:33