void AasRenderer::RenderGeometryShadow(gfx::AnimatedModel * model, const gfx::AnimatedModelParams & params, const gfx::Light3d & globalLight, float alpha) { // Find or create render caching data for the submesh auto &renderData = mRenderDataCache[model->GetHandle()]; if (!renderData) { renderData = std::make_unique<AasRenderData>(); } mDevice.SetMaterial(mGeometryShadowMaterial); auto d3d = mDevice.GetDevice(); d3d->SetVertexShaderConstantF(0, &mDevice.GetCamera().GetViewProj()._11, 4); d3d->SetVertexShaderConstantF(4, &globalLight.dir.x, 1); XMFLOAT4 floats{ params.offsetZ, 0, 0, 0 }; d3d->SetVertexShaderConstantF(5, &floats.x, 1); floats.x = alpha; d3d->SetVertexShaderConstantF(6, &floats.x, 1); auto materialIds(model->GetSubmeshes()); for (size_t i = 0; i < materialIds.size(); ++i) { auto submesh(model->GetSubmesh(params, i)); auto &submeshData = GetSubmeshData(*renderData, i, *submesh); submeshData.binding.Bind(); d3d->SetIndices(submeshData.idxBuffer->GetBuffer()); D3DLOG(d3d->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, submesh->GetVertexCount(), 0, submesh->GetPrimitiveCount())); } }
static HRESULT STDMETHODCALLTYPE MyDrawIndexedPrimitive(IDirect3DDeviceN* pThis, D3DPRIMITIVETYPE a, DWORD b, LPVOID c, DWORD d, LPWORD e, DWORD f, DWORD g) { d3ddebugprintf(__FUNCTION__ "(0x%X) called.\n", pThis); if(ShouldSkipDrawing(false, true)) return D3D_OK; HRESULT rv = DrawIndexedPrimitive(pThis, a, b, c, d, e, f, g); return rv; }
IZ_BOOL CGraphicsDevice::DrawIndexedInstancedPrimitive( E_GRAPH_PRIM_TYPE prim_type, IZ_UINT vtxOffset, IZ_UINT vtxNum, IZ_UINT idxOffset, IZ_UINT nPrimCnt) { return DrawIndexedPrimitive(prim_type, vtxOffset, vtxNum, idxOffset, nPrimCnt); }
void TerrainBorderRenderable::Render(HippoD3d9Device* pdevice, unsigned int escapeTime) { auto device = Globals::GetDevice()->GetDeviceD3D9(); RS_HELP_OBJ(device, D3DRS_ALPHABLENDENABLE, TRUE); RS_HELP_OBJ(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); RS_HELP_OBJ(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); //RS_HELP_OBJ(device, D3DRS_ZWRITEENABLE, false); RS_HELP_OBJ(device, D3DRS_CULLMODE, D3DCULL_CCW); D3DXMATRIX matrix; D3DXMatrixIdentity(&matrix); HRESULT v = m_fxhandle->SetMatrix("g_mWorld", &matrix); //wvp matrix auto proj = Globals::GetRender()->GetProjMatrix(); auto view = Globals::GetRender()->GetViewMatrix(); D3DXMATRIX vp = (*view)*(*proj); v = m_fxhandle->SetMatrix("g_mViewProjection", &vp); //time float time = GetTickCount()*0.001f; v = m_fxhandle->SetValue("g_fTime", &time, sizeof(float)); //viewmatrix const D3DXVECTOR3* camPos = Globals::GetCurrentCamera()->GetPos(); v = m_fxhandle->SetMatrix("ViewMatrix", view); v = m_fxhandle->SetValue("g_camerapos", camPos, sizeof(D3DXVECTOR3)); //texture v = m_fxhandle->SetTexture("g_MeshTexture", m_pTextrue.get()); //threshold D3DXVECTOR4 threshold = D3DXVECTOR4(800.f, 0.99f, 0, 0); v = m_fxhandle->SetValue("threshold", &threshold, sizeof(D3DXVECTOR4)); device->SetStreamSource(0, m_pVB.get(), 0, sizeof(TerrainVertex)); device->SetVertexDeclaration(m_pVertexDecl.get()); device->SetIndices(m_pIB.get()); UINT iPass, totalPasses; m_fxhandle->Begin(&totalPasses, 0); m_fxhandle->BeginPass(0); device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, // 将要绘制的索引缓冲区的起始地址 0, // 索引数组中最小的索引值 16, // 要绘制的索引数组中的顶点数量 0, // 从索引数组中的第几个元素开始绘制图元 8); // 绘制的图元数量 m_fxhandle->EndPass(); m_fxhandle->End(); }
HRESULT c_gbuffer_system::DrawIndexedPrimitive_Structure(IDirect3DDevice9* pDevice, D3DPRIMITIVETYPE Type, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) { HRESULT hr = pDevice->DrawIndexedPrimitive(Type, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount); if(g_default_system.IsRenderable() && !Render::IsRenderingReflection() && g_current_render_state == Enums::_render_progress_structure) { hr &= g_default_system.DrawIndexedPrimitive_StructureImpl(pDevice, Type, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount); hr &= DrawIndexedPrimitive(pDevice, Type, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount); } return hr; }
void RenderCore::RenderCurrentStates() { Clear(); Begin(); for(unsigned int i = 0; i < RSID_NUMBER; ++i) { m_RenderStateRegistry[i]->Apply(true); } RSDrawIndexed* pRSDI= static_cast<RSDrawIndexed*>(m_RenderStateRegistry[RSID_DRAWINDEXED]); if(pRSDI && pRSDI->IsValid()) { DrawIndexedPrimitive(pRSDI->m_NumOfVertices, pRSDI->m_NumOfPrimitives, pRSDI->m_PrimitiveType); } End(); }
void AasRenderer::RenderWithoutMaterial(gfx::AnimatedModel *model, const gfx::AnimatedModelParams& params) { // Find or create render caching data for the model auto &renderData = mRenderDataCache[model->GetHandle()]; if (!renderData) { renderData = std::make_unique<AasRenderData>(); } auto materialIds(model->GetSubmeshes()); for (size_t i = 0; i < materialIds.size(); ++i) { auto submesh(model->GetSubmesh(params, i)); auto &submeshData = GetSubmeshData(*renderData, i, *submesh); submeshData.binding.Bind(); auto d3d = mDevice.GetDevice(); d3d->SetIndices(submeshData.idxBuffer->GetBuffer()); D3DLOG(d3d->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, submesh->GetVertexCount(), 0, submesh->GetPrimitiveCount())); } }
void AasRenderer::Render(gfx::AnimatedModel *model, const gfx::AnimatedModelParams& params, gsl::span<Light3d> lights, const MdfRenderOverrides *materialOverrides) { // Find or create render caching data for the model auto &renderData = mRenderDataCache[model->GetHandle()]; if (!renderData) { renderData = std::make_unique<AasRenderData>(); } auto materialIds(model->GetSubmeshes()); for (size_t i = 0; i < materialIds.size(); ++i) { auto materialId = materialIds[i]; auto submesh(model->GetSubmesh(params, i)); // Remove special material marker in the upper byte and only // use the actual shader registration id materialId &= 0x00FFFFFF; // Usually this should not happen, since it means there's // an unbound replacement material if (materialId == 0) { continue; } // if material was not found if (materialId == 0x00FFFFFF) { continue; } auto material = mMdfFactory.GetById(materialId); if (!material) { logger->error("Legacy shader with id {} wasn't found.", materialId); continue; } material->Bind(mDevice, lights, materialOverrides); // Do we have to recalculate the normals? if (material->GetSpec()->recalculateNormals) { RecalcNormals( submesh->GetVertexCount(), submesh->GetPositions().data(), submesh->GetNormals().data(), submesh->GetPrimitiveCount(), submesh->GetIndices().data() ); } auto &submeshData = GetSubmeshData(*renderData, i, *submesh); submeshData.binding.Bind(); auto d3d = mDevice.GetDevice(); d3d->SetIndices(submeshData.idxBuffer->GetBuffer()); D3DLOG(d3d->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, submesh->GetVertexCount(), 0, submesh->GetPrimitiveCount())); } }
void TerrainRenderablePlane::Render(HippoD3d9Device* pdevice, unsigned int escapeTime) { auto d3d9device = pdevice->GetDeviceD3D9(); //d3d9device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); //world matrix D3DXMATRIX tmpMatrix; D3DXMatrixMultiply(&tmpMatrix, &m_local_matrix, m_parent->GetWorldTransform()); HRESULT v = m_fxhandle->SetMatrix("g_mWorld", &tmpMatrix); //wvp matrix auto proj = Globals::GetRender()->GetProjMatrix(); auto view = Globals::GetRender()->GetViewMatrix(); D3DXMATRIX vp = (*view)*(*proj); v = m_fxhandle->SetMatrix("g_mViewProjection", &vp); //camera const D3DXVECTOR3* pos = Globals::GetCurrentCamera()->GetPos(); v = m_fxhandle->SetValue("g_camera_pos", pos, sizeof(D3DXVECTOR3)); //material D3DXCOLOR vWhite = D3DXCOLOR(0.5, 0.3, 0.2, 1); v = m_fxhandle->SetValue("g_MaterialDiffuseColor", &vWhite, sizeof(D3DXCOLOR)); //texture v = m_fxhandle->SetTexture("g_MeshTexture", m_pTextrue[0]); //tower info auto alltowers = Globals::GetWorld()->GetAllTower(); auto itr = alltowers.begin(); D3DXVECTOR4 tmp[2]; int idx = 0; while (itr != alltowers.end()) { TowerEntity* pEntity = (TowerEntity*)((*itr).get()); D3DXVECTOR3* pos = pEntity->GetPos(); float r = pEntity->GetRange(); tmp[idx] = D3DXVECTOR4(pos->x, pos->y, pos->z, r); ++itr; ++idx; } v = m_fxhandle->SetVectorArray("towerInfo", tmp, 2); //robot info auto player = Globals::GetWorld()->GetPlayer(); pos = player->GetPos(); D3DXVECTOR4 robotpos = D3DXVECTOR4(pos->x, pos->z, 12.f, 1.0f); v = m_fxhandle->SetVector("robotInfo", &robotpos); d3d9device->SetStreamSource(0, m_pVB, 0, sizeof(TerrainVertex)); d3d9device->SetVertexDeclaration(m_pVertexDecl); d3d9device->SetIndices(m_pIB); UINT iPass, totalPasses; m_fxhandle->Begin(&totalPasses, 0); for (iPass = 0; iPass < totalPasses; iPass++) { m_fxhandle->BeginPass(iPass); d3d9device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, // 将要绘制的索引缓冲区的起始地址 0, // 索引数组中最小的索引值 GetVertexNum(), // 要绘制的索引数组中的顶点数量 0, // 从索引数组中的第几个元素开始绘制图元 GetTriangleNum()); // 绘制的图元数量 m_fxhandle->EndPass(); } m_fxhandle->End(); m_border_renderable->Render(pdevice, escapeTime); }
void TerrainRenderable::Render(HippoD3d9Device* pdevice, unsigned int escapeTime) { auto d3d9device = pdevice->GetDeviceD3D9(); //*d3d9device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);*/ //world matrix D3DXMATRIX tmpMatrix; D3DXMatrixMultiply(&tmpMatrix, &m_local_matrix, m_parent->GetWorldTransform()); HRESULT v = m_fxhandle->SetMatrix("g_mWorld", &tmpMatrix); //wvp matrix auto proj = Globals::GetRender()->GetProjMatrix(); auto view = Globals::GetRender()->GetViewMatrix(); D3DXMATRIX vp = (*view)*(*proj); v = m_fxhandle->SetMatrix("g_mViewProjection", &vp); //camera const D3DXVECTOR3* pos=Globals::GetCurrentCamera()->GetPos(); v = m_fxhandle->SetValue("g_camera_pos", pos, sizeof(D3DXVECTOR3)); //texture v = m_fxhandle->SetTexture("g_DiffuseTex", m_pTextrue[0]); v = m_fxhandle->SetTexture("g_DetailTex", m_pTextrue[1]); v = m_fxhandle->SetTexture("g_NormalTex", m_pTextrue[2]); //tower info const GameEntityPtrCon& con = Globals::GetWorld()->GetAllTower(); GameEntityPtrCon::const_iterator itr = con.begin(); GameEntityPtrCon::const_iterator itrend = con.end(); D3DXVECTOR4 tmp[2]; int idx = 0; while (itr != itrend) { auto towerptr = (TowerEntity*)itr->get(); D3DXVECTOR3* pos = towerptr->GetPos(); float r = towerptr->GetRange(); tmp[idx] = D3DXVECTOR4(pos->x, pos->y, pos->z, r); ++itr; ++idx; } v=m_fxhandle->SetVectorArray("towerInfo", tmp, 2); //robot info auto robot=Globals::GetWorld()->GetPlayer(); D3DXVECTOR4 robotpos = D3DXVECTOR4(robot->GetPos()->x, robot->GetPos()->z, 2, 1); v=m_fxhandle->SetVector("robotInfo", &robotpos); d3d9device->SetStreamSource(0, m_pVB, 0, sizeof(TerrainVertex)); d3d9device->SetVertexDeclaration(m_pVertexDecl); d3d9device->SetIndices(m_pIB); UINT iPass, totalPasses; m_fxhandle->Begin(&totalPasses, 0); for (iPass = 0; iPass < totalPasses; iPass++) { m_fxhandle->BeginPass(iPass); //d3d9device->DrawPrimitive(D3DPT_POINTLIST, // 0, // 将要绘制的索引缓冲区的起始地址 // GetVertexNum()); // 绘制的图元数量 d3d9device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, // 将要绘制的索引缓冲区的起始地址 0, // 索引数组中最小的索引值 GetVertexNum(), // 要绘制的索引数组中的顶点数量 0, // 从索引数组中的第几个元素开始绘制图元 GetTriangleNum()); // 绘制的图元数量 m_fxhandle->EndPass(); } m_fxhandle->End(); return; //patch auto pthitr = m_all_patch.begin(); while (pthitr != m_all_patch.end()) { auto patch_fx = (*pthitr)->GetPatchFx(); auto patch_ib = (*pthitr)->GetIB(); int tri_count = (*pthitr)->GetIndexCount() / 3; d3d9device->SetStreamSource(0, m_pVB, 0, sizeof(TerrainVertex)); d3d9device->SetVertexDeclaration(m_pVertexDecl); HRESULT v = d3d9device->SetIndices(patch_ib); v=patch_fx->SetMatrix("g_mWorld", &tmpMatrix); v = patch_fx->SetMatrix("g_mViewProjection", &vp); v = patch_fx->SetValue("g_camera_pos", pos, sizeof(D3DXVECTOR3)); UINT totalPasses; v=patch_fx->Begin(&totalPasses, 0); v = patch_fx->BeginPass(0); v = d3d9device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, // 将要绘制的索引缓冲区的起始地址 0, // 索引数组中最小的索引值 GetVertexNum(), // 要绘制的索引数组中的顶点数量 0, // 从索引数组中的第几个元素开始绘制图元 tri_count); // 绘制的图元数量 v = patch_fx->EndPass(); ++pthitr; } }