Post-processing effect questions

Started by
1 comment, last by george7378 9 years, 4 months ago

Hi everyone,

I've been using a sprite to do post-processing effects for a while now, but I'm having a few issues with it recently. Here is my code for drawing to the screen using post-processing:


bool draw_Processed_Texture(D3DXHANDLE technique, DrawableTex2D screen_texture)
{
if (FAILED(screenSprite->Begin(D3DXSPRITE_DO_NOT_ADDREF_TEXTURE | D3DXSPRITE_SORT_TEXTURE))){return false;}
 
globalEffect->SetValue("i_TextureWidth", &WIDTH, sizeof(unsigned));
globalEffect->SetValue("i_TextureHeight", &HEIGHT, sizeof(unsigned));
 
globalEffect->SetTexture("t_ScreenTexture", screen_texture.drawTexture);
 
globalEffect->SetTechnique(technique);
UINT numPasses = 0;
if (FAILED(globalEffect->Begin(&numPasses, 0))){return false;}
for (UINT i = 0; i < numPasses; i++)
{
if (FAILED(globalEffect->BeginPass(i))){return false;}
screenSprite->Draw(screen_texture.drawTexture, NULL, NULL, NULL, D3DCOLOR_ARGB(255, 255, 255, 255));
if (FAILED(screenSprite->End())){return false;}
if (FAILED(globalEffect->EndPass())){return false;}
}
if (FAILED(globalEffect->End())){return false;}
 
return true;
}
Is this the right way to go about doing it? Do I have my calls in the correct order? Also, in the screenSprite->Draw() function I have specified the texture (screen_texture.drawTexture) again. Since I've already sent it to the shader to be sampled, do I need to put it in the sprite draw call too?
Thanks!
Advertisement
ID3DXSprite only issues a draw call when calling End() or Flush(). So the whole Begin(), Draw(), End() triple should be within that pass. I'm also not quite sure you actually can use it with custom shaders, at least call it with D3DXSPRITE_DONOTMODIFY_RENDERSTATE also.

If that fails, setup your own vertices and draw call. Make sure you don't forget the half-pixel offset needed for correct sampling.

Thanks for the help. It's interesting because I've been using the above for things like gaussian blurs, greyscale rendering, etc... and as far as I can tell it actually works if all I do is apply a pixel shader, but the thing is, I can't remember exactly where I came across this method so I was beginning to question whether it's valid or not!

This topic is closed to new replies.

Advertisement