//----------------------------------------------------------------------------- void CPUT_DX11::UpdatePerFrameConstantBuffer( double totalSeconds ) { if( mpPerFrameConstantBuffer ) { ID3D11Buffer *pBuffer = mpPerFrameConstantBuffer->GetNativeBuffer(); // update parameters of constant buffer D3D11_MAPPED_SUBRESOURCE mapInfo; mpContext->Map( pBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapInfo ); { // TODO: remove construction of XMM type CPUTFrameConstantBuffer *pCb = (CPUTFrameConstantBuffer*)mapInfo.pData; CPUTCamera *pCamera = gpSample->GetCamera(); if( pCamera ) { pCb->View = XMMATRIX((float*)pCamera->GetViewMatrix()); pCb->Projection = XMMATRIX((float*)pCamera->GetProjectionMatrix()); } pCb->LightColor = XMLoadFloat3(&XMFLOAT3((float*)&mLightColor)); // TODO: Get from light float totalSecondsFloat = (float)totalSeconds; pCb->TotalSeconds = XMLoadFloat(&totalSecondsFloat); pCb->AmbientColor = XMLoadFloat3(&XMFLOAT3((float*)&mAmbientColor)); } mpContext->Unmap(pBuffer,0); } }
// Set the render state before drawing this object //----------------------------------------------------------------------------- void CPUTModelDX11::UpdateShaderConstants(CPUTRenderParameters &renderParams) { ID3D11DeviceContext *pContext = ((CPUTRenderParametersDX*)&renderParams)->mpContext; D3D11_MAPPED_SUBRESOURCE mapInfo; pContext->Map( mpModelConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapInfo ); { CPUTModelConstantBuffer *pCb = (CPUTModelConstantBuffer*)mapInfo.pData; // TODO: remove construction of XMM type XMMATRIX world((float*)GetWorldMatrix()); pCb->World = world; CPUTCamera *pCamera = renderParams.mpCamera; XMVECTOR cameraPos = XMLoadFloat3(&XMFLOAT3( 0.0f, 0.0f, 0.0f )); if( pCamera ) { XMMATRIX view((float*)pCamera->GetViewMatrix()); XMMATRIX projection((float*)pCamera->GetProjectionMatrix()); float *pCameraPos = (float*)&pCamera->GetPosition(); cameraPos = XMLoadFloat3(&XMFLOAT3( pCameraPos[0], pCameraPos[1], pCameraPos[2] )); // Note: We compute viewProjection to a local to avoid reading from write-combined memory. // The constant buffer uses write-combined memory. We read this matrix when computing WorldViewProjection. // It is very slow to read it directly from the constant buffer. XMMATRIX viewProjection = view * projection; pCb->ViewProjection = viewProjection; pCb->WorldViewProjection = world * viewProjection; XMVECTOR determinant = XMMatrixDeterminant(world); pCb->InverseWorld = XMMatrixInverse(&determinant, XMMatrixTranspose(world)); } // TODO: Have the lights set their render states? XMVECTOR lightDirection = XMLoadFloat3(&XMFLOAT3( gLightDir.x, gLightDir.y, gLightDir.z )); pCb->LightDirection = XMVector3Normalize(lightDirection); pCb->EyePosition = cameraPos; float *bbCWS = (float*)&mBoundingBoxCenterWorldSpace; float *bbHWS = (float*)&mBoundingBoxHalfWorldSpace; float *bbCOS = (float*)&mBoundingBoxCenterObjectSpace; float *bbHOS = (float*)&mBoundingBoxHalfObjectSpace; pCb->BoundingBoxCenterWorldSpace = XMLoadFloat3(&XMFLOAT3( bbCWS[0], bbCWS[1], bbCWS[2] )); ; pCb->BoundingBoxHalfWorldSpace = XMLoadFloat3(&XMFLOAT3( bbHWS[0], bbHWS[1], bbHWS[2] )); ; pCb->BoundingBoxCenterObjectSpace = XMLoadFloat3(&XMFLOAT3( bbCOS[0], bbCOS[1], bbCOS[2] )); ; pCb->BoundingBoxHalfObjectSpace = XMLoadFloat3(&XMFLOAT3( bbHOS[0], bbHOS[1], bbHOS[2] )); ; // Shadow camera XMMATRIX shadowView, shadowProjection; CPUTCamera *pShadowCamera = gpSample->GetShadowCamera(); if( pShadowCamera ) { shadowView = XMMATRIX((float*)pShadowCamera->GetViewMatrix()); shadowProjection = XMMATRIX((float*)pShadowCamera->GetProjectionMatrix()); pCb->LightWorldViewProjection = world * shadowView * shadowProjection; } } pContext->Unmap(mpModelConstantBuffer,0); }
Box::Box(float x, float y, float z, XMVECTOR position, float mass, bool fixed, XMVECTOR orientation) { this->position = position; // its the center position of the box this->velocity = XMVectorSet(0.f, 0.f, 0.f, 0.f); length = XMVectorSet(x, y, z, 0.f); centerOfMass = Point(position, false); this->transform = XMMatrixTranslationFromVector(this->position); this->centerOfMass.fixed = fixed; this->orientation = XMQuaternionRotationRollPitchYawFromVector(orientation); if (fixed) { centerOfMass.mass = 1.0f; massInverse = 0.0f; intertiaTensorInverse = XMMATRIX(); } else { centerOfMass.mass = mass; massInverse = 1.0f / mass; float prefix = (1.0f / 12.0f) * centerOfMass.mass; XMMATRIX matrix = XMMATRIX(XMVectorSet(prefix*(y*y + z*z), 0.f, 0.f, 0.f), XMVectorSet(0.f, prefix * (x*x + z*z), 0.f, 0.f), XMVectorSet(0.f, 0.f, prefix*(x*x + y*y),0.f), XMVectorSet(0.f, 0.f, 0.f, 1.f)); intertiaTensorInverse = XMMatrixInverse(&XMMatrixDeterminant(matrix), matrix); } XMVECTOR xLength = XMVectorSet(x, 0.f, 0.f, 0.f) / 2; XMVECTOR yLength = XMVectorSet(0.f, y, 0.f, 0.f) / 2; XMVECTOR zLength = XMVectorSet(0.f, 0.f, z, 0.f) / 2; for (int i = 0; i < 8; i++) { corners[0] = XMVECTOR(); } this->angularMomentum = XMVECTOR(); this->angularVelocity = XMVECTOR(); this->torqueAccumulator = XMVECTOR(); corners[0] = -xLength - yLength - zLength; corners[1] = xLength - yLength - zLength; corners[2] = -xLength + yLength - zLength; corners[3] = xLength + yLength - zLength; corners[4] = -xLength - yLength + zLength; corners[5] = xLength - yLength + zLength; corners[6] = -xLength + yLength + zLength; corners[7] = xLength + yLength + zLength; }
void DemoApp::RenderMiniWindow() { //Set Buffers, Layout, Topology and Render States UINT stride = sizeof(Vertex::VertexPNT); UINT offset = 0; md3dImmediateContext->IASetVertexBuffers(0, 1, &m_pScreenQuadVB, &stride, &offset); md3dImmediateContext->IASetIndexBuffer(m_pScreenQuadIB, DXGI_FORMAT_R32_UINT, 0); md3dImmediateContext->IASetInputLayout(InputLayouts::VertexPNT); md3dImmediateContext->RSSetState(RenderStates::NoCullRS); //Resize mini window and translate to upper left corner XMMATRIX scale = XMMatrixScaling(1.0f / AspectRatio(), 1.0f, 1.0f); XMMATRIX world = XMMATRIX( 0.25f, 0.0f, 0.0f, 0.0f, 0.0f, 0.25f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.25 / AspectRatio() - 1, 0.75f, 0.0f, 1.0f); CBPerFrameScreenQuad cbScreenQuadPerFrame; cbScreenQuadPerFrame.wvp = XMMatrixTranspose(scale * world); md3dImmediateContext->UpdateSubresource(m_pCBPerFrameScreenQuad, 0, NULL, &cbScreenQuadPerFrame, 0, 0); md3dImmediateContext->VSSetShader(m_pDebugTextureVS, NULL, 0); md3dImmediateContext->VSSetConstantBuffers(0, 1, &m_pCBPerFrameScreenQuad); md3dImmediateContext->PSSetShader(m_pDebugTexturePS, NULL, 0); md3dImmediateContext->PSSetShaderResources(0, 1, &m_pDepthSRV); md3dImmediateContext->PSSetSamplers(0, 1, &m_pSampleLinear); md3dImmediateContext->DrawIndexed(6, 0, 0); }
void DemoApp::BuildShadowMapMatrices() { //Calculate the radius of the scene's bounding sphere. Approximately use the half of ground plane diagonal. float aabbRadius = sqrt(grndLength * grndLength + grndWidth * grndWidth) / 2.0f ; //Set up light parameter XMVECTOR lightDir = XMLoadFloat3(&mDirLight.Direction); XMVECTOR lightPos = -1.0f * lightDir * aabbRadius; XMFLOAT3 tar = XMFLOAT3(0.0f, 0.0f, 0.0f); XMVECTOR targetPos = XMLoadFloat3(&tar); XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); mLightView = XMMatrixLookAtLH(lightPos, targetPos, up); // Transform bounding sphere to light space. XMFLOAT3 aabbCenterLightSpace; XMStoreFloat3(&aabbCenterLightSpace, XMVector3TransformCoord(targetPos, mLightView)); //// Ortho frustum in light space encloses scene. float l = aabbCenterLightSpace.x - aabbRadius; float b = aabbCenterLightSpace.y - aabbRadius; float n = aabbCenterLightSpace.z - aabbRadius; float r = aabbCenterLightSpace.x + aabbRadius; float t = aabbCenterLightSpace.y + aabbRadius; float f = aabbCenterLightSpace.z + aabbRadius; mLightProj = XMMatrixOrthographicOffCenterLH(l, r, b, t, n, f); // Transform NDC space [-1,+1]^2 to texture space [0,1]^2 mLightViewport = XMMATRIX( 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.5f, 0.5f, 0.0f, 1.0f); mLightVPT = mLightView*mLightProj*mLightViewport; }
bool DX11ViewportRenderer::drawBounds( const MMatrix &matrix, const MBoundingBox &box, float color[3] ) { // Transform from object to world space // XMMATRIX mat = XMMATRIX ( (float)matrix.matrix[0][0], (float)matrix.matrix[0][1], (float)matrix.matrix[0][2], (float)matrix.matrix[0][3], (float)matrix.matrix[1][0], (float)matrix.matrix[1][1], (float)matrix.matrix[1][2], (float)matrix.matrix[1][3], (float)matrix.matrix[2][0], (float)matrix.matrix[2][1], (float)matrix.matrix[2][2], (float)matrix.matrix[2][3], (float)matrix.matrix[3][0], (float)matrix.matrix[3][1], (float)matrix.matrix[3][2], (float)matrix.matrix[3][3] ); // Adjust the unit cube to the bounds // MPoint minPt = box.min(); MPoint maxPt = box.max(); float minVal[3] = { (float)minPt.x, (float)minPt.y, (float)minPt.z }; float maxVal[3] = { (float)maxPt.x, (float)maxPt.y, (float)maxPt.z }; XMMATRIX bounds( 0.5f*(maxVal[0]-minVal[0]), 0.0f, 0.0f, 0.0f, 0.0f, 0.5f*(maxVal[1]-minVal[1]), 0.0f, 0.0f, 0.0f, 0.0f, 0.5f*(maxVal[2]-minVal[2]), 0.0f, 0.5f*(maxVal[0]+minVal[0]), 0.5f*(maxVal[1]+minVal[1]), 0.5f*(maxVal[2]+minVal[2]), 1.0f ); // Set vertex buffer UINT stride = sizeof( BoundsVertex ); UINT offset = 0; m_pD3DDeviceCtx->IASetVertexBuffers( 0, 1, &m_pBoundsVertexBuffer, &stride, &offset ); // Set index buffer m_pD3DDeviceCtx->IASetIndexBuffer( m_pBoundsIndexBuffer, DXGI_FORMAT_R16_UINT, 0 ); // Set constant buffer BoundsConstants cb; cb.fWVP = XMMatrixTranspose( bounds * mat * m_currentViewMatrix * m_currentProjectionMatrix ); cb.fDiffuseMaterial = XMFLOAT3( color[0], color[1], color[2] ); m_pD3DDeviceCtx->UpdateSubresource( m_pBoundsConstantBuffer, 0, NULL, &cb, 0, 0 ); // Set primitive topology m_pD3DDeviceCtx->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_LINELIST ); // get shader SurfaceEffectItemList::const_iterator it = m_resourceManager.getSurfaceEffectItemList().find( "Maya_unlit" ); if ( it == m_resourceManager.getSurfaceEffectItemList().end() ) return false; const SurfaceEffectItem* sei = it->second; // bind shaders m_pD3DDeviceCtx->VSSetShader( sei->fVertexShader, NULL, 0 ); m_pD3DDeviceCtx->VSSetConstantBuffers( 0, 1, &m_pBoundsConstantBuffer ); m_pD3DDeviceCtx->IASetInputLayout( sei->fInputLayout ); m_pD3DDeviceCtx->PSSetShader( sei->fPixelShader, NULL, 0 ); m_pD3DDeviceCtx->PSSetConstantBuffers( 0, 1, &m_pBoundsConstantBuffer ); // draw m_pD3DDeviceCtx->DrawIndexed( 24, 0, 0 ); return true; }
// Updates the cameras matrices void CCamera::UpdateViewMatrix() { if ((mSetting == ECameraSetting::FirstPerson || mSetting == ECameraSetting::ThirdPerson) && mParent == NULL) { mSetting = ECameraSetting::FreeRoam; } switch (mSetting) { case ECameraSetting::ThirdPerson: { // Add first and third person camera angles mWorldMat = mParent->GetMatrix( false ); mPos.x = mWorldMat._41; mPos.y = mWorldMat._42; mPos.z = mWorldMat._43; MoveLocalX( mOffset.x ); MoveY( mOffset.y ); MoveLocalZ( mOffset.z ); RotateLocalX( D3DXToRadian( 15 ) ); break; } case ECameraSetting::FirstPerson: { // Add first and third person camera angles mWorldMat = mParent->GetMatrix( false ); mPos.x = mWorldMat._41; mPos.y = mWorldMat._42; mPos.z = mWorldMat._43; MoveLocalX( mOffset.x ); MoveY( mOffset.y ); MoveLocalZ( mOffset.z ); break; } } if (mSetting != ECameraSetting::BirdsEye) { mWorldMat._41 = mPos.x; mWorldMat._42 = mPos.y; mWorldMat._43 = mPos.z; } // The rendering pipeline actually needs the inverse of the // camera world matrix - called the view matrix. XMVECTOR vector = XMVECTOR(); CXMMATRIX world = XMMATRIX( mWorldMat ); mView = XMMatrixInverse( &vector, world ); }
bool DX11ViewportRenderer::setupMatrices( const MRenderingInfo &info ) // // Description: // // Set up camera matrices. Mechanism to check for changes in camera // parameters should be done before matrix setup. // // Note that we *must* use a "right-handed" system (RH method // versions) for computations to match what is coming from Maya. // { if (!m_pD3DDevice || !m_pD3DDeviceCtx) return false; // set up the viewport D3D11_VIEWPORT vp; vp.Width = (float)m_renderWidth; vp.Height = (float)m_renderHeight; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; vp.TopLeftX = 0; vp.TopLeftY = 0; m_pD3DDeviceCtx->RSSetViewports( 1, &vp ); const MMatrix & view = info.viewMatrix(); const MMatrix & projection = info.projectionMatrix(); // Double to float conversion m_currentViewMatrix = XMMATRIX( (float)view.matrix[0][0], (float)view.matrix[0][1], (float)view.matrix[0][2], (float)view.matrix[0][3], (float)view.matrix[1][0], (float)view.matrix[1][1], (float)view.matrix[1][2], (float)view.matrix[1][3], (float)view.matrix[2][0], (float)view.matrix[2][1], (float)view.matrix[2][2], (float)view.matrix[2][3], (float)view.matrix[3][0], (float)view.matrix[3][1], (float)view.matrix[3][2], (float)view.matrix[3][3]); m_currentProjectionMatrix = XMMATRIX( (float)projection.matrix[0][0], (float)projection.matrix[0][1], (float)projection.matrix[0][2], (float)projection.matrix[0][3], (float)projection.matrix[1][0], (float)projection.matrix[1][1], (float)projection.matrix[1][2], (float)projection.matrix[1][3], (float)projection.matrix[2][0], (float)projection.matrix[2][1], (float)projection.matrix[2][2], (float)projection.matrix[2][3], (float)projection.matrix[3][0], (float)projection.matrix[3][1], (float)projection.matrix[3][2], (float)projection.matrix[3][3]); return true; }
void GuardianSystemDemo::Render() { // Get current eye pose for rendering double eyePoseTime = 0; ovrPosef eyePose[ovrEye_Count] = {}; ovr_GetEyePoses(mSession, mFrameIndex, ovrTrue, mHmdToEyeOffset, eyePose, &eyePoseTime); // Render each eye for (int i = 0; i < ovrEye_Count; ++i) { int renderTargetIndex = 0; ovr_GetTextureSwapChainCurrentIndex(mSession, mTextureChain[i], &renderTargetIndex); ID3D11RenderTargetView* renderTargetView = mEyeRenderTargets[i][renderTargetIndex]; ID3D11DepthStencilView* depthTargetView = mEyeDepthTarget[i]; // Clear and set render/depth target and viewport DIRECTX.SetAndClearRenderTarget(renderTargetView, depthTargetView, 0.2f, 0.2f, 0.2f, 1.0f); DIRECTX.SetViewport((float)mEyeRenderViewport[i].Pos.x, (float)mEyeRenderViewport[i].Pos.y, (float)mEyeRenderViewport[i].Size.w, (float)mEyeRenderViewport[i].Size.h); // Eye XMVECTOR eyeRot = XMVectorSet(eyePose[i].Orientation.x, eyePose[i].Orientation.y, eyePose[i].Orientation.z, eyePose[i].Orientation.w); XMVECTOR eyePos = XMVectorSet(eyePose[i].Position.x, eyePose[i].Position.y, eyePose[i].Position.z, 0); XMVECTOR eyeForward = XMVector3Rotate(XMVectorSet(0, 0, -1, 0), eyeRot); // Matrices XMMATRIX viewMat = XMMatrixLookAtRH(eyePos, XMVectorAdd(eyePos, eyeForward), XMVector3Rotate(XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f), eyeRot)); ovrMatrix4f proj = ovrMatrix4f_Projection(mEyeRenderLayer.Fov[i], 0.001f, 1000.0f, ovrProjection_None); XMMATRIX projMat = XMMatrixTranspose(XMMATRIX(&proj.M[0][0])); XMMATRIX viewProjMat = XMMatrixMultiply(viewMat, projMat); // Render and commit to swap chain mDynamicScene.Render(&viewProjMat, 1.0f, 1.0f, 1.0f, 1.0f, true); ovr_CommitTextureSwapChain(mSession, mTextureChain[i]); // Update eye layer mEyeRenderLayer.ColorTexture[i] = mTextureChain[i]; mEyeRenderLayer.RenderPose[i] = eyePose[i]; mEyeRenderLayer.SensorSampleTime = eyePoseTime; } // Submit frames ovrLayerHeader* layers = &mEyeRenderLayer.Header; ovrResult result = ovr_SubmitFrame(mSession, mFrameIndex++, nullptr, &layers, 1); if (!OVR_SUCCESS(result)) { printf("ovr_SubmitFrame failed"); exit(-1); } }
void DX11::MultMatrix(const float m[16]) { if (s_matrixMode == DX11_MODELVIEW_MATRIX) { g_View = XMMATRIX(m) * g_View; // TODO Check this } else if (s_matrixMode == DX11_PROJECTION_MATRIX) { assert(0); } else { assert(0); } }
bool DX11ViewportRenderer::drawSurface( const MDagPath &dagPath, bool active, bool templated) { bool drewSurface = false; if ( !dagPath.hasFn( MFn::kMesh )) { MMatrix matrix = dagPath.inclusiveMatrix(); MFnDagNode dagNode(dagPath); MBoundingBox box = dagNode.boundingBox(); float color[3] = {0.6f, 0.3f, 0.0f}; if (active) { color[0] = 1.0f; color[1] = 1.0f; color[2] = 1.0f; } else if (templated) { color[0] = 1.0f; color[1] = 0.686f; color[2] = 0.686f; } drawBounds( matrix, box, color); return true; } if ( dagPath.hasFn( MFn::kMesh )) { MMatrix matrix = dagPath.inclusiveMatrix(); MFnDagNode dagNode(dagPath); // Look for any hardware shaders which can draw D3D first. // bool drewWithHwShader = false; { MFnMesh fnMesh(dagPath); MObjectArray sets; MObjectArray comps; unsigned int instanceNum = dagPath.instanceNumber(); if (!fnMesh.getConnectedSetsAndMembers(instanceNum, sets, comps, true)) MGlobal::displayError("ERROR : MFnMesh::getConnectedSetsAndMembers"); for ( unsigned i=0; i<sets.length(); i++ ) { MObject set = sets[i]; MObject comp = comps[i]; MStatus status; MFnSet fnSet( set, &status ); if (status == MS::kFailure) { MGlobal::displayError("ERROR: MFnSet::MFnSet"); continue; } MObject shaderNode = findShader(set); if (shaderNode != MObject::kNullObj) { MPxHardwareShader * hwShader = MPxHardwareShader::getHardwareShaderPtr( shaderNode ); if (hwShader) { const MRenderProfile & profile = hwShader->profile(); if (profile.hasRenderer( MRenderProfile::kMayaD3D)) { // Render a Maya D3D hw shader here.... //printf("Found a D3D hw shader\n"); //drewWithHwShader = true; } } } } } // Get the geometry buffers for this bad boy and render them D3DGeometry* Geometry = m_resourceManager.getGeometry( dagPath, m_pD3DDevice); if( Geometry) { // Transform from object to world space // XMMATRIX objectToWorld = XMMATRIX ( (float)matrix.matrix[0][0], (float)matrix.matrix[0][1], (float)matrix.matrix[0][2], (float)matrix.matrix[0][3], (float)matrix.matrix[1][0], (float)matrix.matrix[1][1], (float)matrix.matrix[1][2], (float)matrix.matrix[1][3], (float)matrix.matrix[2][0], (float)matrix.matrix[2][1], (float)matrix.matrix[2][2], (float)matrix.matrix[2][3], (float)matrix.matrix[3][0], (float)matrix.matrix[3][1], (float)matrix.matrix[3][2], (float)matrix.matrix[3][3] ); FixedFunctionConstants cb; if (!drewWithHwShader) { // Get material properties for shader associated with mesh // // 1. Try to draw with the sample internal programmable shader bool drewGeometryWithShader = false; // 2. Draw with fixed function shader if (!drewGeometryWithShader) { // Set up a default material, just in case there is none. // float diffuse[3]; if (active) { if (templated) { m_pD3DDeviceCtx->RSSetState( m_pWireframeRS ); diffuse[0] = 1.0f; diffuse[1] = 0.686f; diffuse[2] = 0.686f; } else { m_pD3DDeviceCtx->RSSetState( m_pNormalRS ); diffuse[0] = 0.6f; diffuse[1] = 0.6f; diffuse[2] = 0.6f; } } else { if (templated) { m_pD3DDeviceCtx->RSSetState( m_pWireframeRS ); diffuse[0] = 1.0f; diffuse[1] = 0.686f; diffuse[2] = 0.686f; } else { m_pD3DDeviceCtx->RSSetState( m_pNormalRS ); diffuse[0] = 0.5f; diffuse[1] = 0.5f; diffuse[2] = 0.5f; } } // Set constant buffer XMVECTOR det; cb.wvIT = XMMatrixInverse( &det, objectToWorld * m_currentViewMatrix ); cb.wvp = XMMatrixTranspose( objectToWorld * m_currentViewMatrix * m_currentProjectionMatrix ); cb.wv = XMMatrixTranspose( objectToWorld * m_currentViewMatrix ); cb.lightDir = XMFLOAT4( 0.0f, 0.0f, 1.0f, 0.0f ); cb.lightColor = XMFLOAT4( 1.0f, 1.0f, 1.0f, 0.0f ); cb.ambientLight = XMFLOAT4( 0.2f, 0.2f, 0.2f, 0.0f ); cb.diffuseMaterial = XMFLOAT4( diffuse[0], diffuse[1], diffuse[2], 0.0f ); cb.specularColor = XMFLOAT4( 0.2f, 0.2f, 0.2f, 0.0f ); cb.diffuseCoeff = 1.0f; cb.shininess = 16.0f; cb.transparency = 1.0f; m_pD3DDeviceCtx->UpdateSubresource( m_pFixedFunctionConstantBuffer, 0, NULL, &cb, 0, 0 ); // get shader SurfaceEffectItemList::const_iterator it = m_resourceManager.getSurfaceEffectItemList().find( "Maya_fixedFunction" ); if ( it == m_resourceManager.getSurfaceEffectItemList().end() ) return false; const SurfaceEffectItem* sei = it->second; // bind shaders m_pD3DDeviceCtx->VSSetShader( sei->fVertexShader, NULL, 0 ); m_pD3DDeviceCtx->VSSetConstantBuffers( 0, 1, &m_pFixedFunctionConstantBuffer ); m_pD3DDeviceCtx->IASetInputLayout( sei->fInputLayout ); m_pD3DDeviceCtx->PSSetShader( sei->fPixelShader, NULL, 0 ); m_pD3DDeviceCtx->PSSetConstantBuffers( 0, 1, &m_pFixedFunctionConstantBuffer ); Geometry->Render( m_pD3DDeviceCtx ); drewSurface = true; } } // Draw wireframe on top // if ( drewSurface && active ) { bool drawActiveWithBounds = false; if (drawActiveWithBounds) { MBoundingBox box = dagNode.boundingBox(); float color[3] = {1.0f, 1.0f, 1.0f}; drawBounds( matrix, box, color ); } else { cb.lightColor = XMFLOAT4( 0.0f, 0.0f, 0.0f, 0.0f ); cb.ambientLight = XMFLOAT4( 1.0f, 1.0f, 1.0f, 0.0f ); cb.diffuseMaterial = XMFLOAT4( 1.0f, 1.0f, 1.0f, 0.0f ); cb.specularColor = XMFLOAT4( 0.0f, 0.0f, 0.0f, 0.0f ); m_pD3DDeviceCtx->UpdateSubresource( m_pFixedFunctionConstantBuffer, 0, NULL, &cb, 0, 0 ); m_pD3DDeviceCtx->RSSetState( m_pWireframeRS ); Geometry->Render( m_pD3DDeviceCtx ); } } } // If Geometry } return drewSurface; }