void Effect::SetParam(const string& name, const Matrix& data) { auto it = matrixVars.find(name); _ASSERT(it != matrixVars.end()); ID3DX11EffectMatrixVariable* matrixVar = it->second; DXCall(matrixVar->SetMatrix((const F32*) &data)); }
void Effect::AddVariable(ID3DX11EffectVariable* var, const D3DX11_EFFECT_VARIABLE_DESC* varDesc, const D3DX11_EFFECT_TYPE_DESC* typeDesc) { _ASSERT(var && varDesc && typeDesc); switch (typeDesc->Class) { case D3D_SVC_SCALAR : { ID3DX11EffectScalarVariable* scalarVar = var->AsScalar(); _ASSERT(scalarVar->IsValid()); scalarVars[varDesc->Name] = scalarVar; break; } case D3D_SVC_VECTOR : { ID3DX11EffectVectorVariable* vectorVar = var->AsVector(); _ASSERT(vectorVar->IsValid()); vectorVars[varDesc->Name] = vectorVar; break; } case D3D_SVC_MATRIX_COLUMNS: case D3D_SVC_MATRIX_ROWS: { ID3DX11EffectMatrixVariable* matrixVar = var->AsMatrix(); _ASSERT(matrixVar->IsValid()); matrixVars[varDesc->Name] = matrixVar; break; } case D3D_SVC_STRUCT: structVars[varDesc->Name] = var; break; case D3D_SVC_OBJECT: { ID3DX11EffectShaderResourceVariable* resourceVar = var->AsShaderResource(); if (resourceVar->IsValid()) { resourceVars[varDesc->Name] = resourceVar; } break; } default: _ASSERT(false); } }
void Effect::SetParam(const string& name, const Matrix* data, U32 offset, U32 count) { auto it = matrixVars.find(name); _ASSERT(it != matrixVars.end()); ID3DX11EffectMatrixVariable* matrixVar = it->second; DXCall(matrixVar->SetMatrixArray((const F32*) data->v, offset, count)); }
void DrawDepthMaterial::SetMeshInstanceState(const MeshInstance* meshInstance) const { ID3DX11EffectMatrixVariable* mvp = effect->GetVariableByName("transformMatrix")->AsMatrix(); mvp->SetMatrix(transform); effect->GetVariableByName("texDimensions")->SetRawValue(texDimensions, 0, sizeof(float)*2); ID3DX11EffectShaderResourceVariable* shaderResource = effect->GetVariableByName("depthTexture")->AsShaderResource(); shaderResource->SetResource(texture->GetShaderResourceView()); }
void DX11Shader::setMatrix(const char* strName, glm::mat4x4 Matrix) { ID3DX11EffectMatrixVariable* pMatrixVariable; pMatrixVariable = m_pEffect->pEffect->GetVariableByName(strName)->AsMatrix(); if (pMatrixVariable->IsValid()) { pMatrixVariable->SetMatrix(glm::value_ptr(Matrix)); } else { EventManager::Instance().postMessage("Unknown matrix variable: %s in shader: %s", strName, m_pEffect->strName); } }
void BoxApp::DrawScene() { md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::LightSteelBlue)); md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0); md3dImmediateContext->IASetInputLayout(mInputLayout); md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); // Press the Left Mouse Button to activate Wireframe mode, a simple if statement was made to show both work if (GetAsyncKeyState(VK_LBUTTON)){ md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP); } UINT stride = sizeof(Vertex); UINT offset = 0; md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset); md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0); // Set constants XMMATRIX world = XMLoadFloat4x4(&mWorld); XMMATRIX view = XMLoadFloat4x4(&mView); XMMATRIX proj = XMLoadFloat4x4(&mProj); XMMATRIX worldViewProj = world*view*proj; XMMATRIX viewProj = view*proj; mfxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&worldViewProj)); D3DX11_TECHNIQUE_DESC techDesc; mTech->GetDesc( &techDesc ); for(UINT p = 0; p < techDesc.Passes; ++p) { mTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext); // 114 indices for the box and Octagonal. md3dImmediateContext->DrawIndexed(2048, 0, 0); for (int i = 0; i < 5; ++i) { world = XMLoadFloat4x4(&mCylWorld[i]); mfxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&(world*viewProj))); mTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext); md3dImmediateContext->DrawIndexed(mCylinderIndexCount, mCylinderIndexOffset, mCylinderVertexOffset); } } HR(mSwapChain->Present(0, 0)); }
void EffectSystemD3D11::UpdateMatrix(int effectID, const char *name, const void *data) { ASSERT_EFFECT(effectID); ID3DX11EffectMatrixVariable *variable = nullptr; variable = mEffects[effectID]->GetVariableByName(name)->AsMatrix(); if (variable->IsValid()) { variable->SetMatrix((float*)data); } else { LogSystem::GetInstance().Log("effect matrix「%s」非法", name); return; } }
void BoxApp::DrawScene() { md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::LightSteelBlue)); md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0); md3dImmediateContext->IASetInputLayout(mInputLayout); md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); UINT stride = sizeof(Vertex); UINT offset = 0; md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset); md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0); // Set constants XMMATRIX world = XMLoadFloat4x4(&mWorld); XMMATRIX view = XMLoadFloat4x4(&mView); XMMATRIX proj = XMLoadFloat4x4(&mProj); XMMATRIX worldViewProj = world*view*proj; mfxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&worldViewProj)); D3DX11_TECHNIQUE_DESC techDesc; mTech->GetDesc( &techDesc ); for(UINT p = 0; p < techDesc.Passes; ++p) { mTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext); // 36 indices for the box. md3dImmediateContext->DrawIndexed(36, 0, 0); } HR(mSwapChain->Present(0, 0)); }
void TestMaterial::SetMeshInstanceState(const MeshInstance* meshInstance) const { float4x4 mvp; if (meshInstance) { float4x4 meshTransform = meshInstance->GetTransformMatrix(); matrix4x4 tr = DirectX::XMLoadFloat4x4(&meshTransform); matrix4x4 pr = DirectX::XMLoadFloat4x4(&projection); pr = DirectX::XMMatrixMultiply(tr, pr); DirectX::XMStoreFloat4x4(&mvp, pr); ID3DX11EffectMatrixVariable* mvpVar = effect->GetVariableByName("gWorldViewProj")->AsMatrix(); mvpVar->SetMatrix((float*)&mvp); } if (texture != 0) { ID3DX11EffectShaderResourceVariable* shaderResource = effect->GetVariableByName("diffuseTexture")->AsShaderResource(); shaderResource->SetResource(texture->GetShaderResourceView()); } }
void h2GBufferDebugDraw::RenderGBuffer() { m_Renderer->m_D3d11ImmediateContext->ClearDepthStencilView( m_Renderer->m_DepthBufferDSV, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0 ); m_Renderer->m_D3d11ImmediateContext->IASetInputLayout( m_PosTexLayout ); m_Renderer->m_D3d11ImmediateContext->OMSetRenderTargets( 1, &m_Renderer->m_BackbufferRTV, m_Renderer->m_DepthBufferDSV ); ID3DX11EffectShaderResourceVariable * fxTexSamplerVar; fxTexSamplerVar = m_Fx->GetVariableByName( "texSampler" )->AsShaderResource(); fxTexSamplerVar->SetResource( m_Renderer->m_GBuffer->GetBufferByType( m_CurrentBuffer )->m_SRV ); unsigned int stride = sizeof( h2RenderingEngine::vertexPosTex_t ); unsigned int offset = 0; m_Renderer->m_D3d11ImmediateContext->IASetVertexBuffers( 0, 1, &m_Renderer->m_FullScrQuadVB, &stride, &offset ); const h2SceneObject * cameraObj = h2Engine::GetScene()->GetMainCamera(); const h2Camera * camera = static_cast<h2Camera *>( cameraObj->GetComponent( "h2Camera" ) ); h2Matrix44 projMatrix = h2Matrix44::OrthographicD3D( m_Renderer->m_Width, m_Renderer->m_Height, camera->zNear, camera->zFar ); ID3DX11EffectMatrixVariable * fxPVar = m_Fx->GetVariableByName( "orthoProjection" )->AsMatrix(); fxPVar->SetMatrix( projMatrix.GetDataPtr() ); ID3DX11EffectTechnique * tech = nullptr; switch ( m_CurrentBuffer ) { case DEPTH_BUFFER: tech = m_Fx->GetTechniqueByName( "DepthBufferDebugDrawTech" ); break; case NORMAL_BUFFER: tech = m_Fx->GetTechniqueByName( "NormalBufferDebugDrawTech" ); break; } ID3DX11EffectPass * pass = tech->GetPassByIndex( 0 ); pass->Apply( 0, m_Renderer->m_D3d11ImmediateContext ); m_Renderer->m_D3d11ImmediateContext->Draw( 6, 0 ); ID3D11ShaderResourceView * emptySRV = nullptr; m_Renderer->m_D3d11ImmediateContext->PSSetShaderResources(0, 1, &emptySRV); }
void UIDisplay::drawUI( ID3D11DeviceContext* device ) { //Setup temp vars uint stride = sizeof(FontVertex); uint offset = 0; device->IASetInputLayout( mInputLayout ); device->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); //Set vertex and index buffers device->IASetVertexBuffers( 0, 1, &mVB, &stride, &offset ); device->IASetIndexBuffer( mIB, DXGI_FORMAT_R16_UINT, offset ); ID3DX11EffectShaderResourceVariable* mfxTex = mFX->GetVariableByName("uiTexture")->AsShaderResource(); mfxTex->SetResource(mTexture); XMMATRIX world = XMMatrixIdentity(); ID3DX11EffectMatrixVariable* mfxWorld = mFX->GetVariableByName("gWorld")->AsMatrix(); mfxWorld->SetMatrix(reinterpret_cast<float*>(&world)); int indices = ( mVertsGenerated / 4 ) * 6; D3DX11_TECHNIQUE_DESC techDesc; mTechnique->GetDesc( &techDesc ); for(ushort p = 0; p < techDesc.Passes; ++p) { mTechnique->GetPassByIndex(p)->Apply(0, device); if( mVertsGenerated > 0 ) { //Draw the verts we generated wooo device->DrawIndexed( indices, 0, 0 ); } } mVertsGenerated = 0; }
void D3DRenderer::DrawScene() { std::vector<packedBufferData> sceneData = mBufferManager->GrabSceneBuffers(); float bgColor[4] = {0.69f, 0.77f, 0.87f, 1.0f}; mDeviceContext->ClearRenderTargetView(mRenderTargetView, bgColor); mDeviceContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0); mDeviceContext->IASetInputLayout(mInputLayout); mDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); if (setWireframe) { mDeviceContext->RSSetState(mRSD); } ID3DX11EffectMatrixVariable* mEffectWorldViewProj = mEffect->GetVariableByName("gWorldViewProj")->AsMatrix(); D3DX11_TECHNIQUE_DESC techDesc; mETech->GetDesc(&techDesc); UINT stride = sizeof(Vertex); UINT offset = 0; for(UINT p = 0 ; p < techDesc.Passes ; ++p) { for (UINT i = 0 ; i < sceneData.size() ; ++i) { mDeviceContext->IASetVertexBuffers(0, 1, &sceneData[i].bufferContents.vertexBuffer, &stride, &offset); mDeviceContext->IASetIndexBuffer(sceneData[i].bufferContents.indexBuffer , DXGI_FORMAT_R32_UINT, 0); XMMATRIX wvpMatrix = BuildWVPMatrix(sceneData[i].owningEntity->localToWorld, mCamViewMatrix, mProjMatrix); mEffectWorldViewProj->SetMatrix(reinterpret_cast<float*>(&wvpMatrix)); mETech->GetPassByIndex(p)->Apply(0, mDeviceContext); mDeviceContext->DrawIndexed(sceneData[i].bufferContents.iCount, 0, 0); } } mSwapChain->Present(0,0); }
void InitDirect3DApp::DrawScene() { assert(md3dImmediateContext); assert(mSwapChain); // Clear all the old stuff before rendering the new stuff md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::LightSteelBlue)); md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0); // Set the input layout for vertices before drawing md3dImmediateContext->IASetInputLayout(inputLayout); md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); UINT stride = sizeof(Vertex); UINT offset = 0; md3dImmediateContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset); md3dImmediateContext->IASetIndexBuffer(indexBuffer, DXGI_FORMAT_R32_UINT, offset); // Update the worldViewProjMtx and set up XMMATRIX worldViewProjMtx = worldMtx * viewMtx * projMtx; worldViewProj->SetMatrix(reinterpret_cast<float*>(&worldViewProjMtx)); // Draw the indices D3DX11_TECHNIQUE_DESC techniqueDesc; technique->GetDesc(&techniqueDesc); for (unsigned int i = 0; i < techniqueDesc.Passes; ++i) { technique->GetPassByIndex(i)->Apply(0, md3dImmediateContext); md3dImmediateContext->DrawIndexed(36, 0, 0); } // Present the back buffer to the screen HR(mSwapChain->Present(0, 0)); }
void SetMatrices(BaseCamera* pCam, const D3DXMATRIX& mProj) { D3DXMATRIX mView; memcpy(&mView, pCam->getViewMatrix(), sizeof(float) * 16); // Set matrices D3DXMATRIX mWorld, mScale, mTrans; D3DXMatrixScaling(&mScale, WORLD_SCALE, WORLD_SCALE, WORLD_SCALE); // We keep the eye centered in the middle of the tile rings. The height map scrolls in the horizontal // plane instead. D3DXVECTOR3 eye; pCam->getFrom(&eye[0]); float snappedX = eye.x, snappedZ = eye.z; if (SNAP_GRID_SIZE > 0) { snappedX = floorf(snappedX / SNAP_GRID_SIZE) * SNAP_GRID_SIZE; snappedZ = floorf(snappedZ / SNAP_GRID_SIZE) * SNAP_GRID_SIZE; } const float dx = eye.x - snappedX; const float dz = eye.z - snappedZ; snappedX = eye.x - 2*dx; // Why the 2x? I'm confused. But it works. snappedZ = eye.z - 2*dz; D3DXMatrixTranslation(&mTrans, snappedX, 0, snappedZ); D3DXMatrixMultiply(&mWorld, &mScale, &mTrans); ID3DX11EffectMatrixVariable* pmWorldViewProj = g_pTerrainEffect->GetVariableByName("g_WorldViewProj")->AsMatrix(); ID3DX11EffectMatrixVariable* pmProj = g_pTerrainEffect->GetVariableByName("g_Proj")->AsMatrix(); ID3DX11EffectMatrixVariable* pmWorldViewProjLOD = g_pTerrainEffect->GetVariableByName("g_WorldViewProjLOD")->AsMatrix(); ID3DX11EffectMatrixVariable* pmWorldViewLOD = g_pTerrainEffect->GetVariableByName("g_WorldViewLOD")->AsMatrix(); assert(pmProj->IsValid()); assert(pmWorldViewProj->IsValid()); assert(pmWorldViewProjLOD->IsValid()); assert(pmWorldViewLOD->IsValid()); D3DXMATRIX mWorldView = mWorld * mView; D3DXMATRIX mWorldViewProj = mWorldView * mProj; pmWorldViewProj->SetMatrix((float*) &mWorldViewProj); pmProj->SetMatrix((float*) &mProj); // For LOD calculations, we always use the master camera's view matrix. D3DXMATRIX mWorldViewLOD = mWorld * mView; D3DXMATRIX mWorldViewProjLOD = mWorldViewLOD * mProj; pmWorldViewProjLOD->SetMatrix((float*) &mWorldViewProjLOD); pmWorldViewLOD->SetMatrix((float*) &mWorldViewLOD); // Due to the snapping tricks, the centre of projection moves by a small amount in the range ([0,2*dx],[0,2*dz]) // relative to the terrain. For frustum culling, we need this eye position. D3DXVECTOR3 cullingEye = eye; cullingEye.x -= snappedX; cullingEye.z -= snappedZ; g_pEyePosVar->SetFloatVector(cullingEye); g_pViewDirVar->SetFloatVector((float*)&mView._31); }
void WavesApp::DrawScene() { assert(m_pD3dImmediateContext); assert(m_pSwapChain); m_pD3dImmediateContext->ClearRenderTargetView(m_pRenderTargetView, reinterpret_cast<const float *>(&Colors::LightSteelBlue)); m_pD3dImmediateContext->ClearDepthStencilView(m_pDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); //设置顶点输入数据流格式 m_pD3dImmediateContext->IASetInputLayout(m_pInputLayout); //设置顶点拼装方式 m_pD3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); UINT stride = sizeof(Vertex); UINT offset = 0; //Update Constants before drawcall XMMATRIX view = XMLoadFloat4x4(&m_viewMatrix); XMMATRIX proj = XMLoadFloat4x4(&m_projMaxtrix); //Draw all the passes D3DX11_TECHNIQUE_DESC techDesc; m_pShaderTech->GetDesc(&techDesc); for (UINT i = 0; i < techDesc.Passes;++i) { { // //Draw the land. // m_pD3dImmediateContext->IASetVertexBuffers(0, 1, &m_pLandVB, &stride, &offset); m_pD3dImmediateContext->IASetIndexBuffer(m_pLandIB, DXGI_FORMAT_R32_UINT, 0); XMMATRIX world = XMLoadFloat4x4(&m_GridWorldMatrix); XMMATRIX worldViewProj = world*view*proj; m_pShaderMVP->SetMatrix(reinterpret_cast<float *>(&worldViewProj)); m_pShaderTech->GetPassByIndex(i)->Apply(0, m_pD3dImmediateContext);//首参数无意义,已被放弃 m_pD3dImmediateContext->DrawIndexed(m_uLandGridIndexCount, 0, 0); } { // //Draw the Waves. // m_pD3dImmediateContext->RSSetState(m_pWireframeRS); m_pD3dImmediateContext->IASetVertexBuffers(0, 1, &m_pWavesVB, &stride, &offset); m_pD3dImmediateContext->IASetIndexBuffer(m_pWavesIB, DXGI_FORMAT_R32_UINT, 0); XMMATRIX world = XMLoadFloat4x4(&m_WavesWorldMatrix); XMMATRIX worldViewProj = world*view*proj; m_pShaderMVP->SetMatrix(reinterpret_cast<float *>(&worldViewProj)); m_pShaderTech->GetPassByIndex(i)->Apply(0, m_pD3dImmediateContext);//首参数无意义,已被放弃 m_pD3dImmediateContext->DrawIndexed(3 * m_waves.GetTriangleCount(), 0, 0); m_pD3dImmediateContext->RSSetState(nullptr); } } HR(m_pSwapChain->Present(0,0)); }
void Ass3::DrawScene() { timer--;; if (timer <= 0) { if (GetAsyncKeyState('Q') && sliceCount > 3) { sliceCount--; timer = 200; BuildGeometryBuffers(); } else if (GetAsyncKeyState('E') && sliceCount < 500) { sliceCount++; timer = 200; BuildGeometryBuffers(); } else if (GetAsyncKeyState('W') && cylinderHeight < 2) { cylinderHeight += 0.2f; timer = 200; BuildGeometryBuffers(); } else if (GetAsyncKeyState('S') && cylinderHeight > 0.4f) { cylinderHeight -= 0.2f; timer = 200; BuildGeometryBuffers(); } else if (GetAsyncKeyState('A') && cylinderRadius > 0.4f) { cylinderRadius -= 0.2f; timer = 200; BuildGeometryBuffers(); } else if (GetAsyncKeyState('D') && cylinderRadius < 2) { cylinderRadius += 0.2f; timer = 200; BuildGeometryBuffers(); } } md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::LightSteelBlue)); md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0); md3dImmediateContext->IASetInputLayout(mInputLayout); md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); //apply wireframe resterizer state if (wframe) { md3dImmediateContext->RSSetState(mWireframeRS); } UINT stride = sizeof(Vertex); UINT offset = 0; md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset); md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0); // Set constants XMMATRIX world = XMLoadFloat4x4(&mWorld); XMMATRIX view = XMLoadFloat4x4(&mView); XMMATRIX proj = XMLoadFloat4x4(&mProj); XMMATRIX worldViewProj = world*view*proj; mfxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&worldViewProj)); D3DX11_TECHNIQUE_DESC techDesc; mTech->GetDesc( &techDesc ); for(UINT p = 0; p < techDesc.Passes; ++p) { mTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext); // indices for the mesh. md3dImmediateContext->DrawIndexed(indexCount, 0, 0); } HR(mSwapChain->Present(0, 0)); }
void LightDemo::DrawScene() { m_dxImmediateContext->ClearRenderTargetView(m_renderTargetView.Get(), reinterpret_cast<const float*>(&oc::Colors::LightSteelBlue)); m_dxImmediateContext->ClearDepthStencilView(m_depthStencilView.Get(), D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0); m_dxImmediateContext->IASetInputLayout(m_inputLayout.Get()); m_dxImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); uint32 stride = sizeof(Vertex); uint32 offset = 0; // Set constants XMMATRIX view = XMLoadFloat4x4(&m_view); XMMATRIX proj = XMLoadFloat4x4(&m_proj); XMMATRIX viewProj = view*proj; // Set per frame constants. m_fxDirLight->SetRawValue(&m_dirLight, 0, sizeof(m_dirLight)); m_fxPointLight->SetRawValue(&m_pointLight, 0, sizeof(m_pointLight)); m_fxSpotLight->SetRawValue(&m_spotLight, 0, sizeof(m_spotLight)); m_fxEyePosW->SetRawValue(&m_camPosition, 0, sizeof(m_camPosition)); D3DX11_TECHNIQUE_DESC techDesc; m_tech->GetDesc(&techDesc); for(uint32 p = 0; p < techDesc.Passes; ++p) { //Draw the land m_dxImmediateContext->IASetVertexBuffers(0, 1, m_landVB.GetAddressOf(), &stride, &offset); m_dxImmediateContext->IASetIndexBuffer(m_landIB.Get(), DXGI_FORMAT_R32_UINT, 0); //Set per object constants XMMATRIX world = XMLoadFloat4x4(&m_landWorld); XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world); XMMATRIX worldViewProj = world*viewProj; m_fxWorld->SetMatrix(reinterpret_cast<float*>(&world)); m_fxWorldInvTranspose->SetMatrix(reinterpret_cast<float*>(&worldInvTranspose)); m_fxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&worldViewProj)); m_fxMaterial->SetRawValue(&m_landMat, 0, sizeof(m_landMat)); m_tech->GetPassByIndex(p)->Apply(0, m_dxImmediateContext.Get()); m_dxImmediateContext->DrawIndexed(m_landIndexCount, 0, 0); //Draw the wave m_dxImmediateContext->IASetVertexBuffers(0, 1, m_wavesVB.GetAddressOf(), &stride, &offset); m_dxImmediateContext->IASetIndexBuffer(m_wavesIB.Get(), DXGI_FORMAT_R32_UINT, 0); world = XMLoadFloat4x4(&m_wavesWorld); worldInvTranspose = MathHelper::InverseTranspose(world); worldViewProj = world*viewProj; m_fxWorld->SetMatrix(reinterpret_cast<float*>(&world)); m_fxWorldInvTranspose->SetMatrix(reinterpret_cast<float*>(&worldInvTranspose)); m_fxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&worldViewProj)); m_fxMaterial->SetRawValue(&m_wavesMat, 0, sizeof(m_wavesMat)); m_tech->GetPassByIndex(p)->Apply(0, m_dxImmediateContext.Get()); m_dxImmediateContext->DrawIndexed(3*m_waves.TriangleCount(), 0, 0); } HR(m_swapChain->Present(0, 0)); }
void BoxApp::DrawScene() { md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::LightSteelBlue)); md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0); md3dImmediateContext->IASetInputLayout(mInputLayout); md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); UINT stride = sizeof(Vertex); UINT offset = 0; md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset); md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0); // Set constants XMMATRIX world = XMLoadFloat4x4(&mWorld); XMMATRIX view = XMLoadFloat4x4(&mView); XMMATRIX proj = XMLoadFloat4x4(&mProj); XMMATRIX worldViewProj = world*view*proj; mfxWorldViewProj->SetMatrix(reinterpret_cast<float*>(&worldViewProj)); D3DX11_TECHNIQUE_DESC techDesc; float blendFactor[] = { 0.8f, 0.8f, 0.8f, 1.0f }; float blend[] = { 0.0f, 0.0f, 0.0f, 0.9f }; int a = 0; //Draw as normal mTech->GetDesc( &techDesc ); for(UINT p = 0; p < techDesc.Passes; ++p) { mTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext); if (testBlend == 0) { //Red md3dImmediateContext->OMSetBlendState(ColorBlend,blendFactor,0xffffffff); md3dImmediateContext->DrawIndexed(3, 0, 0); //Blue md3dImmediateContext->OMSetBlendState(AlphaBlend,blendFactor,0xffffffff); md3dImmediateContext->DrawIndexed(3, 6, 0); //Green md3dImmediateContext->OMSetBlendState(ColorBlend,blendFactor,0xffffffff); md3dImmediateContext->DrawIndexed(3, 3, 0); } else if (testBlend == 1) { //Red md3dImmediateContext->OMSetBlendState(ColorBlend,blendFactor,0xffffffff); md3dImmediateContext->DrawIndexed(3, 0, 0); //Green md3dImmediateContext->DrawIndexed(3, 3, 0); //Blue md3dImmediateContext->OMSetBlendState(AlphaBlend,blendFactor,0xffffffff); md3dImmediateContext->DrawIndexed(3, 6, 0); } else { //Red md3dImmediateContext->OMSetBlendState(AlphaBlend, blendFactor, 0xffffffff); md3dImmediateContext->DrawIndexed(3, 0, 0); //Green md3dImmediateContext->DrawIndexed(3, 3, 0); //Blue md3dImmediateContext->DrawIndexed(3, 6, 0); } } HR(mSwapChain->Present(0, 0)); }
void EndOfDirectX11::Render() { if( d3dContext_ == 0 ) { return; } float clearColor[] = { 0.0f, 0.0f, 0.25f, 1.0f }; d3dContext_->ClearRenderTargetView( backBufferTarget_, clearColor ); d3dContext_->ClearDepthStencilView( depthStencilView_, D3D11_CLEAR_DEPTH, 1.0f, 0 ); unsigned int stride = sizeof( VertexPos ); unsigned int offset = 0; d3dContext_->IASetInputLayout( inputLayout_ ); d3dContext_->IASetVertexBuffers( 0, 1, &vertexBuffer_, &stride, &offset ); d3dContext_->IASetIndexBuffer( indexBuffer_, DXGI_FORMAT_R16_UINT, 0 ); d3dContext_->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); ID3DX11EffectShaderResourceVariable * colorMap = 0; colorMap = effect_->GetVariableByName( "colorMap" )->AsShaderResource(); colorMap->SetResource( colorMap_ ); ID3DX11EffectShaderResourceVariable* colorMap2; colorMap2 = effect_->GetVariableByName( "secondMap" )->AsShaderResource( ); colorMap2->SetResource( secondMap_ ); ID3DX11EffectSamplerVariable * samplerState = 0; samplerState = effect_->GetVariableByName( "colorSampler" )->AsSampler(); samplerState->SetSampler( 0, samplerState_ ); ID3DX11EffectMatrixVariable * worldMatrix = 0; worldMatrix = effect_->GetVariableByName( "worldMatrix" )->AsMatrix(); worldMatrix->SetMatrix( ( float * )&worldMat_ ); ID3DX11EffectMatrixVariable * viewMatrix = 0; viewMatrix = effect_->GetVariableByName( "viewMatrix" )->AsMatrix(); viewMatrix->SetMatrix( ( float * )&viewMatrix_ ); ID3DX11EffectMatrixVariable * projMatrix = 0; projMatrix = effect_->GetVariableByName( "projMatrix" )->AsMatrix(); projMatrix->SetMatrix( ( float * )&projMatrix_ ); ID3DX11EffectTechnique * colorInvTechnique = 0; colorInvTechnique = effect_->GetTechniqueByName( "MultiTexture" ); D3DX11_TECHNIQUE_DESC techDesc; colorInvTechnique->GetDesc( &techDesc ); for( unsigned int p = 0; p < techDesc.Passes; ++p ) { ID3DX11EffectPass * pass = colorInvTechnique->GetPassByIndex( p ); if( pass != 0 ) { pass->Apply( 0, d3dContext_ ); d3dContext_->DrawIndexed( 36, 0, 0 ); } } swapChain_->Present( 0, 0 ); }