Sign in to follow this  
rkennedy9064

ID3DXSPRITE effects

Recommended Posts

I've been continuing to mess around with DirectX 9 and have run into a sticking point. Is it possible to use effect files with the ID3DXSPRITE interface? If so, does anyone have any resources on how this is possible. I've been looking online and have seen that you need to load an effect file and then select the technique and begin going through the different passes, but all of these examples are using 3D space and passing matrices and multiplying these together. I thought that ID3DXSPRITE pretransformed everything, so I'm just wondering if and how it would be possible to add effects to sprites through this interface. Any help would be greatly appreciated. So far my code looks something like this (not sure if this is the correct way to do this, if it is does anyone have an example of what would go in the effect file?)

[font="Consolas"][size="2"][font="Consolas"][size="2"]Game->GetSpriteBatch()->Begin(BlendMode::AlphaBlend);
LPD3DXEFFECT effect = Game->GetEffect();
effect->SetTechnique([/size][/font][/size][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"FirstTechnique"[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]);
effect->Begin(NULL, NULL);
Game->GetSpriteBatch()->Draw([/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]this[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]->background, D3DXCOLOR(1,1,1,1));
Game->GetSpriteBatch()->Draw([/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]this[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]->startButton, D3DXCOLOR(1,1,1,1));
effect->EndPass();
effect->End();
Game->GetSpriteBatch()->End();

[/size][/font][/size][/font]

Share this post


Link to post
Share on other sites
This might help you, or atleast give you a starting point:
[url="http://archive.gamedev.net/community/forums/topic.asp?topic_id=525531&whichpage=1&#3406912"]http://archive.gamedev.net/community/forums/topic.asp?topic_id=525531&whichpage=1&#3406912[/url]

Good luck.

Share this post


Link to post
Share on other sites
Ok I've managed to get a simple pixel shader to work for ID3DXSPRITE, but now I have a couple questions about it. This is the code I've come up with so far.
[font="Consolas"][size="2"][font="Consolas"][size="2"]Game->GetSpriteBatch()->Begin(BlendMode::AlphaBlend);
LPD3DXEFFECT effect = Game->GetEffects()[[/size][/font][/size][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"effect.fx"[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]];
effect->SetTechnique([/size][/font][/size][/font][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"][font="Consolas"][size="2"][color="#a31515"]"PostProcess"[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]);
effect->Begin(NULL, NULL);
effect->BeginPass(0);
Game->GetSpriteBatch()->Draw([/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]this[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]->startButton, D3DXCOLOR(1,1,1,1));
Game->GetSpriteBatch()->GetSprite()->Flush();
effect->EndPass();
effect->End();

And my HLSL file
texture screenShot;[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]sampler2D sample = sampler_state
{
Texture = (screenShot);
mipfilter = LINEAR;
};[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]float4 MyShader( float2 Tex : TEXCOORD0 ) : COLOR0
{
float4 Color;
Color = tex2D( sample, Tex.xy) * 15;
return Color;
}[/size][/font][/size][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]technique PostProcess
{
pass Pass0
{
VertexShader = null;
PixelShader = compile ps_2_0 MyShader();
}
}

My questions were,
1. If I were to use multiple passes, would I need to flush the ID3DXSPRITE after each pass or would I do all of the passes and then flush the sprite to draw it to the screen?
2. In the HLSL file, is the texture coming from a sampler state the the ID3DXSPRITE sets when I call it's begin mode?
3. My final question is about a vertex shader. From what I've read you can't apply a vertex shader on an ID3DXSPRITE because it hase pre-transformed vertices. Will this limit the types of effects I can apply to my textures, and also, if I render using D3DXSPRITE_OBJECTSPACE, does that make the vertices not pre-transformed anymore, allowing me to apply a vertex shader?

Any information would be greatly appreciated.

[/size][/font][/size][/font]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this