void CTourist::MoveToward(const float fElapsedTime) { D3DXVECTOR3 vTrans(0, 0, m_fSpeed*fElapsedTime); D3DXVec3TransformNormal(&vTrans, &vTrans, &m_mOrientation); m_vPos += vTrans; //平移调整物体世界坐标方向矩阵 D3DXMATRIX mTrans; D3DXMatrixTranslation(&mTrans, vTrans.x, vTrans.y, vTrans.z); D3DXMatrixMultiply(&m_mOrientation, &m_mOrientation, &mTrans); }
void LUMod ( ElementalMatrix<F>& APre, DistPermutation& P, const ElementalMatrix<F>& u, const ElementalMatrix<F>& v, bool conjugate, Base<F> tau ) { DEBUG_CSE const Grid& g = APre.Grid(); typedef Base<F> Real; DistMatrixReadWriteProxy<F,F,MC,MR> AProx( APre ); auto& A = AProx.Get(); const Int m = A.Height(); const Int n = A.Width(); const Int minDim = Min(m,n); if( minDim != m ) LogicError("It is assumed that height(A) <= width(A)"); if( u.Height() != m || u.Width() != 1 ) LogicError("u is expected to be a conforming column vector"); if( v.Height() != n || v.Width() != 1 ) LogicError("v is expected to be a conforming column vector"); AssertSameGrids( A, u, v ); // w := inv(L) P u // TODO: Consider locally maintaining all of w to avoid unnecessarily // broadcasting at every iteration. DistMatrix<F> w( u ); P.PermuteRows( w ); Trsv( LOWER, NORMAL, UNIT, A, w ); // Maintain an external vector for the temporary subdiagonal of U DistMatrix<F,MD,STAR> uSub(g); uSub.SetRoot( A.DiagonalRoot(-1) ); uSub.AlignCols( A.DiagonalAlign(-1) ); Zeros( uSub, minDim-1, 1 ); // Reduce w to a multiple of e0 for( Int i=minDim-2; i>=0; --i ) { // Decide if we should pivot the i'th and i+1'th rows of w const F lambdaSub = A.Get(i+1,i); const F ups_ii = A.Get(i,i); const F omega_i = w.Get( i, 0 ); const F omega_ip1 = w.Get( i+1, 0 ); const Real rightTerm = Abs(lambdaSub*omega_i+omega_ip1); const bool pivot = ( Abs(omega_i) < tau*rightTerm ); const Range<Int> indB( i+2, m ), indR( i+1, n ), indi( i, i+1 ), indip1( i+1, i+2 ); auto lBi = A( indB, indi ); auto lBip1 = A( indB, indip1 ); auto uiR = A( indi, indR ); auto uip1R = A( indip1, indR ); if( pivot ) { // P := P_i P P.Swap( i, i+1 ); // Simultaneously perform // U := P_i U and // L := P_i L P_i^T // // Then update // L := L T_{i,L}^{-1}, // U := T_{i,L} U, // w := T_{i,L} P_i w, // where T_{i,L} is the Gauss transform which zeros (P_i w)_{i+1}. // // More succinctly, // gamma := w(i) / w(i+1), // w(i) := w(i+1), // w(i+1) := 0, // L(:,i) += gamma L(:,i+1), // U(i+1,:) -= gamma U(i,:). const F gamma = omega_i / omega_ip1; const F lambda_ii = F(1) + gamma*lambdaSub; A.Set( i, i, gamma ); A.Set( i+1, i, 0 ); auto lBiCopy = lBi; Swap( NORMAL, lBi, lBip1 ); Axpy( gamma, lBiCopy, lBi ); auto uip1RCopy = uip1R; RowSwap( A, i, i+1 ); Axpy( -gamma, uip1RCopy, uip1R ); // Force L back to *unit* lower-triangular form via the transform // L := L T_{i,U}^{-1} D^{-1}, // where D is diagonal and responsible for forcing L(i,i) and // L(i+1,i+1) back to 1. The effect on L is: // eta := L(i,i+1)/L(i,i), // L(:,i+1) -= eta L(:,i), // delta_i := L(i,i), // delta_ip1 := L(i+1,i+1), // L(:,i) /= delta_i, // L(:,i+1) /= delta_ip1, // while the effect on U is // U(i,:) += eta U(i+1,:) // U(i,:) *= delta_i, // U(i+1,:) *= delta_{i+1}, // and the effect on w is // w(i) *= delta_i. const F eta = lambdaSub/lambda_ii; const F delta_i = lambda_ii; const F delta_ip1 = F(1) - eta*gamma; Axpy( -eta, lBi, lBip1 ); A.Set( i+1, i, gamma/delta_i ); lBi *= F(1)/delta_i; lBip1 *= F(1)/delta_ip1; A.Set( i, i, eta*ups_ii*delta_i ); Axpy( eta, uip1R, uiR ); uiR *= delta_i; uip1R *= delta_ip1; uSub.Set( i, 0, ups_ii*delta_ip1 ); // Finally set w(i) w.Set( i, 0, omega_ip1*delta_i ); } else { // Update // L := L T_{i,L}^{-1}, // U := T_{i,L} U, // w := T_{i,L} w, // where T_{i,L} is the Gauss transform which zeros w_{i+1}. // // More succinctly, // gamma := w(i+1) / w(i), // L(:,i) += gamma L(:,i+1), // U(i+1,:) -= gamma U(i,:), // w(i+1) := 0. const F gamma = omega_ip1 / omega_i; A.Update( i+1, i, gamma ); Axpy( gamma, lBip1, lBi ); Axpy( -gamma, uiR, uip1R ); uSub.Set( i, 0, -gamma*ups_ii ); } } // Add the modified w v' into U { auto a0 = A( IR(0), ALL ); const F omega_0 = w.Get( 0, 0 ); DistMatrix<F> vTrans(g); vTrans.AlignWith( a0 ); Transpose( v, vTrans, conjugate ); Axpy( omega_0, vTrans, a0 ); } // Transform U from upper-Hessenberg to upper-triangular form for( Int i=0; i<minDim-1; ++i ) { // Decide if we should pivot the i'th and i+1'th rows U const F lambdaSub = A.Get( i+1, i ); const F ups_ii = A.Get( i, i ); const F ups_ip1i = uSub.Get( i, 0 ); const Real rightTerm = Abs(lambdaSub*ups_ii+ups_ip1i); const bool pivot = ( Abs(ups_ii) < tau*rightTerm ); const Range<Int> indB( i+2, m ), indR( i+1, n ), indi( i, i+1 ), indip1( i+1, i+2 ); auto lBi = A( indB, indi ); auto lBip1 = A( indB, indip1 ); auto uiR = A( indi, indR ); auto uip1R = A( indip1, indR ); if( pivot ) { // P := P_i P P.Swap( i, i+1 ); // Simultaneously perform // U := P_i U and // L := P_i L P_i^T // // Then update // L := L T_{i,L}^{-1}, // U := T_{i,L} U, // where T_{i,L} is the Gauss transform which zeros U(i+1,i). // // More succinctly, // gamma := U(i+1,i) / U(i,i), // L(:,i) += gamma L(:,i+1), // U(i+1,:) -= gamma U(i,:). const F gamma = ups_ii / ups_ip1i; const F lambda_ii = F(1) + gamma*lambdaSub; A.Set( i+1, i, ups_ip1i ); A.Set( i, i, gamma ); auto lBiCopy = lBi; Swap( NORMAL, lBi, lBip1 ); Axpy( gamma, lBiCopy, lBi ); auto uip1RCopy = uip1R; RowSwap( A, i, i+1 ); Axpy( -gamma, uip1RCopy, uip1R ); // Force L back to *unit* lower-triangular form via the transform // L := L T_{i,U}^{-1} D^{-1}, // where D is diagonal and responsible for forcing L(i,i) and // L(i+1,i+1) back to 1. The effect on L is: // eta := L(i,i+1)/L(i,i), // L(:,i+1) -= eta L(:,i), // delta_i := L(i,i), // delta_ip1 := L(i+1,i+1), // L(:,i) /= delta_i, // L(:,i+1) /= delta_ip1, // while the effect on U is // U(i,:) += eta U(i+1,:) // U(i,:) *= delta_i, // U(i+1,:) *= delta_{i+1}. const F eta = lambdaSub/lambda_ii; const F delta_i = lambda_ii; const F delta_ip1 = F(1) - eta*gamma; Axpy( -eta, lBi, lBip1 ); A.Set( i+1, i, gamma/delta_i ); lBi *= F(1)/delta_i; lBip1 *= F(1)/delta_ip1; A.Set( i, i, ups_ip1i*delta_i ); Axpy( eta, uip1R, uiR ); uiR *= delta_i; uip1R *= delta_ip1; } else { // Update // L := L T_{i,L}^{-1}, // U := T_{i,L} U, // where T_{i,L} is the Gauss transform which zeros U(i+1,i). // // More succinctly, // gamma := U(i+1,i)/ U(i,i), // L(:,i) += gamma L(:,i+1), // U(i+1,:) -= gamma U(i,:). const F gamma = ups_ip1i / ups_ii; A.Update( i+1, i, gamma ); Axpy( gamma, lBip1, lBi ); Axpy( -gamma, uiR, uip1R ); } } }
void ObjectEditHandler::Roaming(CPoint Point, Ogre::TerrainGroup::RayResult rayResult, float Elapsed) { if(mMode == OEM_NONE) return; if(mFreeTransform) { Ogre::Vector3 newPosition; if(!(GetKeyState(VK_LCONTROL) & 0x8000)) { newPosition = Ogre::Vector3(rayResult.position.x, mTarget->getSceneNode()->getPosition().y, rayResult.position.z); if(mOwner->isPaste()) newPosition.y = rayResult.position.y; mTarget->getSceneNode()->setPosition(newPosition); PropertyWnd::current->firePropertyChanged(); } mObjectEditNode->setPosition(newPosition); } else if(GetKeyState(VK_LBUTTON) & 0x8000) { if(Point == mLastPoint) return; CPoint Move = Point - mLastPoint; mLastPoint = Point; if(mMode == OEM_TRANS) { Ogre::Vector3 vCamXAxis, vCamYAxis, vCamZAxis; mOwner->getCamera()->getDerivedOrientation().ToAxes(vCamXAxis, vCamYAxis, vCamZAxis); Ogre::Vector3 vTrans(0,0,0); switch(mAxisMode) { case AM_TRANS_SCALE_X: { float xyPlane = (vCamZAxis.y < 0 ? -1 : 1); float yAxis = (vCamXAxis.z < 0 ? 1 : -1); vTrans.x = Move.x * vCamXAxis.x + Move.y * (1 - vCamXAxis.x) * xyPlane * yAxis; } break; case AM_TRANS_SCALE_Y: { vTrans.y = -Move.y * (vCamYAxis.y > 0 ? 1 : -1); } break; case AM_TRANS_SCALE_Z: { float yAxis = (vCamZAxis.z < 0 ? -1 : 1); vTrans.z = Move.x * vCamXAxis.z + Move.y * (1.0f - vCamXAxis.z) * yAxis; } break; case AM_TRANS_SCALE_ALL: { float xyPlane = (vCamZAxis.y < 0 ? -1 : 1); float yAxis = (vCamXAxis.z < 0 ? 1 : -1); vTrans.x = Move.x * vCamXAxis.x + Move.y * (1 - vCamXAxis.x) * xyPlane * yAxis; vTrans.z = Move.x * vCamXAxis.z + Move.y * (1.0f - vCamXAxis.z) * (vCamZAxis.z < 0 ? -1 : 1); vTrans.y = -Move.y * (vCamYAxis.y > 0 ? 1 : -1); } } if(!(GetKeyState(VK_LCONTROL) & 0x8000)) { mTarget->getSceneNode()->translate(vTrans); PropertyWnd::current->firePropertyChanged(); } mObjectEditNode->translate(vTrans); } else if(mMode == OEM_SCALE) { Ogre::Vector3 vScaleInc(0, 0, 0); if(mAxisMode == AM_TRANS_SCALE_ALL) { vScaleInc.x = Move.x * 0.01f; vScaleInc.y = vScaleInc.x; vScaleInc.z = vScaleInc.x; } else { Ogre::Vector3 vNodeXAxis, vNodeYAxis, vNodeZAxis; mObjectEditNode->getOrientation().ToAxes(vNodeXAxis, vNodeYAxis, vNodeZAxis); const Ogre::Matrix4 &ViewMatrix = mOwner->getCamera()->getViewMatrix(); switch(mAxisMode) { case AM_TRANS_SCALE_X: { vNodeXAxis = ViewMatrix * vNodeXAxis; vScaleInc.x = (Move.x * vNodeXAxis.x - Move.y * vNodeXAxis.y) * 0.001f; } break; case AM_TRANS_SCALE_Y: { vNodeYAxis = ViewMatrix * vNodeYAxis; vScaleInc.y = (Move.x * vNodeYAxis.x - Move.y * vNodeYAxis.y) * 0.001f; } break; case AM_TRANS_SCALE_Z: { vNodeZAxis = ViewMatrix * vNodeZAxis; vScaleInc.z = (Move.x * vNodeZAxis.x - Move.y * vNodeZAxis.y) * 0.001f; } } mTarget->getSceneNode()->setScale( mTarget->getSceneNode()->getScale() + vScaleInc); PropertyWnd::current->firePropertyChanged(); } } else if(mMode == OEM_ROTATE) { Ogre::Quaternion qRotate; switch(mAxisMode) { case AM_ROTATE_X: qRotate.FromAngleAxis(Ogre::Radian(Move.y * 0.01f), mRotateNode->getOrientation().xAxis()); break; case AM_ROTATE_Y: qRotate.FromAngleAxis(Ogre::Radian(Move.x * 0.01f), mRotateNode->getOrientation().yAxis()); break; case AM_ROTATE_Z: qRotate.FromAngleAxis(Ogre::Radian(-Move.y * 0.01f), mRotateNode->getOrientation().zAxis()); break; } if (!(GetKeyState(VK_LCONTROL) & 0x8000)) { mTarget->getSceneNode()->rotate(qRotate, Ogre::Node::TS_PARENT); PropertyWnd::current->firePropertyChanged(); } mRotateNode->rotate(qRotate, Ogre::Node::TS_PARENT); } } else { mIndicatorContext->collide(); OgreOpcode::CollisionPair **CollisionPair = NULL; float Distance = mOwner->getCamera()->getFarClipDistance(); if(Distance < 0.1f) // 近似比较float与0 Distance = Ogre::Math::POS_INFINITY; Ogre::Ray pickRay = mOwner->getCamera()->getCameraToViewportRay(float(Point.x) / mOwner->getActiveView()->getWidth(), float(Point.y) / mOwner->getActiveView()->getHeight()); if(mIndicatorContext->rayCheck(pickRay, Distance, OgreOpcode::COLLTYPE_EXACT, OgreOpcode::COLLTYPE_ALWAYS_EXACT, CollisionPair)) { OgreOpcode::CollisionObject *CollisionObject = CollisionPair[0]->this_object; KAxisMode AxisMode = mCollisionObjectToAxisMode[CollisionObject]; if(mAxisMode == AM_NONE) { mAxisMode = mCollisionObjectToAxisMode[CollisionObject]; mTransformEntities[mAxisMode]->setMaterial(mMaterials[4]); return; } else if(mAxisMode == AxisMode) return; } switch(mAxisMode) // 恢复指示器材质 { case AM_NONE: return; case AM_TRANS_SCALE_X: case AM_ROTATE_X: mTransformEntities[mAxisMode]->setMaterial(mMaterials[0]); break; case AM_TRANS_SCALE_Y: case AM_ROTATE_Y: mTransformEntities[mAxisMode]->setMaterial(mMaterials[1]); break; case AM_TRANS_SCALE_Z: case AM_ROTATE_Z: mTransformEntities[mAxisMode]->setMaterial(mMaterials[2]); break; case AM_TRANS_SCALE_ALL: mTransformEntities[mAxisMode]->setMaterial(mMaterials[3]); break; } mAxisMode = AM_NONE; } }
//-------------------------------------------------------------------------------------- void CALLBACK OnD3D10FrameRender(ID3D10Device* pDev10, double fTime, float fElapsedTime, void* pUserContext) { HRESULT hr; g_pCamManager->SyncToCameraUI(g_CameraUI); //dont delete, used no only here const DXGI_SURFACE_DESC *pBackBufferSurfaceDesc = DXUTGetDXGIBackBufferSurfaceDesc(); if( ShadowAlgorithm != OldShadowAlgorithm ) { OldShadowAlgorithm = ShadowAlgorithm; switch( ShadowAlgorithm ) { case STANDARD_BP: g_ABP.OnD3D10DestroyDevice(); break; case BP_MSSM_KERNEL: g_BPMSSMKernel.OnD3D10DestroyDevice(); break; case STD_VSM: g_StdVSM.OnD3D10DestroyDevice(); break; case MIP_VSM: g_MipVSM.OnD3D10DestroyDevice(); break; case HIR_BP: g_HBP.OnD3D10DestroyDevice(); break; case BP_GI: g_BPGI.OnD3D10DestroyDevice(); break; case STD_PCSS: g_PCSS.OnD3D10DestroyDevice(); break; default: break; }; switch( ShadowAlgorithm ) { case STANDARD_BP: g_ABP.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext); g_ABP.OnD3D10SwapChainResized(pDev10,NULL,pBackBufferSurfaceDesc,pUserContext ); break; case BP_MSSM_KERNEL: g_BPMSSMKernel.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext); g_BPMSSMKernel.OnD3D10SwapChainResized(pDev10,NULL,pBackBufferSurfaceDesc,pUserContext ); break; case STD_VSM: g_StdVSM.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext); g_StdVSM.OnD3D10SwapChainResized(pDev10,NULL,pBackBufferSurfaceDesc,pUserContext ); break; case MIP_VSM: g_MipVSM.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext); g_MipVSM.OnD3D10SwapChainResized(pDev10,NULL,pBackBufferSurfaceDesc,pUserContext ); break; case HIR_BP: g_HBP.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext); g_HBP.OnD3D10SwapChainResized(pDev10,NULL,pBackBufferSurfaceDesc,pUserContext ); break; case BP_GI: g_BPGI.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext); g_BPGI.OnD3D10SwapChainResized(pDev10,NULL,pBackBufferSurfaceDesc,pUserContext ); break; case STD_PCSS: g_PCSS.OnD3D10CreateDevice(pDev10,pBackBufferSurfaceDesc,pUserContext); g_PCSS.OnD3D10SwapChainResized(pDev10,NULL,pBackBufferSurfaceDesc,pUserContext ); break; default: break; }; } //begin light and view pos management { static double old_fTime = 0.001; fTime = old_fTime; old_fTime += 0.02; static double oldTime = 0; static unsigned old_iSta = 0; static double stop_time = 0; static double total_stop_time = 0; double tmp = fTime; unsigned iSta = g_SampleUI.GetCheckBox(IDC_STATIC)->GetChecked(); if( 0 == old_iSta && 1 == iSta )//turn to be static { stop_time = fTime - total_stop_time; } if( 1 == iSta ) { total_stop_time += ( fTime - oldTime ); fTime = stop_time; } if( 0 == iSta ) { fTime -= total_stop_time; } old_iSta = iSta; oldTime = tmp; }//end light and view pos management S3UTCamera& g_CameraRef = *(g_pCamManager->ActiveEye()); // compute view matrix D3DXMATRIX mTmp, mWorldView, mWorldViewProj, mWorldViewInv; D3DXMatrixInverse(&mTmp, NULL, g_CameraRef.GetWorldMatrix()); D3DXMatrixMultiply(&mWorldView, &mTmp, g_CameraRef.GetViewMatrix()); // correct near/far clip planes according to camera location D3DXVECTOR3 vBox[2]; float fAspectRatio = pBackBufferSurfaceDesc->Width / (FLOAT)pBackBufferSurfaceDesc->Height; // clear depth and color ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView(); pDev10->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH, 1.0, 0); ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView(); if( g_D3DSettingsDlg.IsActive() ) { g_D3DSettingsDlg.OnRender( fElapsedTime ); return; } Parameters para; para.fLightZn = g_fCtrledLightZn; float biases[15]; biases[0] = g_fDepthBiasObject0; biases[1] = g_fDefaultDepthBias; biases[2] = g_fDepthBiasHammer; biases[3] = g_fDepthBiasLeftForearm; biases[4] = g_fDepthBiasRightForearm; biases[5] = g_fDepthBiasLeftShoulder; biases[6] = g_fDepthBiasRightShoulder; biases[7] = g_fDepthBiasBlackPlate; biases[8] = g_fDepthBiasHelmet; biases[9] = g_fDepthBiasEyes; biases[10] = g_fDepthBiasBelt; biases[11] = g_fDepthBiasLeftThigh; biases[12] = g_fDepthBiasRightThigh; biases[13] = g_fDepthBiasLeftShin; biases[14] = g_fDepthBiasRightShin; g_MeshScene.set_biases(biases,15); float light_size[NUM_LIGHT] = LIGHT_SIZE; float light_ZNS[NUM_LIGHT] = LIGHT_ZNS; float light_view_angle[NUM_LIGHT] = LIGHT_VIEW_ANGLES; D3DXVECTOR4 light_color[NUM_LIGHT] = LIGHT_COLOR; bool render_ogre = g_SampleUI.GetCheckBox( IDC_ANIMATE )->GetChecked(); bool render_scene = g_SampleUI.GetCheckBox( IDC_SCENE )->GetChecked(); bool render_fan = g_SampleUI.GetCheckBox( IDC_FAN )->GetChecked(); float ClearColor[4] = { 0, 0, 0, 1 }; pDev10->ClearRenderTargetView(g_pBlendBuffer->m_pRTView, ClearColor); //use alpha val 1 to represent untouched pixels pDev10->ClearRenderTargetView(g_pWidgetBuffer->m_pRTView, ClearColor); //light management ID3D10RenderTargetView *p_RTV; ID3D10ShaderResourceView *p_SRV; static float light_scale_factor = 0.2; static float ls_incre = 0.04; if( g_LightVary == true || g_fFilterSize < g_fFilterSizeCtrl ) { g_fFilterSize -= ls_incre; if( g_fFilterSize < 0.1 || g_fFilterSize > g_fFilterSizeCtrl ) ls_incre = -ls_incre; } else { g_fFilterSize = g_fFilterSizeCtrl; } g_fFilterSize = g_fFilterSizeCtrl; //light pos is not modified here. this light pos stored in 3DWidget is only synced with light camera after rendering of the light //if you try to modify light pos here, light would be freezed, of course, this is a bug introduced by bad design D3DXVECTOR3 vTmp; // render GBuffer pDev10->OMSetDepthStencilState(g_pDSState,0); g_GBuffer.OnD3D10FrameRender( true, true, g_SampleUI, g_MeshScene, g_CameraRef, pDev10, fTime, fElapsedTime, pUserContext ); g_Blender.OriginalSampleMask = 0; pDev10->OMGetBlendState( &g_Blender.pOriginalBlendState, g_Blender.OriginalBlendFactor, &g_Blender.OriginalSampleMask ); float BlendBufferClearColor[4] = { 1, 1, 0, 1 }; bool isFirstPass = true; for( int cam_idx = 0; cam_idx < g_pCamManager->CameraCount(); ++cam_idx ) { // rendering a subdivided light if( g_pCamManager->Camera(cam_idx)->GetCamType() == S3UTCamera::eLight&& g_pCamManager->Camera(cam_idx)->IsActive() ) { float scaled_half_light_size = (g_pCamManager->Camera(cam_idx)->GetLightSize()*LIGHT_SCALE_FACTOR); float fStartPt = -scaled_half_light_size; float fInterval = 2 * scaled_half_light_size / g_nNumLightSample; float fSubLightSize = g_pCamManager->Camera(cam_idx)->GetLightSize(); if( g_nNumLightSample > 0 ) { fSubLightSize = fSubLightSize / g_nNumLightSample; } if( g_nNumLightSample == 0 ) { g_nNumLightSample = 1; } static float total_light_x_incre = 0; static int light_mov_dir = 0; float shadow_factor = 0.8/(g_nNumLightSample * g_nNumLightSample); for( int ix = 0; ix < g_nNumLightSample; ++ix ) { for( int iy = 0; iy < g_nNumLightSample; ++iy ) { D3DXVECTOR3 vLight = *g_pCamManager->Camera(cam_idx)->GetEyePt(); S3UTCamera local_cam = *g_pCamManager->Camera(cam_idx); D3DXVECTOR3 vTrans( fStartPt+(ix+0.5)*fInterval,fStartPt+(iy+0.5)*fInterval,0 ); if( g_nNumLightSample == 1 ) { vTrans = D3DXVECTOR3(0,0,0); } D3DXMATRIX mInvLightView; D3DXVECTOR4 tmp_light_pos; D3DXMatrixInverse(&mInvLightView, NULL, local_cam.GetViewMatrix()); D3DXVec3Transform(&tmp_light_pos, &vTrans, &mInvLightView ); D3DXVECTOR3 tmp_light_pos_3(tmp_light_pos.x,tmp_light_pos.y,tmp_light_pos.z); D3DXVECTOR3 vLookAt = *local_cam.GetLookAtPt(); local_cam.SetViewParams( &tmp_light_pos_3, &vLookAt ); g_MeshScene.set_parameters( render_ogre, render_scene, render_fan, false ); D3DXMATRIX mLightView; // here we compute light viewprojection so that light oversees the whole scene D3DXMATRIX mTranslate; D3DXMatrixInverse(&mTranslate, NULL, local_cam.GetWorldMatrix()); D3DXMatrixMultiply(&mLightView, &mTranslate, local_cam.GetViewMatrix()); unsigned iTmp = g_SampleUI.GetCheckBox(IDC_BDUMP_SHADOWMAP)->GetChecked(); ssmap.Render(pDev10, &g_MeshScene, local_cam,fTime,fElapsedTime,iTmp); pDev10->RSSetState(g_pRenderState); p_RTV = g_pBlendBuffer->m_pRTView; float NewBlendFactor[4] = {0,0,0,0}; //alpha blending initial; if( isFirstPass ) { isFirstPass = false; pDev10->OMSetBlendState( g_Blender.m_pSceneBlendStateInitial, NewBlendFactor, 0xffffffff ); } else { pDev10->OMSetBlendState( g_Blender.m_pSceneBlendStateOn, NewBlendFactor, 0xffffffff ); } if( ShadowAlgorithm == BP_GI ) { V(g_BPGI.m_pEffect->GetVariableByName("g_fLumiFactor")->AsScalar()->SetFloat( shadow_factor )); g_BPGI.set_parameters( para,p_RTV,&light_color[0] ); g_BPGI.set_input_buffer( &g_GBuffer ); g_BPGI.OnD3D10FrameRender(render_ogre,render_scene,g_SampleUI,g_MeshScene,fSubLightSize,ssmap,g_CameraRef,local_cam,pDev10,fTime,fElapsedTime,pUserContext); } else if( ShadowAlgorithm == STANDARD_BP ) { V(g_ABP.m_pEffect->GetVariableByName("fLumiFactor")->AsScalar()->SetFloat( shadow_factor )); g_ABP.set_parameters( para,p_RTV,&light_color[0] ); g_ABP.set_input_buffer( &g_GBuffer ); g_ABP.OnD3D10FrameRender(render_ogre,render_scene,g_SampleUI,g_MeshScene,fSubLightSize,ssmap,g_CameraRef,local_cam,pDev10,fTime,fElapsedTime,pUserContext); } else if( ShadowAlgorithm == BP_MSSM_KERNEL ) { V(g_BPMSSMKernel.m_pEffect->GetVariableByName("fLumiFactor")->AsScalar()->SetFloat( shadow_factor )); g_BPMSSMKernel.set_parameters( para,p_RTV,&light_color[0] ); g_BPMSSMKernel.set_input_buffer( &g_GBuffer ); g_BPMSSMKernel.OnD3D10FrameRender(render_ogre,render_scene,g_SampleUI,g_MeshScene,fSubLightSize,ssmap,g_CameraRef,local_cam,pDev10,fTime,fElapsedTime,pUserContext); } else if( ShadowAlgorithm == STD_VSM ) { V(g_StdVSM.m_pEffect->GetVariableByName("fLumiFactor")->AsScalar()->SetFloat( shadow_factor )); g_StdVSM.set_bias( g_fDefaultDepthBias,g_f3rdDepthDelta, g_f1stDepthDelta ); g_StdVSM.set_parameters( para,p_RTV,&light_color[0] ); g_StdVSM.set_input_buffer( &g_GBuffer ); g_StdVSM.OnD3D10FrameRender(render_ogre,render_scene,g_SampleUI,g_MeshScene,fSubLightSize,ssmap,g_CameraRef,local_cam,pDev10,fTime,fElapsedTime,pUserContext); } else if( ShadowAlgorithm == MIP_VSM ) { V(g_MipVSM.m_pEffect->GetVariableByName("fLumiFactor")->AsScalar()->SetFloat( shadow_factor )); g_MipVSM.set_parameters( para,p_RTV,&light_color[0] ); g_MipVSM.set_input_buffer( &g_GBuffer ); g_MipVSM.OnD3D10FrameRender(render_ogre,render_scene,g_SampleUI,g_MeshScene,fSubLightSize,ssmap,g_CameraRef,local_cam,pDev10,fTime,fElapsedTime,pUserContext); } else if( ShadowAlgorithm == STD_PCSS ) { V(g_PCSS.m_pEffect->GetVariableByName("fLumiFactor")->AsScalar()->SetFloat( shadow_factor )); g_PCSS.set_parameters( para,p_RTV,&light_color[0] ); g_PCSS.set_input_buffer( &g_GBuffer ); g_PCSS.OnD3D10FrameRender(render_ogre,render_scene,g_SampleUI,g_MeshScene,fSubLightSize,ssmap,g_CameraRef,local_cam,pDev10,fTime,fElapsedTime,pUserContext); } //alpha blending restore pDev10->OMSetBlendState( g_Blender.pOriginalBlendState, g_Blender.OriginalBlendFactor, g_Blender.OriginalSampleMask ); if( g_SampleUI.GetCheckBox( IDC_SHOW_3DWIDGET )->GetChecked() ) { if( g_pCamManager->Camera(cam_idx)->GetCamType() == S3UTCamera::eLight&& g_pCamManager->Camera(cam_idx)->IsActive() ) { pDev10->OMSetRenderTargets(1, &(g_pWidgetBuffer->m_pRTView), g_GBuffer.m_pDepthBuffer->m_pDSView); g_Widget.m_pSsmap = &ssmap; g_Widget.OnD3D10FrameRender(pDev10,g_CameraRef,local_cam); } } } } } } //----------------------------------------------------------------------------------- D3DXMATRIX mMatrixScale; D3DXMATRIX mMatrixScaleWVP; D3DXMatrixScaling( &mMatrixScale,(FLOAT)5,(FLOAT)5,(FLOAT)5 ); D3DXMatrixMultiply( &mMatrixScaleWVP, &mMatrixScale, &mWorldViewProj ); ID3D10RenderTargetView* pOrigRTV = DXUTGetD3D10RenderTargetView(); pDev10->OMSetRenderTargets(1,&pOrigRTV,NULL); float FinalClearColor[4] = { 1, 0, 0, 1 }; pDev10->ClearRenderTargetView(pOrigRTV, FinalClearColor); g_MeshScene.set_parameters( render_ogre,render_scene, render_fan ); g_Final.set_parameters( para, pOrigRTV, NULL, g_pBlendBuffer->m_pSRView, g_pWidgetBuffer->m_pSRView ); S3UTCamera& g_LCameraRef = g_LCamera[0]; g_Final.set_input_buffer( &g_GBuffer ); g_pSkyBox->OnFrameRender( mMatrixScaleWVP ); g_Final.OnD3D10FrameRender(g_SampleUI,g_MeshScene,g_fFilterSize,ssmap,g_CameraRef,g_LCameraRef,pDev10,fTime,fElapsedTime,pUserContext); g_LCameraRef.SetProjParams(g_fCtrledLightFov, 1.0, g_fCtrledLightZn, g_fCtrledLightZf); //if( g_SampleUI.GetCheckBox( IDC_SHOW_3DWIDGET )->GetChecked() ) //{ // for( int cam_idx = 0; cam_idx < g_pCamManager->CameraCount(); ++cam_idx ) // { // // rendering a subdivided light // if( g_pCamManager->Camera(cam_idx)->GetCamType() == S3UTCamera::eLight&& // g_pCamManager->Camera(cam_idx)->IsActive() ) // { // g_Widget.m_pSsmap = &ssmap; // g_Widget.OnD3D10FrameRender(pDev10,g_CameraRef,*(g_pCamManager->Camera(cam_idx))); // } // } //} // render UI if (g_bShowUI) { RenderText(); g_SampleUI.OnRender(fElapsedTime); //g_HUD.OnRender(fElapsedTime); } if( g_bShowLightUI ) { g_CameraUI.OnRender(fElapsedTime); } if( g_SampleUI.GetCheckBox( IDC_FRAME_DUMP )->GetChecked() ) { static int g_Frame = 0; IDXGISwapChain* pSwapChain = DXUTGetDXGISwapChain(); ID3D10Texture2D* pRT; pSwapChain->GetBuffer(0, __uuidof(pRT), reinterpret_cast<void**>(&pRT)); WCHAR filename[32]; StringCchPrintf(filename, 100, L"DumpedImages\\screenshot%.3d.jpg", g_Frame); D3DX10SaveTextureToFile(pRT, D3DX10_IFF_JPG, filename); SAFE_RELEASE(pRT); ++g_Frame; } }