void SpotlightDemo::drawSpheres() { D3DXMATRIX W, WIT; HR(mFX->SetValue(mhAmbientMtrl, &mSphereMtrl.ambient, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhDiffuseMtrl, &mSphereMtrl.diffuse, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhSpecMtrl, &mSphereMtrl.spec, sizeof(D3DXCOLOR))); HR(mFX->SetFloat(mhSpecPower, mSphereMtrl.specPower)); for(int z = -30; z <= 30; z+= 10) { D3DXMatrixTranslation(&W, -10.0f, 7.5f, (float)z); D3DXMatrixInverse(&WIT, 0, &W); D3DXMatrixTranspose(&WIT, &WIT); HR(mFX->SetMatrix(mhWVP, &(W*mView*mProj))); HR(mFX->SetMatrix(mhWorld, &W)); HR(mFX->SetMatrix(mhWorldInvTrans, &WIT)); HR(mFX->CommitChanges()); HR(mSphere->DrawSubset(0)); D3DXMatrixTranslation(&W, 10.0f, 7.5f, (float)z); D3DXMatrixInverse(&WIT, 0, &W); D3DXMatrixTranspose(&WIT, &WIT); HR(mFX->SetMatrix(mhWVP, &(W*mView*mProj))); HR(mFX->SetMatrix(mhWorld, &W)); HR(mFX->SetMatrix(mhWorldInvTrans, &WIT)); HR(mFX->CommitChanges()); HR(mSphere->DrawSubset(0)); } }
void MirrorDemo::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, 0xffeeeeee, 1.0f, 0)); HR(gd3dDevice->BeginScene()); HR(mFX->SetTechnique(mhTech)); HR(mFX->SetValue(mhLightVecW, &mLightVecW, sizeof(D3DXVECTOR3))); HR(mFX->SetValue(mhDiffuseLight, &mDiffuseLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhAmbientLight, &mAmbientLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhSpecularLight, &mSpecularLight, sizeof(D3DXCOLOR))); // All objects use the same material. HR(mFX->SetValue(mhAmbientMtrl, &mWhiteMtrl.ambient, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhDiffuseMtrl, &mWhiteMtrl.diffuse, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhSpecularMtrl, &mWhiteMtrl.spec, sizeof(D3DXCOLOR))); HR(mFX->SetFloat(mhSpecularPower, mWhiteMtrl.specPower)); drawRoom(); drawMirror(); drawTeapot(); drawReflectedTeapot(); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void GateDemo::drawGround() { HR(mFX->SetValue(mhAmbientMtrl, &mGroundMtrl.ambient, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhDiffuseMtrl, &mGroundMtrl.diffuse, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhSpecularMtrl, &mGroundMtrl.spec, sizeof(D3DXCOLOR))); HR(mFX->SetFloat(mhSpecularPower, mGroundMtrl.specPower)); HR(mFX->SetMatrix(mhWVP, &(mGroundWorld*mView*mProj))); D3DXMATRIX worldInvTrans; D3DXMatrixInverse(&worldInvTrans, 0, &mGroundWorld); D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans); HR(mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans)); HR(mFX->SetMatrix(mhWorld, &mGroundWorld)); HR(mFX->SetTexture(mhTex, mGroundTex)); HR(gd3dDevice->SetVertexDeclaration(VertexPNT::Decl)); HR(gd3dDevice->SetStreamSource(0, mGridVB, 0, sizeof(VertexPNT))); HR(gd3dDevice->SetIndices(mGridIB)); // Begin passes. UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); for(UINT i = 0; i < numPasses; ++i) { HR(mFX->BeginPass(i)); HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, mNumGridVertices, 0, mNumGridTriangles)); HR(mFX->EndPass()); } HR(mFX->End()); }
void AmbientDiffuseDemo::drawScene() { HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255,255,255), 1.0f, 0)); HR(gd3dDevice->BeginScene()); HR(mFX->SetTechnique(mhTech)); HR(mFX->SetMatrix(mhWVP, &(mWorld*mView*mProj))); D3DXMATRIX worldInverseTranspose; D3DXMatrixInverse(&worldInverseTranspose, 0, &mWorld); D3DXMatrixTranspose(&worldInverseTranspose, &worldInverseTranspose); HR(mFX->SetMatrix(mhWorldInverseTranspose, &worldInverseTranspose)); HR(mFX->SetValue(mhLightVecW, &mLightVecW, sizeof(D3DXVECTOR3))); HR(mFX->SetValue(mhDiffuseMtrl, &mDiffuseMtrl, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhDiffuseLight, &mDiffuseLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhAmbientMtrl, &mAmbientMtrl, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhAmbientLight, &mAmbientLight, sizeof(D3DXCOLOR))); UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); for (UINT i = 0; i < numPasses; ++i) { HR(mFX->BeginPass(i)); HR(mTeapot->DrawSubset(0)); HR(mFX->EndPass()); } HR(mFX->End()); mGfxStats->display(D3DCOLOR_XRGB(0,0,0)); HR(gd3dDevice->EndScene()); HR(gd3dDevice->Present(0, 0, 0, 0)); }
void MeshNode::Draw(IDirect3DDevice9* device) const{ if(!initialized) return; assert(NULL != device); // set the transform device->SetTransform(D3DTS_WORLDMATRIX(0), &transform_); //FIXME Should not be accessed directly ID3DXEffect* effect = GraphicsLayer::GetInstance().m_pEffect; effect->SetMatrix( "g_WorldMatrix", &transform_); effect->SetValue( "g_ColorTint", &m_colorMtrlTint, sizeof( D3DXCOLOR ) ); effect->SetValue( "g_TexOffset", &m_texOffset, sizeof( Vector2 ) ); assert(SUCCEEDED(effect->SetTechnique( "RenderSceneWithTextureDefault" ))); UINT cPasses = 1; assert(SUCCEEDED(effect->Begin( &cPasses, 0 ))); for(UINT iPass = 0; iPass < cPasses; iPass++ ) { effect->BeginPass( iPass ) ; mesh_->Draw(device); assert(SUCCEEDED(effect->EndPass())); } assert(SUCCEEDED(effect->End())); if(NULL != boundsMesh_){ Matrix t = CreateMatrix(worldBounds_.center); device->SetTransform(D3DTS_WORLDMATRIX(0), &t); boundsMesh_->DrawSubset(0); } }
void SpotlightDemo::drawCylinders() { D3DXMATRIX T, R, W, WIT; D3DXMatrixRotationX(&R, D3DX_PI*0.5f); HR(mFX->SetValue(mhAmbientMtrl, &mCylinderMtrl.ambient, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhDiffuseMtrl, &mCylinderMtrl.diffuse, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhSpecMtrl, &mCylinderMtrl.spec, sizeof(D3DXCOLOR))); HR(mFX->SetFloat(mhSpecPower, mCylinderMtrl.specPower)); for(int z = -30; z <= 30; z+= 10) { D3DXMatrixTranslation(&T, -10.0f, 3.0f, (float)z); W = R*T; D3DXMatrixInverse(&WIT, 0, &W); D3DXMatrixTranspose(&WIT, &WIT); HR(mFX->SetMatrix(mhWVP, &(W*mView*mProj))); HR(mFX->SetMatrix(mhWorld, &W)); HR(mFX->SetMatrix(mhWorldInvTrans, &WIT)); HR(mFX->CommitChanges()); HR(mCylinder->DrawSubset(0)); D3DXMatrixTranslation(&T, 10.0f, 3.0f, (float)z); W = R*T; D3DXMatrixInverse(&WIT, 0, &W); D3DXMatrixTranspose(&WIT, &WIT); HR(mFX->SetMatrix(mhWVP, &(W*mView*mProj))); HR(mFX->SetMatrix(mhWorld, &W)); HR(mFX->SetMatrix(mhWorldInvTrans, &WIT)); HR(mFX->CommitChanges()); HR(mCylinder->DrawSubset(0)); } }
void SolarSysDemo::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0)); HR(gd3dDevice->BeginScene()); HR(mFX->SetValue(mhLight, &mLight, sizeof(DirLight))); HR(mFX->SetTechnique(mhTech)); UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); HR(mFX->BeginPass(0)); // Wrap the texture coordinates that get assigned to TEXCOORD2 in the pixel shader. HR(gd3dDevice->SetRenderState(D3DRS_WRAP2, D3DWRAP_U)); // Build the world transforms for each frame, then render them. buildObjectWorldTransforms(); D3DXMATRIX S; for(int i = 0; i < NUM_OBJECTS; ++i) { float s = mObject[i].size; D3DXMatrixScaling(&S, s, s, s); // Prefix the frame matrix with a scaling transformation to // size it relative to the world. mWorld = S * mObject[i].toWorldXForm; HR(mFX->SetMatrix(mhWVP, &(mWorld*mView*mProj))); D3DXMATRIX worldInvTrans; D3DXMatrixInverse(&worldInvTrans, 0, &mWorld); D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans); HR(mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans)); HR(mFX->SetMatrix(mhWorld, &mWorld)); HR(mFX->SetValue(mhMtrl, &mWhiteMtrl, sizeof(Mtrl))); HR(mFX->SetTexture(mhTex, mObject[i].tex)); HR(mFX->CommitChanges()); mSphere->DrawSubset(0); } HR(gd3dDevice->SetRenderState(D3DRS_WRAP2, 0)); HR(mFX->EndPass()); HR(mFX->End()); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void WaterDemo::drawScene() { HR(gd3dDevice->BeginScene()); mSky->draw(); HR(mFX->SetValue(mhLight, &mLight, sizeof(DirLight))); HR(mFX->SetMatrix(mhWVP, &(mSceneWorld*gCamera->viewProj()))); HR(mFX->SetValue(mhEyePosW, &gCamera->pos(), sizeof(D3DXVECTOR3))); UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); HR(mFX->BeginPass(0)); for(UINT j = 0; j < mSceneMtrls.size(); ++j) { HR(mFX->SetValue(mhMtrl, &mSceneMtrls[j], sizeof(Mtrl))); // If there is a texture, then use. if(mSceneTextures[j] != 0) { HR(mFX->SetTexture(mhTex, mSceneTextures[j])); } // But if not, then set a pure white texture. When the texture color // is multiplied by the color from lighting, it is like multiplying by // 1 and won't change the color from lighting. else { HR(mFX->SetTexture(mhTex, mWhiteTex)); } HR(mFX->SetTexture(mhNormalMap, mSceneNormalMaps[j])); HR(mFX->CommitChanges()); HR(mSceneMesh->DrawSubset(j)); } HR(mFX->EndPass()); HR(mFX->End()); // Draw alpha blended object last. mWater->draw(); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void DiffusePyramidDemo::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffeeeeee, 1.0f, 0)); HR(gd3dDevice->BeginScene()); // Let Direct3D know the vertex buffer, index buffer and vertex // declaration we are using. HR(gd3dDevice->SetStreamSource(0, mVB, 0, sizeof(VertexPN))); HR(gd3dDevice->SetVertexDeclaration(VertexPN::Decl)); // Setup the rendering FX HR(mFX->SetTechnique(mhTech)); HR(mFX->SetMatrix(mhWVP, &(mWorld*mView*mProj))); D3DXMATRIX worldInverseTranspose , tmp1; D3DXMatrixInverse(&worldInverseTranspose, 0, &mWorld); D3DXMatrixTranspose(&tmp1, &worldInverseTranspose); ////! debug //if (worldInverseTranspose!=tmp1) //{ // DebugBreak(); //} HR(mFX->SetMatrix(mhWorldInverseTranspose, &worldInverseTranspose)); HR(mFX->SetValue(mhLightVecW, &mLightVecW, sizeof(D3DXVECTOR3))); HR(mFX->SetValue(mhDiffuseMtrl, &mDiffuseMtrl, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhDiffuseLight, &mDiffuseLight, sizeof(D3DXCOLOR))); // Begin passes. UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); for(UINT i = 0; i < numPasses; ++i) { HR(mFX->BeginPass(i)); HR(gd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 4)); HR(mFX->EndPass()); } HR(mFX->End()); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void MirrorDemo::drawReflectedTeapot() { HR(gd3dDevice->SetRenderState(D3DRS_STENCILENABLE, true)); HR(gd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS)); HR(gd3dDevice->SetRenderState(D3DRS_STENCILREF, 0x1)); HR(gd3dDevice->SetRenderState(D3DRS_STENCILMASK, 0xffffffff)); HR(gd3dDevice->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff)); HR(gd3dDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP)); HR(gd3dDevice->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP)); HR(gd3dDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE)); // Disable writes to the depth and back buffers HR(gd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, false)); HR(gd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true)); HR(gd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO)); HR(gd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE)); // Draw mirror to stencil only. drawMirror(); // Re-enable depth writes HR(gd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, true )); // Only draw reflected teapot to the pixels where the mirror // was drawn to. HR(gd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_EQUAL)); HR(gd3dDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP)); // Build Reflection transformation. D3DXMATRIX R; D3DXPLANE plane(0.0f, 0.0f, 1.0f, 0.0f); // xy plane D3DXMatrixReflect(&R, &plane); // Save the original teapot world matrix. D3DXMATRIX oldTeapotWorld = mTeapotWorld; // Add reflection transform. mTeapotWorld = mTeapotWorld * R; // Reflect light vector also. D3DXVECTOR3 oldLightVecW = mLightVecW; D3DXVec3TransformNormal(&mLightVecW, &mLightVecW, &R); HR(mFX->SetValue(mhLightVecW, &mLightVecW, sizeof(D3DXVECTOR3))); // Disable depth buffer and render the reflected teapot. HR(gd3dDevice->SetRenderState(D3DRS_ZENABLE, false)); HR(gd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false)); // Finally, draw the reflected teapot HR(gd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW)); drawTeapot(); mTeapotWorld = oldTeapotWorld; mLightVecW = oldLightVecW; // Restore render states. HR(gd3dDevice->SetRenderState(D3DRS_ZENABLE, true)); HR(gd3dDevice->SetRenderState( D3DRS_STENCILENABLE, false)); HR(gd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW)); }
void GateDemo::drawGate() { // Enable alpha test. HR(gd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, true)); HR(gd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL)); HR(gd3dDevice->SetRenderState(D3DRS_ALPHAREF, 100)); // Turn off backface culling so you can see both sides of the gate. HR(gd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE)); HR(mFX->SetValue(mhAmbientMtrl, &mGateMtrl.ambient, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhDiffuseMtrl, &mGateMtrl.diffuse, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhSpecularMtrl, &mGateMtrl.spec, sizeof(D3DXCOLOR))); HR(mFX->SetFloat(mhSpecularPower, mGateMtrl.specPower)); HR(mFX->SetMatrix(mhWVP, &(mGateWorld*mView*mProj))); D3DXMATRIX worldInvTrans; D3DXMatrixInverse(&worldInvTrans, 0, &mGateWorld); D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans); HR(mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans)); HR(mFX->SetMatrix(mhWorld, &mGateWorld)); HR(mFX->SetTexture(mhTex, mGateTex)); HR(gd3dDevice->SetVertexDeclaration(VertexPNT::Decl)); HR(gd3dDevice->SetStreamSource(0, mGateVB, 0, sizeof(VertexPNT))); HR(gd3dDevice->SetIndices(mGateIB)); // Begin passes. UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); for(UINT i = 0; i < numPasses; ++i) { HR(mFX->BeginPass(i)); HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2)); HR(mFX->EndPass()); } HR(mFX->End()); // Disable alpha test. HR(gd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false)); // Turn culling back on. HR(gd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW)); }
void SpotlightDemo::buildViewMtx() { float x = mCameraRadius * cosf(mCameraRotationY); float z = mCameraRadius * sinf(mCameraRotationY); D3DXVECTOR3 pos(x, mCameraHeight, z); D3DXVECTOR3 target(0.0f, 0.0f, 0.0f); D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&mView, &pos, &target, &up); HR(mFX->SetValue(mhEyePos, &pos, sizeof(D3DXVECTOR3))); // Spotlight position is the same as the camera position. HR(mFX->SetValue(mhLightPosW, &pos, sizeof(D3DXVECTOR3))); // Spotlight direction is the same as the camera forward direction. D3DXVECTOR3 lightDir = target - pos; D3DXVec3Normalize(&lightDir, &lightDir); HR(mFX->SetValue(mhLightDirW, &lightDir, sizeof(D3DXVECTOR3))); }
void XFileDemo::drawScene() { HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffeeeeee, 1.0f, 0)); HR(gd3dDevice->BeginScene()); HR(mFX->SetValue(mhLight, &mLight, sizeof(DirLight))); HR(mFX->SetMatrix(mhWVP, &(mWorld*mView*mProj))); D3DXMATRIX worldInvTrans; D3DXMatrixInverse(&worldInvTrans, 0, &mWorld); D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans); HR(mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans)); HR(mFX->SetMatrix(mhWorld, &mWorld)); HR(mFX->SetTechnique(mhTech)); UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); HR(mFX->BeginPass(0)); for (int j = 0; j < mMtrl.size(); ++j) { HR(mFX->SetValue(mhMtrl, &mMtrl[j], sizeof(Material))); if (mTex[j] != 0) { HR(mFX->SetTexture(mhTex, mTex[j])); } else { HR(mFX->SetTexture(mhTex, mWhiteTex)); } HR(mFX->CommitChanges()); HR(mMesh->DrawSubset(j)); } HR(mFX->EndPass()); HR(mFX->End()); mGfxStats->display(D3DCOLOR_XRGB(0,0,0)); HR(gd3dDevice->EndScene()); HR(gd3dDevice->Present(0, 0, 0, 0)); }
void MultiTexDemo::buildViewMtx() { float x = mCameraRadius * cosf(mCameraRotationY); float z = mCameraRadius * sinf(mCameraRotationY); D3DXVECTOR3 pos(x, mCameraHeight, z); D3DXVECTOR3 target(0.0f, 0.0f, 0.0f); D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&mView, &pos, &target, &up); HR(mFX->SetValue(mhEyePos, &pos, sizeof(D3DXVECTOR3))); }
void SphereCylDemo::drawCylinders() { HR(gd3dDevice->SetRenderState(D3DRS_WRAP0, D3DWRAP_U)); D3DXMATRIX T, R, W, WIT; D3DXMatrixRotationX(&R, -D3DX_PI*0.5f); HR(mFX->SetValue(mhAmbientMtrl, &mCylinderMtrl.ambient, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhDiffuseMtrl, &mCylinderMtrl.diffuse, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhSpecMtrl, &mCylinderMtrl.spec, sizeof(D3DXCOLOR))); HR(mFX->SetFloat(mhSpecPower, mCylinderMtrl.specPower)); HR(mFX->SetTexture(mhTex, mCylTex)); for(int z = -30; z <= 30; z+= 10) { D3DXMatrixTranslation(&T, -10.0f, 3.0f, (float)z); W = R*T; D3DXMatrixInverse(&WIT, 0, &W); D3DXMatrixTranspose(&WIT, &WIT); HR(mFX->SetMatrix(mhWVP, &(W*mView*mProj))); HR(mFX->SetMatrix(mhWorld, &W)); HR(mFX->SetMatrix(mhWorldInvTrans, &WIT)); HR(mFX->CommitChanges()); HR(mCylinder->DrawSubset(0)); D3DXMatrixTranslation(&T, 10.0f, 3.0f, (float)z); W = R*T; D3DXMatrixInverse(&WIT, 0, &W); D3DXMatrixTranspose(&WIT, &WIT); HR(mFX->SetMatrix(mhWVP, &(W*mView*mProj))); HR(mFX->SetMatrix(mhWorld, &W)); HR(mFX->SetMatrix(mhWorldInvTrans, &WIT)); HR(mFX->CommitChanges()); HR(mCylinder->DrawSubset(0)); } // Disable. HR(gd3dDevice->SetRenderState(D3DRS_WRAP0, 0)); }
void ProjTexDemo::drawScene() { HR(gd3dDevice->BeginScene()); // Draw sky first--this also replaces our gd3dDevice->Clear call. //mSky->draw(); HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0)); // Draw the scene mesh. HR(mFX->SetTechnique(mhTech)); HR(mFX->SetMatrix(mhWorldInvTrans, &mSceneWorld)); HR(mFX->SetMatrix(mhWorld, &mSceneWorld)); HR(mFX->SetValue(mhLight, &mLight, sizeof(SpotLight))); HR(mFX->SetMatrix(mhWVP, &(mSceneWorld*gCamera->viewProj()))); HR(mFX->SetValue(mhEyePosW, &gCamera->pos(), sizeof(D3DXVECTOR3))); HR(mFX->SetTexture(mhTex, mSkullTex)); HR(mFX->SetMatrix(mhLightWVP, &mLightWVP)); UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); HR(mFX->BeginPass(0)); for(UINT j = 0; j < mSceneMtrls.size(); ++j) { HR(mFX->SetValue(mhMtrl, &mSceneMtrls[j], sizeof(Mtrl))); HR(mFX->CommitChanges()); HR(mSceneMesh->DrawSubset(j)); } HR(mFX->EndPass()); HR(mFX->End()); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void SpotlightDemo::drawGrid() { HR(gd3dDevice->SetStreamSource(0, mVB, 0, sizeof(VertexPN))); HR(gd3dDevice->SetIndices(mIB)); HR(gd3dDevice->SetVertexDeclaration(VertexPN::Decl)); D3DXMATRIX W, WIT; D3DXMatrixIdentity(&W); D3DXMatrixInverse(&WIT, 0, &W); D3DXMatrixTranspose(&WIT, &WIT); HR(mFX->SetMatrix(mhWorld, &W)); HR(mFX->SetMatrix(mhWVP, &(W*mView*mProj))); HR(mFX->SetMatrix(mhWorldInvTrans, &WIT)); HR(mFX->SetValue(mhAmbientMtrl, &mGridMtrl.ambient, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhDiffuseMtrl, &mGridMtrl.diffuse, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhSpecMtrl, &mGridMtrl.spec, sizeof(D3DXCOLOR))); HR(mFX->SetFloat(mhSpecPower, mGridMtrl.specPower)); HR(mFX->CommitChanges()); HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, mNumGridVertices, 0, mNumGridTriangles)); }
void SpotlightDemo::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0)); HR(gd3dDevice->BeginScene()); // Setup the rendering FX HR(mFX->SetValue(mhAmbientLight, &mAmbientLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhDiffuseLight, &mDiffuseLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhSpecLight, &mSpecLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhAttenuation012, &mAttenuation012, sizeof(D3DXVECTOR3))); HR(mFX->SetFloat(mhSpotPower, mSpotPower)); // Begin passes. UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); for(UINT i = 0; i < numPasses; ++i) { HR(mFX->BeginPass(i)); drawGrid(); drawCylinders(); drawSpheres(); HR(mFX->EndPass()); } HR(mFX->End()); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void MultiTexDemo::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffeeeeee, 1.0f, 0)); HR(gd3dDevice->BeginScene()); // Setup the rendering FX HR(mFX->SetTechnique(mhTech)); HR(mFX->SetMatrix(mhWVP, &(mWorld*mView*mProj))); D3DXMATRIX worldInvTrans; D3DXMatrixInverse(&worldInvTrans, 0, &mWorld); D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans); HR(mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans)); HR(mFX->SetValue(mhLightVecW, &mLightVecW, sizeof(D3DXVECTOR3))); HR(mFX->SetValue(mhDiffuseMtrl, &mDiffuseMtrl, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhDiffuseLight, &mDiffuseLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhAmbientMtrl, &mAmbientMtrl, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhAmbientLight, &mAmbientLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhSpecularLight, &mSpecularLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhSpecularMtrl, &mSpecularMtrl, sizeof(D3DXCOLOR))); HR(mFX->SetFloat(mhSpecularPower, mSpecularPower)); HR(mFX->SetMatrix(mhWorld, &mWorld)); HR(mFX->SetTexture(mhTex0, mTex0)); HR(mFX->SetTexture(mhTex1, mTex1)); HR(mFX->SetTexture(mhTex2, mTex2)); HR(mFX->SetTexture(mhBlendMap, mBlendMap)); HR(gd3dDevice->SetVertexDeclaration(VertexPNT::Decl)); HR(gd3dDevice->SetStreamSource(0, mGridVB, 0, sizeof(VertexPNT))); HR(gd3dDevice->SetIndices(mGridIB)); // Begin passes. UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); for(UINT i = 0; i < numPasses; ++i) { HR(mFX->BeginPass(i)); HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, mNumGridVertices, 0, mNumGridTriangles)); HR(mFX->EndPass()); } HR(mFX->End()); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void GateDemo::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffeeeeee, 1.0f, 0)); HR(gd3dDevice->BeginScene()); // Setup the rendering FX HR(mFX->SetTechnique(mhTech)); HR(mFX->SetValue(mhLightVecW, &mLightVecW, sizeof(D3DXVECTOR3))); HR(mFX->SetValue(mhDiffuseLight, &mDiffuseLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhAmbientLight, &mAmbientLight, sizeof(D3DXCOLOR))); HR(mFX->SetValue(mhSpecularLight, &mSpecularLight, sizeof(D3DXCOLOR))); drawGround(); drawGate(); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void PropsDemo::drawObject(Object3D& obj, const D3DXMATRIX& toWorld) { // Transform AABB into the world space. AABB box; obj.box.xform(toWorld, box); // Only draw if AABB is visible. if( gCamera->isVisible( box ) ) { HR(mFX->SetMatrix(mhWVP, &(toWorld*gCamera->viewProj()))); D3DXMATRIX worldInvTrans; D3DXMatrixInverse(&worldInvTrans, 0, &toWorld); D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans); HR(mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans)); HR(mFX->SetMatrix(mhWorld, &toWorld)); for(UINT j = 0; j < obj.mtrls.size(); ++j) { HR(mFX->SetValue(mhMtrl, &obj.mtrls[j], sizeof(Mtrl))); // If there is a texture, then use. if(obj.textures[j] != 0) { HR(mFX->SetTexture(mhTex, obj.textures[j])); } // But if not, then set a pure white texture. When the texture color // is multiplied by the color from lighting, it is like multiplying by // 1 and won't change the color from lighting. else { HR(mFX->SetTexture(mhTex, mWhiteTex)); } HR(mFX->CommitChanges()); HR(obj.mesh->DrawSubset(j)); } } }
void PropsDemo::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff888888, 1.0f, 0)); HR(gd3dDevice->BeginScene()); HR(mFX->SetValue(mhEyePosW, &gCamera->pos(), sizeof(D3DXVECTOR3))); HR(mFX->SetTechnique(mhTech)); UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); HR(mFX->BeginPass(0)); drawObject(mCastle, mCastleWorld); // Use alpha test to block non leaf pixels from being rendered in the // trees (i.e., use alpha mask). HR(gd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, true)); HR(gd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL)); HR(gd3dDevice->SetRenderState(D3DRS_ALPHAREF, 200)); // Draw the trees: NUM_TREES/4 of each of the four types. for(int i = 0; i < NUM_TREES; ++i) { if( i < NUM_TREES/4 ) drawObject(mTrees[0], mTreeWorlds[i]); else if( i < 2*NUM_TREES/4 ) drawObject(mTrees[1], mTreeWorlds[i]); else if( i < 3*NUM_TREES/4 ) drawObject(mTrees[2], mTreeWorlds[i]); else drawObject(mTrees[3], mTreeWorlds[i]); } HR(gd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false)); HR(mFX->EndPass()); HR(mFX->End()); HR(mGrassFX->SetValue(mhGrassEyePosW, &gCamera->pos(), sizeof(D3DXVECTOR3))); HR(mGrassFX->SetMatrix(mhGrassViewProj, &(gCamera->viewProj()))); HR(mGrassFX->SetFloat(mhGrassTime, mTime)); HR(mGrassFX->Begin(&numPasses, 0)); HR(mGrassFX->BeginPass(0)); // Draw to depth buffer only. HR(mGrassMesh->DrawSubset(0)); HR(mGrassFX->EndPass()); HR(mGrassFX->End()); mTerrain->draw(); mWater->draw(); // draw alpha blended objects last. mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
void RobotArmDemo::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0)); HR(gd3dDevice->BeginScene()); HR(mFX->SetValue(mhLight, &mLight, sizeof(DirLight))); HR(mFX->SetTechnique(mhTech)); UINT numPasses = 0; HR(mFX->Begin(&numPasses, 0)); HR(mFX->BeginPass(0)); // Build the world transforms for each bone, then render them. buildBoneWorldTransforms(); D3DXMATRIX T; D3DXMatrixTranslation(&T, -NUM_BONES, 0.0f, 0.0f); for(int i = 0; i < NUM_BONES; ++i) { // Append the transformation with a slight translation to better // center the skeleton at the center of the scene. mWorld = mBones[i].toWorldXForm * T; HR(mFX->SetMatrix(mhWVP, &(mWorld*mView*mProj))); D3DXMATRIX worldInvTrans; D3DXMatrixInverse(&worldInvTrans, 0, &mWorld); D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans); HR(mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans)); HR(mFX->SetMatrix(mhWorld, &mWorld)); for(int j = 0; j < mMtrl.size(); ++j) { HR(mFX->SetValue(mhMtrl, &mMtrl[j], sizeof(Mtrl))); // If there is a texture, then use. if(mTex[j] != 0) { HR(mFX->SetTexture(mhTex, mTex[j])); } // But if not, then set a pure white texture. When the texture color // is multiplied by the color from lighting, it is like multiplying by // 1 and won't change the color from lighting. else { HR(mFX->SetTexture(mhTex, mWhiteTex)); } HR(mFX->CommitChanges()); HR(mBoneMesh->DrawSubset(j)); } } HR(mFX->EndPass()); HR(mFX->End()); mGfxStats->display(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }