开发者

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

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.


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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜