   Drawing twice and then blending the image
  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 lotBtw, I use C++[edited by - Hedos on May 28, 2004 7:31:04 PM]
  In my opinion you must do this:1)m_pd3dDevice->BeginScene()2)setup world matrix view 13)call geometry rendering4)setup world matrix view 25)call again geometry rendering6)m_pd3dDevice->EndScene(); 7)m_pd3dDevice->Present( 0, 0, 0, 0 );<-- show the world to the screenyou must use alphablending too... else the second rendering over write the first one..byez [edited by - BlueChip on May 28, 2004 7:54:27 PM];  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.. :/ ;  Draw scene to rendertarget 1Draw scene to rendertarget 2Blend target 1 and 2 50% as backbuffer.;quote:Original post by Namethatnobodyelsetook   Draw scene to rendertarget 1Draw scene to rendertarget 2Blend 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 hereedit: Oh well, I have difficulties finding good informations on Multiple Render Targets.. could you provide a short exemple on how would this be achieved?Thanks   [edited by - Hedos on May 28, 2004 9:28:34 PM];  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 RenderingUpdate();pDev->SetRenderTarget(0, pSurface1);pDev->Clear(...);DrawScene();Update();pDev->SetRenderTarget(0, pSurface2);pDev->Clear(...);DrawScene();pDev->SetRenderTarget(0, pOriginalBackBuffer);pDev->SetTexture(0, pRenderTexture1);pDev->SetTexture(1, pRenderTexture2);// Set renderstates for a 50% blend....// ....RenderQuad();pDev->Present();;  You should be able to get away with this:BeginScene()Clear()  <- clear the back buffer, depth buffer, and stencil buffer(if used)Setup Camera 0Turn Off Alpha BlendingRender StuffClear()  <- clear only the depth bufferSetup Camera 1Turn On Alpha BlendingRender StuffEndScene()Present()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];  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.ClearRender first frameClear ZSet ColorWriteEnable to 0Render second frame(Z only)Set ColorWriteEnable to ARGBSet ZWriteEnable to falseSet 50% blendRender 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. ;  Thanks a lot guys, it looks like to be exactly what I''m looking for 