English 中文(简体)
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();
问题回答

暂无回答




相关问题
Prerequisite for learning directx

I am from .net C# background and I want to learn DirectX. I have knowledge of C++ but I am fairly new to graphic world. I am little confused about how to start learning directx, should I start ...

How to programmatically disable the auto-focus of a webcam?

I am trying to do computer vision using a webcam (the model is Hercules Dualpix). I know it is not the ideal camera to use, but I have no choice here. The problem is the auto-focus makes it hard/...

Making an object orbit a fixed point in directx?

I am trying to make a very simple object rotate around a fixed point in 3dspace. Basically my object is created from a single D3DXVECTOR3, which indicates the current position of the object, ...

3d Alternative for D3DXSPRITE for billboarding

I am looking to billboard a sun image in my 3d world (directx 9). Creating a D3DXSPRITE is great in some cases, but it is only a 2d object and can not exist in my "world" as a 3d object. What is ...

热门标签