Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Drawing twice and then blending the image

This topic is 5288 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm trying to do something in DirectX 9 but I have some problems doing it.. What I want to do is draw my world, with all the polygons, sky, etc.. After that and before displaying the world to the screen, I want to draw it again, but this time, the world will be slightly different.. So what I want to do is to blend ( 50%/50% ) both world. Does anyone has any idea on how could this be realised? Thanks a lot Btw, I use C++ [edited by - Hedos on May 28, 2004 7:31:04 PM]

Share this post

Link to post
Share on other sites
In my opinion you must do this:

2)setup world matrix view 1
3)call geometry rendering
4)setup world matrix view 2
5)call again geometry rendering
7)m_pd3dDevice->Present( 0, 0, 0, 0 );<-- show the world to the screen

you must use alphablending too... else the second rendering over write the first one..


[edited by - BlueChip on May 28, 2004 7:54:27 PM]

Share this post

Link to post
Share on other sites
But the problem is that, if I set the second drawing to 50% transparency, it will not work correctly since the objects drawn in the second drawing who are behind objects in the first drawing will not be visible..
And also, if I use transparency, it won''t just blend the 2 world, it will also blend the objects between each others into the second world.. :/

Share this post

Link to post
Share on other sites
Original post by Namethatnobodyelsetook
Draw scene to rendertarget 1
Draw scene to rendertarget 2
Blend target 1 and 2 50% as backbuffer.

Thanks a lot
I'm going to search for render targets as I don't know what it is.. if I have any problems I'll post them here

edit: Oh well, I have difficulties finding good informations on Multiple Render Targets.. could you provide a short exemple on how would this be achieved?

[edited by - Hedos on May 28, 2004 9:28:34 PM]

Share this post

Link to post
Share on other sites
You don''t want Multiple Render Targets, as that''s a new DX9 feature for render the scene to multiple surfaces at once. You just want Render Targets.

// Init

// Create two render targets identical to back buffer

// pDev->CreateRenderTarget makes surfaces, but that''s useless

// since you can''t SetTexture a surface...

D3DXCreateTexture(pDev, d3dpp.BackBufferWidth, d3dpp.BackBufferHeight, 1, D3DUSAGE_RENDERTARGET, d3dpp.BackBufferFormat, D3DPOOL_DEFAULT, &pRenderTexture1);
D3DXCreateTexture(pDev, d3dpp.BackBufferWidth, d3dpp.BackBufferHeight, 1, D3DUSAGE_RENDERTARGET, d3dpp.BackBufferFormat, D3DPOOL_DEFAULT, &pRenderTexture2);
// Get surfaces from textures we made, and original backbuffer.

pRenderTexture1->GetSurfaceLevel(0, &pSurface1);
pRenderTexture2->GetSurfaceLevel(0, &pSurface2);
pDev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pOriginalBackBuffer);

// When Rendering

pDev->SetRenderTarget(0, pSurface1);

pDev->SetRenderTarget(0, pSurface2);

pDev->SetRenderTarget(0, pOriginalBackBuffer);
pDev->SetTexture(0, pRenderTexture1);
pDev->SetTexture(1, pRenderTexture2);
// Set renderstates for a 50% blend....

// ....


Share this post

Link to post
Share on other sites
You should be able to get away with this:

Clear() <- clear the back buffer, depth buffer, and stencil buffer(if used)
Setup Camera 0
Turn Off Alpha Blending
Render Stuff
Clear() <- clear only the depth buffer
Setup Camera 1
Turn On Alpha Blending
Render Stuff

Clearing the depth buffer will make sure that everything gets drawn again, just like it was a normal scene with no depth data to get in the way.

I suppose if your scene contains alpha blended stuff, then you won't be able to simply turn on alpha blending for the second pass, and thus this wouldn't work. But if you don't have any alpha blended stuff, it should be fine. (Or maybe I'm just not thinking very well, and it will work regardless. It has been known to happen.)

[edited by - Agony on May 28, 2004 9:59:29 PM]

Share this post

Link to post
Share on other sites
Agony, that works assuming you''ve sorted each poly front to back, which isn''t likely. You''re likely doing a crude object sort, so you''re not in control of which faces of an object are rendered first.

I suppose you could do this though, assuming you have no semi-transparent objects in your scene.

Render first frame
Clear Z
Set ColorWriteEnable to 0
Render second frame(Z only)
Set ColorWriteEnable to ARGB
Set ZWriteEnable to false
Set 50% blend
Render second frame (color only)

Because the second render is done twice, once to lay down Z, and then blending with color it should be fine, again, assuming no alpha blending objects in the scene.

If you have alphablended objects you''re going to need the long method I posted above.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!