views:

206

answers:

1

Dear all,

Is it possible to use a pixel shader inside a sprite?

I have create a simple pixel shader, that just writes red color, for testing. I have surrounded my Sprite.DrawImage(tex,...) call by the effect.Begin(...), BeginPass(0), and EndPass(), End(), but my shader seems not to be used : My texture is drawn just normally.

A: 

I am not sure what language you are using. I will assume this is an XNA question.

Is it possible to use a pixel shader inside a sprite?

Yes, you can load a shader file (HLSL, up to and including shader model 3 in XNA) and call spritebatch with using it.

If you post sample code it would be easier for us to see if anything isn't setup properly. However, It looks like you have things in the right order. I would check the shader code.

Your application code should look something like this:

Effect effect; 
effect = Content.Load<Effect> ("customeffect"); //load "customeffect.fx"
effect.CurrentTechnique = effect.Techniques["customtechnique"];

effect.Begin();

foreach (EffectPass pass in effect.CurrentTechnique.Passes)
 {
     pass.Begin();

     spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);

     spriteBatch.Draw(texture, Vector2.Zero, null, Color.White, 0, new Vector2(20, 20), 1, SpriteEffects.None, 0);

     spriteBatch.End();

     pass.End();
 }

 effect.End();
Arriu
Thanx for your reply,but i am using Managed DirectX, so it is possible to use in MDX?
Firoz
Yes, don't see any reason it shouldn't. Why not just try it?
Cecil Has a Name