shaders on sprites

Started by
3 comments, last by 999999999 18 years, 6 months ago
Hi, I am writing a directx engine and I would like to use ID3DXSprite to draw 2d images. My problem is: Can I use vertex/pixel shaders on sprites, for example, doesn't Direct3D draw sprites as textured quads? So, I have tried this but the shaders seem not to work:

shaderMGR->ActivateShader(spriteShader);
sprite->Draw(230,10);
shaderMGR->DeactivateShader();
I thought Direct3D used ordinary draw primitive calls to draw texture quads, so why can't I use shaders just how I use them with my DrawPrimitive calls? Thanks,999999999
Advertisement
I did read something about this a while back, but I'm not a 100% sure.

ID3DXSprite's implementation will make sure that the device is in the state that it requires in order to operate correctly, and "undo" any changes when it's finished rendering. Whether it specifically uses state-blocks or not I don't know, but it'd be functionally similar.

Provided that assertion is correct, then your calling SetVertexShader() and/or SetPixelShader() will be ignored by the sprite implementation...

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

The sprites are NOT drawn when you call sprite->Draw(...)
When you draw sprites, you call Begin(...), then Draw(...) (it adds a sprite to the list of sprites) and then, End(...) which is the method that actually draw the quads on screen.

Edit : For the renderstates, I just checked in the SDK, and they write the renderstates that are modified by the call to Begin(). It doesn't seem like they modify the shaders. Only basic render states, sampler states.
Anyway, you can use D3DXSPRITE_DONOTMODIFY_RENDERSTATE in the Begin(...) method to not modify the renderstates (in which case, you have to set them yourself before calling End(...) ^^
The thread I was thinking about is this one from the official MSDN/WGGT forums. It doesn't seem to have a particularly clear answer though [oh]

Quote:if you want to use Effects, I recommend you build the vertex buffer yourself. You could draw D3DX sprites within an Effect block, but the vertices might not come as you would expect them to. It would certainly be easier to just deal with the vertex data yourself.


The above quote is the response from one of the Microsoft developers, which doesn't say you *CANT* use pixel shaders and sprites, but it doesn't seem to be the advised tactic either...

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Thanks guys. I have found the way it works: you have to call ActivateShader() after sprite->Begin() and before sprite->Draw(). D3DXSPRITE_DONOTMODIFY_RENDERSTATE doesn't work.

Thanks.

This topic is closed to new replies.

Advertisement