Quote:Original post by chub
By the way your program only runs at about 2 fps on my machine, so maybe you have some optimising to do?
Yea, it ran very slowly on both of my machines as well, so it may be something you want to look into.
Quote:Original post by chub
By the way your program only runs at about 2 fps on my machine, so maybe you have some optimising to do?
Quote:
Original post by chub
By the way your program only runs at about 2 fps on my machine, so maybe you have some optimising to do?
Quote:Original post by Adriano
WHY???
Quote:Something weird is going on here and I can't realize what.
I've already lost a lot of time and still haven't resolved anything
friend void RenderPasses(CD3DManager* pD3D, CD3DDevice* pDevice, CCamera* pCamera, ONFRAMERENDER_METHOD* pRenderMethod, void* pRenderContext, D3DCOLOR backgroundColor = 0x0){ // Reset ambient light pDevice->pD3Ddevice->SetRenderState(D3DRS_AMBIENT, 0x0); // Reset active lights for this device, in order to add only // the ones needed for rendering the scene for (UINT i = 0; i < pDevice->activeLightsCount; i++) pDevice->pD3Ddevice->LightEnable( i, FALSE ); pDevice->activeLightsCount = 0; // See if to render shadows and set rendering passes if (pD3D->renderShadows) { pDevice->renderShadows = true; pD3D->renderPassesCount = max(2, pD3D->renderPassesCount); // Z-Fill and ambient pass on first pass // Turn OFF color buffer pDevice->pD3Ddevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); // Turn ON lighting, turn OFF ambient light by default pDevice->pD3Ddevice->SetRenderState(D3DRS_LIGHTING, TRUE); // Turn ON depth buffer pDevice->pD3Ddevice->SetRenderState(D3DRS_ZENABLE, TRUE); pDevice->pD3Ddevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE); // Turn OFF stencil buffer pDevice->pD3Ddevice->SetRenderState(D3DRS_STENCILENABLE, FALSE); } else // Default to stencil buffer OFF when not rendering shadows pDevice->pD3Ddevice->SetRenderState(D3DRS_STENCILENABLE, FALSE); // Clear the backbuffer and the zbuffer pDevice->pD3Ddevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, backgroundColor, 1.0f, 0); if(SUCCEEDED(pDevice->pD3Ddevice->BeginScene())) { // Call Render method if (pRenderMethod != NULL) for (UINT i = 0; i < pD3D->renderPassesCount; i++) { // Apply rendering camera pCamera->Render(*pDevice); // Clear stencil buffer pDevice->pD3Ddevice->Clear(0, NULL, D3DCLEAR_STENCIL, D3DCOLOR_XRGB(0,0,0), 1.0f, 0); // Render pDevice->renderPassNumber = i; pRenderMethod(*pDevice, *pCamera, pD3D->Time, pD3D->elapsedTime, pRenderContext); } } // End the scene pDevice->pD3Ddevice->EndScene();};
void OnFrameRender(CD3DDevice& device, CCamera camera, double time, float elapsedTime, void* pContext){ device.pD3Ddevice->SetRenderState(D3DRS_AMBIENT, 0x007A7A7A); // Render shadows and light if (device.GetRenderPassNumber() == 1) { shadow.Render(); light.Render(); } // Render meshes meshes[0].Render(); meshes[1].Render(); world.Render();}
// CShadow::Rendervoid Render (CD3DDevice dev, CCamera camera, DWORD ambientShadow) throw (HResultException){ // Shadow rendering occurs only from second pass if (dev.renderShadows && dev.renderPassNumber >= 1) { HRESULT hr; // Choose technique for shadow rendering if (update) { } // Turn OFF depth buffer writing dev.pD3Ddevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); // Turn ON colour buffer dev.pD3Ddevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ); dev.pD3Ddevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ZERO ); dev.pD3Ddevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE ); // Turn OFF lighting dev.pD3Ddevice->SetRenderState(D3DRS_LIGHTING, FALSE); // Turn ON stencil buffer dev.pD3Ddevice->SetRenderState(D3DRS_STENCILENABLE, TRUE); dev.pD3Ddevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); dev.pD3Ddevice->SetRenderState(D3DRS_CCW_STENCILFUNC, D3DCMP_ALWAYS); dev.pD3Ddevice->SetRenderState(D3DRS_STENCILMASK, 0xffffffff); dev.pD3Ddevice->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff); // Render volume shadow D3DXMATRIX cameraWorld; D3DXMatrixIdentity (&cameraWorld); // OPTIMISED: use support for 2-sided stencil if (dev.D3DCaps.StencilCaps & D3DSTENCILCAPS_TWOSIDED) { // Radeon 9000 use single sided stencil } else { // USE THE TRADITIONAL 2-PASS METHOD if (depthpass) { // Configure the necessary render states dev.pD3Ddevice->SetRenderState(D3DRS_STENCILREF, 0x1); dev.pD3Ddevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP); dev.pD3Ddevice->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP); // Set stencil to increment dev.pD3Ddevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_INCR); // Render front faces ... // Set stencil to decrement dev.pD3Ddevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_DECR); // Render back faces ... // Reset any necessary states dev.pD3Ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); // Alter stencil buffer dev.pD3Ddevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_GREATER); dev.pD3Ddevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP); } else if (depthfail) { // Carmack's reverse. // Configure the necessary render states dev.pD3Ddevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP ); // Draw back sides, doing nothing with depth pass and incrementing with depth // fail. // Set stencil to increment dev.pD3Ddevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_INCR); // Render back faces ... // Draw front sides, doing nothing with depth pass and decrementing with depth // fail. // Set stencil to decrement dev.pD3Ddevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_DECR); // Render front faces ... // Alter stencil buffer dev.pD3Ddevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_GREATER); dev.pD3Ddevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP); } } // Turn ON ambient light dev.pD3Ddevice->SetRenderState(D3DRS_AMBIENT, ambientShadow); // Set color buffer dev.pD3Ddevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); if (dev.D3DCaps.DestBlendCaps & D3DPBLENDCAPS_SRCCOLOR) dev.pD3Ddevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR); else dev.pD3Ddevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); }}
// CLight::Rendervoid Render(CD3DDevice& dev, D3DMATERIAL9 material) throw(InvalidOperationException){ // SHADOWS // Render a light for each pass, beginning from second pass if (dev.renderShadows && dev.renderPassNumber >= 1) { dev.pD3Ddevice->SetMaterial(&material); dev.pD3Ddevice->SetLight(dev.activeLightsCount, &light); // Turn ON current light, turn OFF previously used one dev.pD3Ddevice->LightEnable(dev.activeLightsCount, enabled); if(dev.activeLightsCount > 1) dev.pD3Ddevice->LightEnable(dev.activeLightsCount-1,false); dev.pD3Ddevice->SetRenderState(D3DRS_LIGHTING, TRUE); // Increment active lights only if this one is enabled if (enabled) dev.activeLightsCount++; }}