Jump to content

  • Log In with Google      Sign In   
  • Create Account

Blending a texture onto the render target with StretchRect


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 davepl1968   Members   -  Reputation: 166

Like
0Likes
Like

Posted 30 August 2013 - 12:48 PM

I have a scene that I render to a texture (works fine).  I keep a copy of that texture, which I use to create a blur in the X and Y direction so now I have:

 

a) The original texture of the scene

b) A blurred copy of the scene on the device's default rendertarget

 

I now want to draw the original texture on top, giving it the "blur" around the original scene data.  When I do this, however, it just completely replaces everything; my blurred scene is wiped out and the original replaces it entirely, as if StretchRect can do no combining or blending.

 

I turn on Alpha blending and set the blending mode to Additive (also tried AlphaAdditive):

pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
BlendMode::Set(pd3dDevice, BlendMode::Additive);
pd3dDevice->StretchRect(ptrDrawSurface, NULL, ptrOriginalDeviceRenderTarget, NULL, D3DTEXF_POINT);

So what am I missing?  How do I get the original version of the scene to be placed on top of the blurred version of the scene without it just completely replacing it?

 

Thanks!

 

 



Sponsor:

#2 DwarvesH   Members   -  Reputation: 471

Like
0Likes
Like

Posted 30 August 2013 - 02:14 PM

Render targets have two modes of operation: preserve and discard. They are usually created in discard mode for performance reasons. When this is true, the content of the render target is not longer available after you resolve it (i.e. use it as a texture). You could try and switch to render targets in preserve mode, but like I said, there is a performance overhead. Even worse, since you will actually read back the preserved render target and blend. I believe it also consumes more VRam.

 

What you are describing looks like a bloom like shader. You could create a shader and use a full screen quad to achieve your desired effect. This shader would take two sampler inputs: the original scene and the blurred scene. You would do the blending yourself in the pixel shader. Basically your entire pixel shader would be just (in pseudo-code): return blend(texture1, texture2);. 



#3 davepl1968   Members   -  Reputation: 166

Like
0Likes
Like

Posted 30 August 2013 - 02:15 PM

Thanks, that's what I've been working on since I posted it (a 'Combine' shader that takes the two blur stages and combines their outputs to the screen).  I'm not familiar with the blend() function, so thanks!  I had just been adding them with a scale factor.


Edited by davepl1968, 30 August 2013 - 02:16 PM.


#4 SimmerD   Crossbones+   -  Reputation: 1102

Like
0Likes
Like

Posted 30 August 2013 - 03:17 PM

Discard only applies after Present() or PresentEx(), not if you copy the back buffer into a rendertarget.

 

Stretch rect only does a filtered copy, not blending. You will need to write a shader or draw alpha blended quads with the screen buffer applied with DrawPrimitive().






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS