bool SkyBox::Render(std::shared_ptr<D3DRenderer> d3d, DirectX::CXMMATRIX world, DirectX::CXMMATRIX view, DirectX::CXMMATRIX projection, std::shared_ptr<Camera> camera, std::shared_ptr<Light> light) { ID3D11DeviceContext *context = d3d->GetDeviceContext(); DirectX::XMMATRIX sphereWorld = DirectX::XMMatrixIdentity(), scale = DirectX::XMMatrixScaling(0.3f, 0.3f, 0.3f), translation; translation = DirectX::XMMatrixTranslationFromVector(camera->GetPosition()); sphereWorld = scale * translation; if (!SetShaderParameters(context, sphereWorld, view, projection, texture->GetTexture())) return false; UINT strides = sizeof(DirectX::VertexPositionNormalTexture), offset = 0; context->IASetInputLayout(m_layout); context->IASetIndexBuffer(sphereIndexBuffer, DXGI_FORMAT_R32_UINT, 0); context->IASetVertexBuffers(0, 1, &sphereVertBuffer, &strides, &offset); context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); context->PSSetShader(pixelShader, NULL, 0); context->VSSetShader(vertexShader, NULL, 0); context->RSSetState(d3d->GetRasterState(1)); d3d->SetDepthLessEqual(); context->DrawIndexed(NumSphereFaces*3, 0, 0); d3d->End2D(); context->RSSetState(d3d->GetRasterState(0)); return true; }
void CGUIWindowTestPatternDX::DrawRectangle(float x, float y, float x2, float y2, DWORD color) { XMFLOAT4 float4; CD3DHelper::XMStoreColor(&float4, color); Vertex vert[] = { { XMFLOAT3( x, y, 0.5f), float4, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x2, y, 0.5f), float4, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x2, y2, 0.5f), float4, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x2, y2, 0.5f), float4, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3(x, y2, 0.5f), float4, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, { XMFLOAT3( x, y, 0.5f), float4, XMFLOAT2(0.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, }; UpdateVertexBuffer(vert, ARRAYSIZE(vert)); ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context(); CGUIShaderDX* pGUIShader = g_Windowing.GetGUIShader(); pGUIShader->Begin(SHADER_METHOD_RENDER_DEFAULT); unsigned stride = sizeof(Vertex), offset = 0; pContext->IASetVertexBuffers(0, 1, &m_vb, &stride, &offset); pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); pGUIShader->Draw(ARRAYSIZE(vert), 0); }
void CGUIWindowTestPatternDX::DrawHorizontalLines(int top, int left, int bottom, int right) { Vertex* vert = new Vertex[2 + (bottom - top)]; int p = 0; for (int i = top; i <= bottom; i += 2) { vert[p].pos.x = (float)left; vert[p].pos.y = (float)i; vert[p].pos.z = 0.5f; vert[p].color = XMFLOAT4(m_white, m_white, m_white, 1.0f); ++p; vert[p].pos.x = (float)right; vert[p].pos.y = (float)i; vert[p].pos.z = 0.5f; vert[p].color = XMFLOAT4(m_white, m_white, m_white, 1.0f); ++p; } UpdateVertexBuffer(vert, p); ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context(); CGUIShaderDX* pGUIShader = g_Windowing.GetGUIShader(); pGUIShader->Begin(SHADER_METHOD_RENDER_DEFAULT); unsigned stride = sizeof(Vertex), offset = 0; pContext->IASetVertexBuffers(0, 1, &m_vb, &stride, &offset); pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); pGUIShader->Draw(p, 0); delete [] vert; }
void CFullscreenTriangleDrawer::DrawDX11( ID3D11ShaderResourceView* pTextureSRV ) { ID3D11Device* pDevice = static_cast<ID3D11Device*>( gD3DDevice ); ID3D11DeviceContext* pContext = NULL; pDevice->GetImmediateContext( &pContext ); CDX11StateGuard stateGuard; pContext->IASetInputLayout( NULL ); pContext->IASetIndexBuffer( NULL, DXGI_FORMAT_UNKNOWN, 0 ); pContext->IASetVertexBuffers( 0, 0, NULL, NULL, NULL ); pContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); pContext->VSSetShader( m_pVertexShader11, NULL, 0 ); pContext->PSSetShader( m_pPixelShader11, NULL, 0 ); ID3D11SamplerState* pNullSampler[] = { NULL }; pContext->PSSetSamplers( 0, 1, pNullSampler ); pContext->PSSetShaderResources( 0, 1, &pTextureSRV ); pContext->OMSetBlendState( m_pBlendState11, NULL, 0xFFFFFFFF ); // Draw pContext->Draw( 3, 0 ); }
//----------------------------------------- void CPUTSprite::DrawSprite( CPUTRenderParameters &renderParams, CPUTMaterial &material ) { // TODO: Should we warn here? // If it doesn't draw, make sure you created it with createDebugSprite == true if( mpVertexBuffer ) { ID3D11DeviceContext *pContext = ((CPUTRenderParametersDX*)&renderParams)->mpContext; material.SetRenderStates(renderParams); UINT stride = sizeof( SpriteVertex ); UINT offset = 0; pContext->IASetVertexBuffers( 0, 1, &mpVertexBuffer, &stride, &offset ); // Set the input layout pContext->IASetInputLayout( mpInputLayout ); // Set primitive topology pContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); pContext->Draw( 6, 0 ); } } // CPUTSprite::DrawSprite()
void ParticleManager::RenderParticles(DxGraphics* pDxGraphics, Camera& cam) { cam.CalculateViewMatrix(); XMMATRIX tWorld = XMMatrixTranspose(m_worldMat); XMMATRIX tView = XMMatrixTranspose(cam.GetViewMatrix()); XMMATRIX tProj = XMMatrixTranspose(cam.GetProjMatrix()); ID3D11DeviceContext* pCon = pDxGraphics->GetImmediateContext(); UINT stride = sizeof(Particle); UINT offset = 0; pCon->IASetVertexBuffers(0, 1, &m_vBuffer, &stride, &offset); pCon->IASetInputLayout(m_inputLayout); pCon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); pCon->VSSetShader(m_vShader, 0, 0); pCon->PSSetShader(m_pShader, 0, 0); pCon->UpdateSubresource(m_camWorldBuffer, 0, NULL, &tWorld, 0, 0); pCon->UpdateSubresource(m_camViewBuffer, 0, NULL, &tView, 0, 0); pCon->UpdateSubresource(m_camProjBuffer, 0, NULL, &tProj, 0, 0); pCon->VSSetConstantBuffers(0, 1, &m_camWorldBuffer); pCon->VSSetConstantBuffers(1, 1, &m_camViewBuffer); pCon->VSSetConstantBuffers(2, 1, &m_camProjBuffer); pCon->Draw(m_particleList.size(), 0); pCon->VSSetShader(NULL, 0, 0); pCon->GSSetShader(NULL, 0, 0); pCon->PSSetShader(NULL, 0, 0); }
void COverlayImageDX::Render(SRenderState &state) { ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context(); CGUIShaderDX* pGUIShader = g_Windowing.GetGUIShader(); XMMATRIX world = pGUIShader->GetWorld(); XMMATRIX trans = m_pos == POSITION_RELATIVE ? XMMatrixTranslation(state.x - state.width * 0.5f, state.y - state.height * 0.5f, 0.0f) : XMMatrixTranslation(state.x, state.y, 0.0f), scale = XMMatrixScaling(state.width, state.height, 1.0f); pGUIShader->SetWorld(XMMatrixMultiply(XMMatrixMultiply(world, scale), trans)); const unsigned stride = m_vertex.GetStride(); const unsigned offset = 0; ID3D11Buffer* vertexBuffer = m_vertex.Get(); // Set the vertex buffer to active in the input assembler so it can be rendered. pContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset); // Set the type of primitive that should be rendered from this vertex buffer, in this case triangles. pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); pGUIShader->Begin(SHADER_METHOD_RENDER_TEXTURE_NOBLEND); g_Windowing.SetAlphaBlendEnable(true); ID3D11ShaderResourceView* views[] = { m_texture.GetShaderResource() }; pGUIShader->SetShaderViews(1, views); pGUIShader->Draw(6, 0); // restoring transformation pGUIShader->SetWorld(world); pGUIShader->RestoreBuffers(); }
void GeometricPrimitive::Render(D3D11RendererMaterial* pMaterial) { ID3D11DeviceContext* pDeviceContext = g_objDeviecManager.GetImmediateContext(); pDeviceContext->IASetPrimitiveTopology((D3D_PRIMITIVE_TOPOLOGY)D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); pDeviceContext->IASetInputLayout(pMaterial->getLayout<VertexPositionNormalTexture>()); pImpl->Draw(pDeviceContext); }
void RenderTargetPingPong::Apply(ID3D11Device* device, ID3DX11EffectTechnique* technique) { ID3D11DeviceContext* context; device->GetImmediateContext(&context); ID3D11Buffer* zero = 0; UINT nought = 0; context->IASetVertexBuffers(0,1,&zero,&nought,&nought); context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); context->IASetInputLayout(0); { ID3D11RenderTargetView* view[] = { m_target->RenderTargetView() }; context->OMSetRenderTargets(1, const_cast<ID3D11RenderTargetView**> (view), m_depth_stencil_view); } m_shader_resource_variable->SetResource(m_source->ShaderResourceView()); for(UINT n = 0; n < Effect::NumPasses(technique); ++n) { technique->GetPassByIndex(n)->Apply(0,context); context->Draw(4,0); } m_shader_resource_variable->SetResource(0); m_last_target = m_target; std::swap(m_source,m_target); }
//--------------------------------------------------------------------------- void FontRenderer::FontDrawingBegin( RenderContext* rc ) { assert( m_vertexBuffer != NULL ); assert( m_indexBuffer != NULL ); m_currentRC = rc; m_fontDrawOps.clear(); ID3D11DeviceContext* dc = m_currentRC->Context(); UINT viewportCount = 1; D3D11_VIEWPORT vp; dc->RSGetViewports(&viewportCount, &vp); UINT stride = sizeof(FontTextVertex); UINT offset = 0; dc->IASetInputLayout(m_vertexLayout); dc->IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0); dc->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset); dc->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); dc->VSSetShader( m_vertexShader, 0, 0 ); dc->PSSetShader( m_pixelShader, 0, 0 ); dc->PSSetSamplers( 0, 1, &m_samplerState ); dc->RSSetState(m_rasterState); float blendFactor[4] = {1.0f}; dc->OMSetBlendState(m_blendState, blendFactor, 0xffffffff); m_activeFont = NULL; // needs to be set! }
//--------------------------------------------------------------------------- void ShadowMapGen::DrawRenderable(const RenderableNode& r) { if (!r.GetFlag( RenderableNode::kShadowCaster ) ) return; ID3D11DeviceContext* dc = m_rc->Context(); ConstantBufferShadowMapGenPerDraw constBuffer; Matrix::Transpose(r.WorldXform, constBuffer.world ); UpdateConstantBuffer(dc,m_pConstantBufferPerDraw,&constBuffer,sizeof(constBuffer)); uint32_t stride = r.mesh->vertexBuffer->GetStride(); uint32_t offset = 0; uint32_t startIndex = 0; uint32_t startVertex = 0; uint32_t indexCount = r.mesh->indexBuffer->GetCount(); ID3D11Buffer* d3dvb = r.mesh->vertexBuffer->GetBuffer(); ID3D11Buffer* d3dib = r.mesh->indexBuffer->GetBuffer(); dc->IASetPrimitiveTopology( (D3D11_PRIMITIVE_TOPOLOGY)r.mesh->primitiveType ); dc->IASetVertexBuffers( 0, 1, &d3dvb, &stride, &offset ); dc->IASetIndexBuffer(d3dib, DXGI_FORMAT_R32_UINT, 0); dc->DrawIndexed(indexCount, startIndex, startVertex); }
void Render::Draw() { UINT stride = sizeof(GENERIC::Vertex); UINT offset = 0; ID3D11DeviceContext* context = RenderDevice::Get()->GetContext(); context->IASetInputLayout(_inputLayout); context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); context->IASetVertexBuffers(0, 1, &pVB, &stride, &offset); context->IASetIndexBuffer(pIB, DXGI_FORMAT_R32_UINT, 0); D3DX11_TECHNIQUE_DESC techDesc; _tech->GetDesc(&techDesc); XMMATRIX world = pOwner->GetComponent<Transform>()->GetWorldMatrix(); XMMATRIX vp = General::Get()->GetMainCamera()->GetViewProjectionMatrix(); Effect::BasicEffect::Get()->SetWorldMatrix(reinterpret_cast<float*>(&world)); Effect::BasicEffect::Get()->SetViewProjectionMatrix(reinterpret_cast<float*>(&vp)); for (UINT i = 0; i < techDesc.Passes; ++i) { _tech->GetPassByIndex(i)->Apply(0, context); context->DrawIndexed(_meshData->GetNumIndices(), 0, 0); } }
void entity::draw(ID3D11DeviceContext& device, const camera& camera, shadow_map& shadow_map) const { this->update_world_matrix(); this->shader.vertex.set_data("world", this->world_matrix); this->shader.vertex.set_data("view", camera.view_mat()); this->shader.vertex.set_data("projection", camera.projection); this->shader.vertex.set_data("shadowView", shadow_map.light_view); this->shader.vertex.set_data("shadowProjection", shadow_map.light_projection); this->shader.pixel.set_sampler_state("state", this->shader_texture.state); this->shader.pixel.set_shader_resource_view("res", this->shader_texture.resource_view); this->shader.pixel.set_shader_resource_view("shadowMap", shadow_map.shadow.resource_view); this->shader.pixel.set_sampler_state("shadowSampler", shadow_map.shadow.sampler_state); this->shader.vertex.activate(true); this->shader.pixel.activate(true); UINT stride = sizeof(Vertex); UINT offset = 0; device.IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); device.IASetVertexBuffers(0, 1, &this->object_mesh.vertices.buffer, &stride, &offset); device.IASetIndexBuffer(this->object_mesh.indices.buffer, DXGI_FORMAT_R32_UINT, 0); device.DrawIndexed( this->object_mesh.indices.len, 0, 0); }
void ComplexTree::draw(ID3D11Device* device, const GameTime& gameTime) { ID3D11DeviceContext* deviceContext; device->GetImmediateContext(&deviceContext); ID3D11Buffer* buffers[2] = { trunkMesh.GetVB11(0, 0), instanceBuffer }; unsigned strides[2] = { trunkMesh.GetVertexStride(0,0), sizeof(Vector3) }; unsigned offsets[2] = {0}; deviceContext->IASetInputLayout(inputLayout); deviceContext->IASetVertexBuffers(0, 2, buffers, strides, offsets); deviceContext->IASetIndexBuffer(trunkMesh.GetIB11(0), trunkMesh.GetIBFormat11(0), 0); Camera& camera = vegetationRendering.getCamera(); const Light& light = vegetationRendering.getLight(); D3D11_VIEWPORT viewport; unsigned numViewports = 1; deviceContext->RSGetViewports(&numViewports, &viewport); evGSCulling->SetBool(vegetationRendering.isGSCullingEnabled()); evShowSavedCulling->SetBool(vegetationRendering.showSaved()); evSavedViewProjection->SetMatrix(vegetationRendering.getSavedViewMatrix() * vegetationRendering.getSavedProjectionMatrix()); evCameraPosition->SetFloatVector(camera.getPosition()); evLightVector->SetFloatVector(Vector3(light.Direction.x, light.Direction.y, light.Direction.z)); evAmbientLight->SetFloatVector(Vector3(light.Ambient.r, light.Ambient.g, light.Ambient.b)); evDiffuseLight->SetFloatVector(Vector3(light.Diffuse.r, light.Diffuse.g, light.Diffuse.b)); evSpecularLight->SetFloatVector(Vector3(light.Specular.r, light.Specular.g, light.Specular.b)); evShininess->SetFloat(TREE_SHININESS); evWorld->SetMatrix(world); evViewProjection->SetMatrix(camera.getView() * camera.getProjection(TREE_NEAR_PLANE, TREE_FAR_PLANE)); for(unsigned i = 0; i < trunkMesh.GetNumSubsets(0); ++i) { SDKMESH_SUBSET* subset = trunkMesh.GetSubset(0, i); //D3D11_PRIMITIVE_TOPOLOGY primitiveType = trunkMesh.GetPrimitiveType11((SDKMESH_PRIMITIVE_TYPE)subset->PrimitiveType); deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST); SDKMESH_MATERIAL* material = trunkMesh.GetMaterial(subset->MaterialID); if(material) evTrunkTexture->SetResource(material->pDiffuseRV11); pass->Apply(0, deviceContext); deviceContext->DrawIndexedInstanced((unsigned)subset->IndexCount, drawInstanceCount, (unsigned)subset->IndexStart, (int)subset->VertexStart,0); //deviceContext->DrawIndexed((unsigned)subset->IndexCount, (unsigned)subset->IndexStart, (int)subset->VertexStart); } /*deviceContext->IASetInputLayout(inputLayoutLOD1); unsigned stride = sizeof(float) * 3; unsigned offset = 0; deviceContext->IASetVertexBuffers(0, 1, &instanceBuffer, &stride, &offset); deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); evWorld->SetMatrix(Matrix::createScale(Vector3(9))); passLOD1->Apply(0, deviceContext); deviceContext->Draw(INSTANCE_COUNT, 0);*/ deviceContext->Release(); }
static void DoRendering (const float* worldMatrix, const float* identityMatrix, float* projectionMatrix, const MyVertex* verts) { // Does actual rendering of a simple triangle #if SUPPORT_D3D11 // D3D11 case if (s_DeviceType == kUnityGfxRendererD3D11 && EnsureD3D11ResourcesAreCreated()) { ID3D11DeviceContext* ctx = NULL; g_D3D11Device->GetImmediateContext (&ctx); ID3D11RenderTargetView* pCurrentRenderTarget; ID3D11DepthStencilView* pCurrentDepthStencil; // Get the current render targets ctx->OMGetRenderTargets(1, &pCurrentRenderTarget, &pCurrentDepthStencil); ctx->OMSetRenderTargets(1, &g_pD3D11RenderTargetView, nullptr); /* // update native texture from code D3D11_TEXTURE2D_DESC desc; g_TexturePointer->GetDesc(&desc); unsigned char* data = new unsigned char[desc.Width*desc.Height * 4]; FillTextureFromCode(desc.Width, desc.Height, desc.Width * 4, data); ctx->UpdateSubresource(g_TexturePointer, 0, NULL, data, desc.Width * 4, 0); delete[] data; */ const float CLEAR_CLR[4] = { 1, 1, 0, 1 }; // Yellow ctx->ClearRenderTargetView(g_pD3D11RenderTargetView, CLEAR_CLR); // Restore the original render target ctx->OMSetRenderTargets(1, &pCurrentRenderTarget, pCurrentDepthStencil); // update constant buffer - just the world matrix in our case ctx->UpdateSubresource (g_D3D11CB, 0, NULL, worldMatrix, 64, 0); // set shaders ctx->VSSetConstantBuffers (0, 1, &g_D3D11CB); ctx->VSSetShader (g_D3D11VertexShader, NULL, 0); ctx->PSSetShader (g_D3D11PixelShader, NULL, 0); // update vertex buffer ctx->UpdateSubresource (g_D3D11VB, 0, NULL, verts, sizeof(verts[0])*3, 0); // set input assembler data and draw ctx->IASetInputLayout (g_D3D11InputLayout); ctx->IASetPrimitiveTopology (D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); UINT stride = sizeof(MyVertex); UINT offset = 0; ctx->IASetVertexBuffers (0, 1, &g_D3D11VB, &stride, &offset); ctx->Draw (3, 0); ctx->Release(); } #endif }
void Mesh::Draw() { ID3D11DeviceContext * context = GetContext(); unsigned int offset = 0; context->IASetVertexBuffers(0,1,&vertexBuffer,&stride,&offset); context->IASetPrimitiveTopology(topology); context->Draw(numberOfVerts,0); }
void Mesh::DrawIndexed() { ID3D11DeviceContext * context = GetContext(); unsigned int offset = 0; context->IASetVertexBuffers(0,1,&vertexBuffer,&stride,&offset); context->IASetIndexBuffer(indexBuffer,DXGI_FORMAT_R32_UINT,0); context->IASetPrimitiveTopology(topology); context->DrawIndexed(numberOfIndecies,0,0); }
void Terrain::DrawShadowMap(const Camera& cam) { ID3D11DeviceContext* dc = pDeviceContext; dc->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST); dc->IASetInputLayout(InputLayouts::Terrain); UINT stride = sizeof(Vertex::Terrain); UINT offset = 0; dc->IASetVertexBuffers(0, 1, &mQuadPatchVB, &stride, &offset); dc->IASetIndexBuffer(mQuadPatchIB, DXGI_FORMAT_R16_UINT, 0); XMMATRIX view = XMLoadFloat4x4(&d3d->m_LightView); XMMATRIX proj = XMLoadFloat4x4(&d3d->m_LightProj); XMMATRIX viewProj = XMMatrixMultiply(view, proj); XMMATRIX world = XMLoadFloat4x4(&mWorld); XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world); XMMATRIX worldViewProj = world*viewProj; XMMATRIX ShadowTransform = world * XMLoadFloat4x4(&d3d->m_ShadowTransform); XMFLOAT4 worldPlanes[6]; ExtractFrustumPlanes(worldPlanes, cam.ViewProj()); // Set per frame constants. Effects::TerrainFX->SetViewProj(viewProj); Effects::TerrainFX->SetEyePosW(cam.GetPosition()); Effects::TerrainFX->SetMinDist(20.0f); Effects::TerrainFX->SetMaxDist(400.0f); Effects::TerrainFX->SetMinTess(0.0f); Effects::TerrainFX->SetMaxTess(3.0f); Effects::TerrainFX->SetTexelCellSpaceU(1.0f / mInfo.HeightmapWidth); Effects::TerrainFX->SetTexelCellSpaceV(1.0f / mInfo.HeightmapHeight); Effects::TerrainFX->SetWorldCellSpace(mInfo.CellSpacing); Effects::TerrainFX->SetWorldFrustumPlanes(worldPlanes); Effects::TerrainFX->SetHeightMap(mHeightMapSRV); Effects::TerrainFX->SetShadowMap(d3d->GetShadowMap()); Effects::TerrainFX->SetShadowTransform(ShadowTransform); ID3DX11EffectTechnique* tech = Effects::TerrainFX->TessBuildShadowMapTech; D3DX11_TECHNIQUE_DESC techDesc; tech->GetDesc( &techDesc ); for(UINT i = 0; i < techDesc.Passes; ++i) { ID3DX11EffectPass* pass = tech->GetPassByIndex(i); pass->Apply(0, dc); dc->DrawIndexed(mNumPatchQuadFaces*4, 0, 0); } //dc->HSSetShader(0, 0, 0); //dc->DSSetShader(0, 0, 0); }
void FBXObject::SetupDrawVertexBuffer() { ID3D11DeviceContext* pImmediateContext = DX11App::getInstance()->direct3d.pImmediateContext; UINT stride = sizeof( cFBXBuffer::SimpleSkinnedVertex ); UINT offset = 0; pImmediateContext->IASetVertexBuffers( 0, 1, &(this->pMeshVertexBuffer.second), &stride, &offset ); pImmediateContext->IASetIndexBuffer( this->pMeshIndexBuffer.second, DXGI_FORMAT_R16_UINT, 0 ); pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); }
void CGUIShaderDX::RestoreBuffers(void) { const unsigned stride = sizeof(Vertex); const unsigned offset = 0; ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context(); // Set the vertex buffer to active in the input assembler so it can be rendered. pContext->IASetVertexBuffers(0, 1, &m_pVertexBuffer, &stride, &offset); // Set the type of primitive that should be rendered from this vertex buffer, in this case triangles. pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); }
~CDX11StateGuard() { ID3D11Device* pDevice = static_cast<ID3D11Device*>( gD3DDevice ); ID3D11DeviceContext* pContext = NULL; pDevice->GetImmediateContext( &pContext ); // Apply saved state pContext->OMSetBlendState( m_pBlendState, m_BlendFactor, m_SampleMask ); pContext->RSSetState( m_pRasterizerState ); pContext->IASetPrimitiveTopology( m_PrimitiveTopology ); pContext->IASetIndexBuffer( m_pIndexBuffer, m_IndexBufferFormat, m_IndexBufferOffset ); pContext->IASetInputLayout( m_pInputLayout ); pContext->IASetVertexBuffers( 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, m_pVertexBuffers, m_pVertexBufferStrides, m_pVertexBufferOffsets ); pContext->VSSetShader( m_pVertexShader, m_ppVertexShaderClassInstances, m_VertexShaderClassInstancesCount ); pContext->PSSetShader( m_pPixelShader, m_ppPixelShaderClassInstances, m_PixelShaderClassInstancesCount ); pContext->PSSetSamplers( 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, m_ppPixelShaderSamplers ); pContext->PSSetShaderResources( 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, m_ppPixelShaderResources ); // Release references SAFE_RELEASE( m_pBlendState ); SAFE_RELEASE( m_pRasterizerState ); SAFE_RELEASE( m_pIndexBuffer ); SAFE_RELEASE( m_pInputLayout ); for ( UINT i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i ) { SAFE_RELEASE( m_pVertexBuffers[i] ); } SAFE_RELEASE( m_pVertexShader ); for ( UINT i = 0; i < m_VertexShaderClassInstancesCount; ++i ) { SAFE_RELEASE( m_ppVertexShaderClassInstances[i] ); } SAFE_RELEASE( m_pPixelShader ); for ( UINT i = 0; i < m_PixelShaderClassInstancesCount; ++i ) { SAFE_RELEASE( m_ppPixelShaderClassInstances[i] ); } for ( UINT i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i ) { SAFE_RELEASE( m_ppPixelShaderSamplers[i] ); } for ( UINT i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i ) { SAFE_RELEASE( m_ppPixelShaderResources[i] ); } }
void ParticleManager::UpdateParticles(float dt, DxGraphics* pDxGraphics, Camera& cam) { // Update the world mat XMMATRIX transMat = XMMatrixTranslation(0.0f, 0.0f, 0.0f); XMMATRIX rotMat = XMMatrixRotationRollPitchYaw(0.0f, 0.0f, 0.0f); XMMATRIX scaleMat = XMMatrixScaling(1.0f, 1.0f, 1.0f); m_worldMat = rotMat * scaleMat * transMat; cam.CalculateViewMatrix(); // stream out the particles which runs through the physics XMMATRIX tWorld = XMMatrixTranspose(m_worldMat); XMMATRIX tView = XMMatrixTranspose(cam.GetViewMatrix()); XMMATRIX tProj = XMMatrixTranspose(cam.GetProjMatrix()); m_massPoint.dt = dt; ID3D11DeviceContext* pCon = pDxGraphics->GetImmediateContext(); // Set the stream out buffer UINT offsetSO[1] = { 0 }; pCon->SOSetTargets(1, &m_vStream, offsetSO); UINT stride = sizeof(Particle); UINT offset = 0; pCon->IASetVertexBuffers(0, 1, &m_vBuffer, &stride, &offset); pCon->IASetInputLayout(m_inputLayout); pCon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); pCon->VSSetShader(m_vUpdate, 0, 0); pCon->GSSetShader(m_gUpdate, 0, 0); pCon->PSSetShader(NULL, 0, 0); //// Update the cBuffer pCon->UpdateSubresource(m_pointBuffer, 0, NULL, &m_massPoint, 0, 0); pCon->VSSetConstantBuffers(3, 1, &m_pointBuffer); pCon->Draw(m_particleList.size(), 0); pCon->VSSetShader(NULL, 0, 0); pCon->GSSetShader(NULL, 0, 0); pCon->PSSetShader(NULL, 0, 0); // Unbind the SO ID3D11Buffer* bufferArray[1] = { 0 }; pCon->SOSetTargets(1, bufferArray, offsetSO); std::swap(m_vStream, m_vBuffer); }
void DiffuseModel::renderBuffers() { unsigned int stride; unsigned int offset; stride = sizeof(VertexType); offset = 0; ID3D11DeviceContext * deviceContext = GraphicsDX::GetDeviceContext(); deviceContext->IASetVertexBuffers(0, 1, &_vertexBuffer, &stride, &offset); deviceContext->IASetIndexBuffer(_indexBuffer, DXGI_FORMAT_R32_UINT, 0); deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); }
//--------------------------------------------------------------------------- void TexturedShader::DrawRenderable(const RenderableNode& r) { // update per draw cb. ID3D11DeviceContext* dc = m_rc->Context(); ID3D11ShaderResourceView* textures[] = {NULL, NULL, NULL}; ConstantBufferPerDraw constBuff; Matrix::Transpose(r.WorldXform, constBuff.cb_world ); constBuff.cb_hasDiffuseMap = 0; constBuff.cb_hasNormalMap = 0; constBuff.cb_hasSpecularMap = 0; constBuff.cb_lighting = r.lighting; Matrix w = r.WorldXform; w.M41 = w.M42 = w.M43 = 0; w.M44 = 1; Matrix::Invert(w,constBuff.cb_worldInvTrans); Matrix::Transpose(r.TextureXForm, constBuff.cb_textureTrans); constBuff.cb_matDiffuse = r.diffuse; constBuff.cb_matEmissive = r.emissive; constBuff.cb_matSpecular = float4(r.specular.x,r.specular.y, r.specular.z, r.specPower); if(r.textures[TextureType::DIFFUSE]) { constBuff.cb_hasDiffuseMap = 1; textures[0] = r.textures[TextureType::DIFFUSE]->GetView(); } if(r.textures[TextureType::NORMAL]) { constBuff.cb_hasNormalMap = 1; textures[1] = r.textures[TextureType::NORMAL]->GetView(); } UpdateConstantBuffer(dc,m_pConstantBufferPerDraw,&constBuff, sizeof(constBuff)); dc->PSSetShaderResources( 0, ARRAY_SIZE(textures), textures ); uint32_t stride = r.mesh->vertexBuffer->GetStride(); uint32_t offset = 0; uint32_t startIndex = 0; uint32_t startVertex = 0; uint32_t indexCount = r.mesh->indexBuffer->GetCount(); ID3D11Buffer* d3dvb = r.mesh->vertexBuffer->GetBuffer(); ID3D11Buffer* d3dib = r.mesh->indexBuffer->GetBuffer(); dc->IASetPrimitiveTopology( (D3D11_PRIMITIVE_TOPOLOGY)r.mesh->primitiveType ); dc->IASetVertexBuffers( 0, 1, &d3dvb, &stride, &offset ); dc->IASetIndexBuffer(d3dib, DXGI_FORMAT_R32_UINT, 0); dc->DrawIndexed(indexCount, startIndex, startVertex); }
// Callbacks to draw things in world space, left-hand space, and right-hand // space. void DrawWorld( void* userData //< Passed into AddRenderCallback , osvr::renderkit::GraphicsLibrary library //< Graphics library context to use , osvr::renderkit::RenderBuffer buffers //< Buffers to use , osvr::renderkit::OSVR_ViewportDescription viewport //< Viewport we're rendering into , OSVR_PoseState pose //< OSVR ModelView matrix set by RenderManager , osvr::renderkit::OSVR_ProjectionMatrix projection //< Projection matrix set by RenderManager , OSVR_TimeValue deadline //< When the frame should be sent to the screen ) { // Make sure our pointers are filled in correctly. if (library.D3D11 == nullptr) { std::cerr << "DrawWorld: No D3D11 GraphicsLibrary, this should not happen" << std::endl; return; } if (buffers.D3D11 == nullptr) { std::cerr << "DrawWorld: No D3D11 RenderBuffer, this should not happen" << std::endl; return; } ID3D11DeviceContext* context = library.D3D11->context; ID3D11RenderTargetView* renderTargetView = buffers.D3D11->colorBufferView; // Set vertex buffer UINT stride = sizeof(SimpleVertex); UINT offset = 0; context->IASetVertexBuffers(0, 1, &g_vertexBuffer, &stride, &offset); // Set primitive topology context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); // Set depth/stencil state context->OMSetDepthStencilState(g_depthStencilState, 1); // Draw a triangle using the simple shaders context->VSSetShader(vertexShader.Get(), nullptr, 0); context->PSSetShader(pixelShader.Get(), nullptr, 0); context->Draw(3, 0); }
void Shader::bind(D3DRenderer* renderer) { ID3D11DeviceContext* context = renderer->context(); context->IASetInputLayout(mpInputLayout); context->IASetPrimitiveTopology(mPrimitiveTopology); //Set any active shaders and disable ones not in use context->VSSetShader(mpVertexShader, NULL, 0); context->PSSetShader(mpPixelShader, NULL, 0); context->GSSetShader(mpGeometryShader, NULL, 0); context->CSSetShader(mpComputeShader, NULL, 0); context->HSSetShader(mpHullShader, NULL, 0); context->DSSetShader(mpDomainShader, NULL, 0); }
void COverlayQuadsDX::Render(SRenderState &state) { if (m_count == 0) return; ID3D11Buffer* vertexBuffer = m_vertex.Get(); if (vertexBuffer == nullptr) return; ID3D11DeviceContext* pContext = DX::DeviceResources::Get()->GetD3DContext(); CGUIShaderDX* pGUIShader = DX::Windowing()->GetGUIShader(); XMMATRIX world, view, proj; pGUIShader->GetWVP(world, view, proj); if (CServiceBroker::GetWinSystem()->GetGfxContext().GetStereoMode() == RENDER_STEREO_MODE_SPLIT_HORIZONTAL || CServiceBroker::GetWinSystem()->GetGfxContext().GetStereoMode() == RENDER_STEREO_MODE_SPLIT_VERTICAL) { CRect rect; DX::Windowing()->GetViewPort(rect); DX::Windowing()->SetCameraPosition(CPoint(rect.Width() * 0.5f, rect.Height() * 0.5f), static_cast<int>(rect.Width()), static_cast<int>(rect.Height())); } XMMATRIX trans = XMMatrixTranslation(state.x, state.y, 0.0f); XMMATRIX scale = XMMatrixScaling(state.width, state.height, 1.0f); pGUIShader->SetWorld(XMMatrixMultiply(XMMatrixMultiply(world, scale), trans)); const unsigned stride = sizeof(Vertex); const unsigned offset = 0; // Set the vertex buffer to active in the input assembler so it can be rendered. pContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset); // Set the type of primitive that should be rendered from this vertex buffer, in this case triangles. pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); DX::Windowing()->SetAlphaBlendEnable(true); pGUIShader->Begin(SHADER_METHOD_RENDER_FONT); pGUIShader->SetShaderViews(1, m_texture.GetAddressOfSRV()); pGUIShader->Draw(m_count * 6, 0); // restoring transformation pGUIShader->SetWVP(world, view, proj); pGUIShader->RestoreBuffers(); }
void D3D11Mesh::Render() { ID3D11DeviceContext* pContext = m_shader->GetContext(); ID3D11ShaderResourceView* ptexRv = dynamic_cast<D3D11Texture*>(m_tex)->m_textureRV; unsigned int stride = sizeof(Vertex); unsigned int offset = 0; pContext->IASetInputLayout(m_vertexLayout); pContext->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset); pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); pContext->PSSetShaderResources(0, 1, &ptexRv); pContext->Draw(m_numtriangles*3, 0); }
void D3D11App::DebugViewTexture2D(ID3D11ShaderResourceView *srv, const float x, const float y, const float width, const float height, const int slice) { // Make sure we have enough space in the vertex buffer SetToolsVBSize(4 * sizeof(Pos2Tex3)); // Fill vertex buffer Pos2Tex3 *dest; ID3D11DeviceContext* context = m_context->GetDeviceContext(); D3D11_MAPPED_SUBRESOURCE resource; context->Map(m_toolsVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &resource); dest = reinterpret_cast<Pos2Tex3*> ( resource.pData ); dest[0].pos = float2(x, y + height); dest[0].tex = float3(0, 0, (float) slice); dest[1].pos = float2(x + width, y + height); dest[1].tex = float3(1, 0, (float) slice); dest[2].pos = float2(x, y); dest[2].tex = float3(0, 1, (float) slice); dest[3].pos = float2(x + width, y); dest[3].tex = float3(1, 1, (float) slice); context->Unmap(m_toolsVB, 0); ID3D11DeviceContext *dev = m_context->GetDeviceContext(); // Setup the effect m_context->SetEffect(m_toolsEffect); if (slice < 0) { m_context->SetTexture("tex2d", srv); m_context->Apply(2, 0); } else { m_context->SetTexture("texArray", srv); m_context->Apply(2, 1); } dev->IASetInputLayout(m_pos2Tex3Layout); UINT stride = sizeof(Pos2Tex3); UINT offset = 0; dev->IASetVertexBuffers(0, 1, &m_toolsVB, &stride, &offset); // Render a textured quad dev->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); dev->Draw(4, 0); }
void D3D11App::RenderBillboards(const float3 *position, const int count, const float size, const float4 &color) { // Make sure we have enough room in the tool vertex buffer SetToolsVBSize(count * 6 * sizeof(float3)); float3 dx, dy; m_camera.GetBaseVectors(&dx, &dy, NULL); // Fill vertex buffer float3 *dest; ID3D11DeviceContext* context = m_context->GetDeviceContext(); D3D11_MAPPED_SUBRESOURCE resource; context->Map( m_toolsVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &resource); dest = reinterpret_cast<float3*> ( resource.pData ); for (int i = 0; i < count; i++) { dest[6 * i + 0] = position[i] + size * (-dx + dy); dest[6 * i + 1] = position[i] + size * ( dx + dy); dest[6 * i + 2] = position[i] + size * (-dx - dy); dest[6 * i + 3] = position[i] + size * (-dx - dy); dest[6 * i + 4] = position[i] + size * ( dx + dy); dest[6 * i + 5] = position[i] + size * ( dx - dy); } context->Unmap(m_toolsVB, 0 ); ID3D11DeviceContext *dev = m_context->GetDeviceContext(); // Set constants float4x4 *mvp; dev->Map(m_toolsVsCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &resource); mvp = reinterpret_cast<float4x4*> ( resource.pData ); *mvp = m_camera.GetModelViewProjection(); dev->Unmap(m_toolsVsCB, 0); float4 *col; dev->Map( m_toolsPsCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &resource); col = reinterpret_cast<float4*> ( resource.pData ); *col = color; dev->Unmap( m_toolsPsCB, 0 ); // Setup effect m_context->SetEffect(m_toolsEffect); m_context->Apply(1, 0); dev->IASetInputLayout(m_pos3Layout); UINT stride = sizeof(float3); UINT offset = 0; dev->IASetVertexBuffers(0, 1, &m_toolsVB, &stride, &offset); // Render the quads dev->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); dev->Draw(6 * count, 0); }