Example #1
0
void CALLBACK OnFrameMove(_In_ double fTime, _In_ float fElapsedTime, _In_opt_ void* pUserContext)
{
	static float rot = 0.0f;
	rot += fElapsedTime;
	XMMATRIX mscale = XMMatrixScaling(1.0f, 1.0f, 1.0f);
	XMMATRIX mrot	= XMMatrixRotationRollPitchYaw(0.0f, 0.0f, rot);
	XMMATRIX mtrans = XMMatrixTranslation(20.0f, 50.0f, 0.0f);

	// gmesh 의 월드 매트릭스 -> XMMATRIX
	XMMATRIX mParent = XMLoadFloat4x4(&g_mesh->getWorld());

	g_matLight = (mscale * mtrans * mrot) * mParent;
	
	// 조명 메시 연결
	XMFLOAT4X4 mlit = XMFLOAT4X4();
	XMStoreFloat4x4(&mlit, g_matLight);
	g_meshLight->setWorld(mlit);


	g_camera.FrameMove(fElapsedTime);




}
Example #2
0
	void ProxyModel::Draw(const GameTime& gameTime)
	{
		ID3D11DeviceContext* direct3DDeviceContext = mGame->GetD3DDeviceContext();			
		direct3DDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
		direct3DDeviceContext->IASetInputLayout(mInputLayout.Get());

		UINT stride = sizeof(VertexPositionColorAlpha);
		UINT offset = 0;
		direct3DDeviceContext->IASetVertexBuffers(0, 1, mVertexBuffer.GetAddressOf(), &stride, &offset);
		direct3DDeviceContext->IASetIndexBuffer(mIndexBuffer.Get(), DXGI_FORMAT_R32_UINT, 0);

		direct3DDeviceContext->VSSetShader(mVertexShader.Get(), nullptr, 0);
		direct3DDeviceContext->PSSetShader(mPixelShader.Get(), nullptr, 0);

		XMMATRIX worldMatrix = XMLoadFloat4x4(&mWorldMatrix);
		XMMATRIX wvp = worldMatrix * mCamera->ViewProjectionMatrix();
		XMStoreFloat4x4(&mVertexCBufferPerObjectData.WorldViewProjection, XMMatrixTranspose(wvp));

		direct3DDeviceContext->UpdateSubresource(mVertexCBufferPerObject.Get(), 0, nullptr, &mVertexCBufferPerObjectData, 0, 0);
		direct3DDeviceContext->VSSetConstantBuffers(0, 1, mVertexCBufferPerObject.GetAddressOf());

		if (mDisplayWireframe)
		{
			mGame->GetD3DDeviceContext()->RSSetState(RasterizerStates::Wireframe.Get());
			direct3DDeviceContext->DrawIndexed(mIndexCount, 0, 0);
			mGame->GetD3DDeviceContext()->RSSetState(nullptr);
		}
		else
		{
			direct3DDeviceContext->DrawIndexed(mIndexCount, 0, 0);
		}
	}
Example #3
0
	void KungFuPOC::UpdateKinectSkeletonData()
	{
		float3 offset(0.0, 0.0, 0.0);
		
		SkeletonData data;
		kinectController.GetSkeletonData(&data);
		int skeletonIndex = GetActiveSkeleton(data.skeletonData);
		if (skeletonIndex < 0) return;

		NUI_SKELETON_DATA skeleton = data.skeletonData[skeletonIndex];
		Vector4* positions = skeleton.SkeletonPositions;
		
		float dz = 0.0;
		for (int i = 0; i != NUI_SKELETON_POSITION_COUNT; ++i) {			
			Vector4& pos = positions[i];
			pos.z = -pos.z;
			// don't let player come too close to the painting!
			if (i == 0) {
				if (pos.z > PAINTING_Z - MINIMUM_PLAYER_DISTANCE) {
					dz = pos.z - (PAINTING_Z - MINIMUM_PLAYER_DISTANCE);
				}
			}
			pos.z -= dz;
		}

		stickFigureMesh->Update(deviceContext, positions);

		matrix4x4 projectionMtx = XMLoadFloat4x4(&projection);
		for (auto it = paintLogics.begin(); it != paintLogics.end(); ++it) {
			deviceContext->OMSetRenderTargets(1, &backBufferView, depthStencilView);
			SetViewport(0, 0, (float)windowWidth, (float)windowHeight);
			(*it)->Update(projectionMtx, deviceContext, positions);
		}
	}
void cGridMesh::Draw()
{
	// Set Layout And Topology
	g_pD3DDC->IASetInputLayout(cInputLayouts::Simple);
	g_pD3DDC->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	// Set VertexBuffer And IndexBuffer
	UINT stride = sizeof(Vertex::Simple);
	UINT offset = 0;
	g_pD3DDC->IASetVertexBuffers(0, 1, &m_VB, &stride, &offset);
	g_pD3DDC->IASetIndexBuffer(m_IB, DXGI_FORMAT_R32_UINT, 0);

	// worldViewProj Çà·ÄÀ» ±¸ÇÑ´Ù.
	XMMATRIX world	= XMLoadFloat4x4(&GetTransformMatrix());
	XMMATRIX view	= g_pCameraManager->GetView();
	XMMATRIX proj	= g_pCameraManager->GetProj();
	XMMATRIX worldViewProj = world * view * proj;

	// ¼ÎÀÌ´õ¿¡ »ó¼ö°ª ¼³Á¤.
	cEffects::SimpleFX->SetWorldViewProj(worldViewProj);

	ID3DX11EffectTechnique* tech = cEffects::SimpleFX->ColorTech;
	D3DX11_TECHNIQUE_DESC techDesc;
	tech->GetDesc(&techDesc);
	for (UINT p = 0; p < techDesc.Passes; ++p)
	{
		tech->GetPassByIndex(p)->Apply(0, g_pD3DDC);

		// »öÀÎÀ» »ç¿ëÇؼ­ ±×¸°´Ù.
		g_pD3DDC->DrawIndexed(m_GridIndexCount, 0, 0);
	}

	HR(g_pD3DSC->Present(0, 0));
}
Example #5
0
void CPlayer::RotateY(float fAngle)
{
    XMMATRIX matRotY = XMMatrixRotationY(fAngle);
    //CXMMATRIX 형식으로 바꿀 필요 있음.
    XMMATRIX matWorld = XMLoadFloat4x4( &m_matWorld );
    XMStoreFloat4x4( &m_matWorld , XMMatrixMultiply( matWorld , matRotY) );
}
Example #6
0
void RenderSystem::CheckPick()
{
	float tempDist;
	float closestDist = FLT_MAX;
	int hitIndex;
	float pickedDist = 0;

	XMMATRIX Proj      = XMMatrixPerspectiveFovLH(0.4f*3.14f, GetAspect(), 1.0f, 1000.0f);
	d3dPicking.PickRayVector(m_Camera.GetMouseX(), m_Camera.GetMouseY(), XMLoadFloat4x4(&m_Camera.GetViewMatrix()), Proj);

	//Check if picking the object and mark it
	for (int i = 0; i < 20; i++)
	{
		if (bottleHit[i] == 0) //No need to check bottles already hit
		{
			tempDist = d3dPicking.Pick(bottleModel[i]);
			if (tempDist < closestDist)
			{
				closestDist = tempDist;
				hitIndex = i;
			}
		}
	}

	//We pick a object, and set the closest one be the target object
	if (closestDist < FLT_MAX)
	{
		bottleHit[hitIndex] = 1;
		pickedDist = closestDist;
		++score;
	}

}
void Simulation::Draw()
{
	m_Camera.UpdateViewMatrix();

	XMStoreFloat4x4(&(matrixBufferData.view), XMMatrixTranspose(m_Camera.View()));
	
	const float clearColor[4] = { 0.0f, 0.0, 0.0f, 1.0f };

	devCon->ClearRenderTargetView(renderTargetView, clearColor);
	devCon->ClearDepthStencilView(depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);

	float blendFactors[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
	devCon->OMSetBlendState(blendState, blendFactors, 0xFFFFFF);

	devCon->IASetInputLayout(inputLayout);
	devCon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	devCon->VSSetConstantBuffers(0, 1, &matrixBuffer);
	devCon->OMSetDepthStencilState(depthStencilState, 0);

	for (GameObject* obj : objects)
	{
		devCon->RSSetState(current);
		XMStoreFloat4x4(&(matrixBufferData.world), XMLoadFloat4x4(&(obj->GetWorldMatrix())));
		devCon->UpdateSubresource(matrixBuffer, 0, NULL, &matrixBufferData, 0, 0);
		obj->Draw(devCon);
	}
	
	swapChain->Present(0, 0);
}
Example #8
0
void Entity::Draw2D(ID3DX11EffectTechnique* activeTech, ID3D11DeviceContext* context, UINT pass, const Camera& camera, XMMATRIX& ortho)
{
	XMMATRIX world = XMLoadFloat4x4(&mWorld);
	XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);

	XMMATRIX worldViewProj = world*ortho;
	Effects::BasicFX->SetWorld(world);
	Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
	Effects::BasicFX->SetWorldViewProj(worldViewProj);

	if (!useTexTrans){ Effects::BasicFX->SetTexTransform(XMMatrixScaling(origTexScale.x, origTexScale.y, origTexScale.z)); }
	if (mBasicTexTrans)
	{
		XMMATRIX Scale;
		mFlipTexture ? Scale = XMMatrixScaling(-origTexScale.x, origTexScale.y, origTexScale.z) : Scale = XMMatrixScaling(origTexScale.x, origTexScale.y, origTexScale.z);
		Effects::BasicFX->SetTexTransform(XMMatrixTranslation(texTrans.x, texTrans.y, texTrans.z)*Scale);
	}
	if (mUseAnimation)
	{
		XMMATRIX Scale;
		mAnim->Flipped() ? Scale = XMMatrixScaling(-origTexScale.x, origTexScale.y, origTexScale.z) : Scale = XMMatrixScaling(origTexScale.x, origTexScale.y, origTexScale.z);
		Effects::BasicFX->SetTexTransform(XMMatrixTranslation(mAnim->GetX(), mAnim->GetY(), texTrans.z)*Scale);
	}
	Effects::BasicFX->SetMaterial(mMat);
	Effects::BasicFX->SetDiffuseMap(mTexSRV);

	activeTech->GetPassByIndex(pass)->Apply(0, context);
	context->DrawIndexed(mIndexCount, mIndexOffset, mVertexOffset);
}
Example #9
0
void Transform::UpdateCBuffer()
{
	//updatesubresource med den nya transformData
	XMMATRIX tempWorld = XMMatrixIdentity();

	XMMATRIX tempScale = XMMatrixIdentity();
	XMMATRIX tempRotation = XMMatrixIdentity();
	XMMATRIX tempPosition = XMMatrixIdentity();

	tempScale = XMMatrixScaling(transformData.scale.x, transformData.scale.y, transformData.scale.z);
	//XMMatrixRotationQuaternion använd en quaternion istället! cool stuff, sen bör det funka
	//transformData.pos.z = transformData.pos.z * -1.0f;
	//transformData.rot.x = transformData.rot.x * -1.0f;
	//transformData.rot.y = transformData.rot.y * -1.0f;
	XMVECTOR rotationQuat = XMVectorSet(transformData.rot.x, transformData.rot.y, transformData.rot.z, transformData.rot.w);
	tempRotation = XMMatrixRotationQuaternion(rotationQuat);
	tempPosition = XMMatrixTranslation(transformData.pos.x, transformData.pos.y, transformData.pos.z);

	tempWorld = tempRotation * tempScale * tempPosition;
	if (parent != nullptr)
	{
		parent->UpdateCBuffer();
		XMMATRIX parentWorld = XMLoadFloat4x4(&parent->transformCBufferData.world);
		tempWorld = tempWorld /** parentWorld*/;
	}

	XMStoreFloat4x4(&transformCBufferData.world, XMMatrixTranspose(tempWorld));
	//transformdata ligger på plats 0, material på 1, osv
	gDeviceContext->UpdateSubresource(transformCBuffer, 0, NULL, &transformCBufferData.world, 0, 0); //skapa en separat struct för transformdata som ska in i shadern, world osv
	gDeviceContext->VSSetConstantBuffers(0, 1, &transformCBuffer);
}
Example #10
0
void LevelParts::setWorld(XMFLOAT4X4 tempLevelPartsWorld)
{


	mLevelPartsWorld = tempLevelPartsWorld;


	XMMATRIX tempWorld = XMLoadFloat4x4(&mLevelPartsWorld);


	XMVECTOR Scale;
	XMVECTOR Position;
	XMVECTOR Rotation;


	XMMatrixDecompose(&Scale, &Rotation, &Position, tempWorld);

	XMStoreFloat3(&mLevelPartsPosition, Position);

	XMStoreFloat3(&mLevelPartsScale, Scale);

	XMStoreFloat4(&mLevelPartsRotation, Rotation);





	XMVECTOR S = XMLoadFloat3(&mLevelPartsScale);
	XMVECTOR P = XMLoadFloat3(&mLevelPartsPosition);
	XMVECTOR Q = XMLoadFloat4(&mLevelPartsRotationQuad);
	XMVECTOR rot = XMLoadFloat4(&mLevelPartsRotation);

	XMStoreFloat4x4(&mLevelPartsStartingWorld, XMMatrixAffineTransformation(S, rot, Q, P));

}
Example #11
0
void InClassProj::DrawParticles()
{
	XMVECTOR eyePos = m2DCam->GetPos();
	XMMATRIX proj = XMLoadFloat4x4(&mProj);
	XMMATRIX view = m2DCam->GetView();

	XMMATRIX vp = view * proj;

	mParticleEffect->SetPerFrameParams(eyePos);
	mParticleEffect->SetPerObjectParams(vp, mParticleTexture);

	md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
	md3dImmediateContext->IASetInputLayout(Vertex::GetParticleVertLayout());
	
	UINT stride = sizeof(Vertex::ParticleVertex);
	UINT offset = 0;

	md3dImmediateContext->IASetVertexBuffers(0, 1, &mParticleVB, &stride, &offset);
	
	md3dImmediateContext->OMSetDepthStencilState(mNoDepthDS, 0);
	float blendFactor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
	md3dImmediateContext->OMSetBlendState(mAdditiveBS, blendFactor, 0xffffffff);

	D3DX11_TECHNIQUE_DESC techDesc; 
	mParticleEffect->GetTech()->GetDesc(&techDesc);
	for (UINT p = 0; p < techDesc.Passes; ++p)
	{
		mParticleEffect->GetTech()->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
		md3dImmediateContext->Draw(mParticles.size(), 0);
	}

	md3dImmediateContext->OMSetBlendState(0, blendFactor, 0xffffffff);
	md3dImmediateContext->OMSetDepthStencilState(NULL, 0);
}
void Enemies::update(float dt)
{



	DeltaTime = dt;

	for (int i = 0; i < mEnemyInstances.size(); i++)
	{

		enemyclass[i]->update(DeltaTime);

		mEnemyInstances[i].World = enemyclass[i]->GetWorld();

		XMMATRIX temp = XMLoadFloat4x4(&mEnemyInstances[i].World);
		XMVECTOR Scale;
		XMVECTOR Rotation;
		XMVECTOR Position;

		XMFLOAT3 tempPosition;

		XMMatrixDecompose(&Scale, &Rotation, &Position, temp);
		XMStoreFloat3(&tempPosition, Position);



		LevelCollisions[i].Center = tempPosition;


	}

}
Example #13
0
void LightHandler::Draw(TerrainEntity* terrain, ID3D11DeviceContext* devCon, Camera* camera)
{
	devCon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	devCon->IASetInputLayout(InputLayouts::mPos);
	
	this->mShadowMap->BindDSVAndSetRTV(devCon);
	this->mShadowMap->ResetMap();

	Effects::TerrainFX->SetShadowMap(this->mShadowMap->GetDepthSRV());

	XMMATRIX lightVP = XMMatrixMultiply(this->CalcView(camera), this->CalcProj(camera));

	Effects::TerrainFX->SetLightVP(lightVP);
	Effects::ShadowFX->SetLightVP(lightVP);

	D3DX11_TECHNIQUE_DESC techDesc = {};
	Effects::ShadowFX->mShadowTech->GetDesc(&techDesc);

	for(UINT i(0); i != techDesc.Passes; ++i)
	{
		Effects::ShadowFX->SetWorld(XMLoadFloat4x4(&terrain->GetInstance()->mWorld));

		Effects::ShadowFX->mShadowTech->GetPassByIndex(i)->Apply(0, devCon);
		terrain->GetInstance()->mModel->GetMesh()->Draw(devCon);
	}
}
Example #14
0
	//---------------------------------------------------------------------
	void Frustum::setViewParams(FXMVECTOR pos, FXMVECTOR lookAt, FXMVECTOR upDir)
	{
		XMStoreFloat4x4(&mViewMatrix, XMMatrixLookAtLH(pos, lookAt, upDir));
		XMStoreFloat4x4(&mViewProjMatrix, XMLoadFloat4x4(&mViewMatrix) * XMLoadFloat4x4(&mProjMatrix));

		/// front
		mPlanes[FS_FRONT].x = mViewProjMatrix._14 + mViewProjMatrix._13;
		mPlanes[FS_FRONT].y = mViewProjMatrix._24 + mViewProjMatrix._23;
		mPlanes[FS_FRONT].z = mViewProjMatrix._34 + mViewProjMatrix._33;
		mPlanes[FS_FRONT].w = mViewProjMatrix._44 + mViewProjMatrix._43;
		XMStoreFloat4(&mPlanes[FS_FRONT], XMPlaneNormalizeEst(XMLoadFloat4(&mPlanes[FS_FRONT])));

		/// back
		mPlanes[FS_BACK].x = mViewProjMatrix._14 - mViewProjMatrix._13;
		mPlanes[FS_BACK].y = mViewProjMatrix._24 - mViewProjMatrix._23;
		mPlanes[FS_BACK].z = mViewProjMatrix._34 - mViewProjMatrix._33;
		mPlanes[FS_BACK].w = mViewProjMatrix._44 - mViewProjMatrix._43;
		XMStoreFloat4(&mPlanes[FS_BACK], XMPlaneNormalizeEst(XMLoadFloat4(&mPlanes[FS_BACK])));

		/// left
		mPlanes[FS_LEFT].x = mViewProjMatrix._14 + mViewProjMatrix._11;
		mPlanes[FS_LEFT].y = mViewProjMatrix._24 + mViewProjMatrix._21;
		mPlanes[FS_LEFT].z = mViewProjMatrix._34 + mViewProjMatrix._31;
		mPlanes[FS_LEFT].w = mViewProjMatrix._44 + mViewProjMatrix._41;
		XMStoreFloat4(&mPlanes[FS_LEFT], XMPlaneNormalizeEst(XMLoadFloat4(&mPlanes[FS_LEFT])));

		/// right
		mPlanes[FS_RIGHT].x = mViewProjMatrix._14 - mViewProjMatrix._11;
		mPlanes[FS_RIGHT].y = mViewProjMatrix._24 - mViewProjMatrix._21;
		mPlanes[FS_RIGHT].z = mViewProjMatrix._34 - mViewProjMatrix._31;
		mPlanes[FS_RIGHT].w = mViewProjMatrix._44 - mViewProjMatrix._41;
		XMStoreFloat4(&mPlanes[FS_RIGHT], XMPlaneNormalizeEst(XMLoadFloat4(&mPlanes[FS_RIGHT])));

		/// top
		mPlanes[FS_TOP].x = mViewProjMatrix._14 - mViewProjMatrix._12;
		mPlanes[FS_TOP].y = mViewProjMatrix._24 - mViewProjMatrix._22;
		mPlanes[FS_TOP].z = mViewProjMatrix._34 - mViewProjMatrix._32;
		mPlanes[FS_TOP].w = mViewProjMatrix._44 - mViewProjMatrix._42;
		XMStoreFloat4(&mPlanes[FS_TOP], XMPlaneNormalizeEst(XMLoadFloat4(&mPlanes[FS_TOP])));

		/// buttom
		mPlanes[FS_BUTTOM].x = mViewProjMatrix._14 + mViewProjMatrix._12;
		mPlanes[FS_BUTTOM].y = mViewProjMatrix._24 + mViewProjMatrix._22;
		mPlanes[FS_BUTTOM].z = mViewProjMatrix._34 + mViewProjMatrix._32;
		mPlanes[FS_BUTTOM].w = mViewProjMatrix._44 + mViewProjMatrix._42;
		XMStoreFloat4(&mPlanes[FS_BUTTOM], XMPlaneNormalizeEst(XMLoadFloat4(&mPlanes[FS_BUTTOM])));
	}
Example #15
0
//Needs to be called befor all other drawcalls, and ended with "EndDraw()"
void DirectXGraphicEngine::BeginDraw()
{
	if (m_IsDrawing)
	{
		Logger::Log( "Rendering call Begin was called before end was called", "DirectXRenderSystem", LoggerType::MSG_ERROR );
		return;
	}

	//clear the backbuffer, and depthstencil buffer
	float t_Black[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
	m_DeviceContext->ClearRenderTargetView(m_RenderTargetView, t_Black);
	m_DeviceContext->ClearDepthStencilView(m_DepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);

	//clear gbuffers
	for (int i = 0; i < 3; i++)
	{
		m_DeviceContext->ClearRenderTargetView(m_GBufferRTV[i], t_Black);
	}

	m_IsDrawing = true;

	UINT t_Strides = sizeof(XMFLOAT4X4);
	UINT t_Offsets = 0;

	m_DeviceContext->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	m_DeviceContext->IASetVertexBuffers(1, 1, &m_InstanceBuffer, &t_Strides, &t_Offsets);



	//update viewmatrix
	DirectXMatrixLibrary* t_MatrixLib = (DirectXMatrixLibrary*)t_MatrixLib->GetInstance();

	UINT t_Size = m_View.size();
	for (size_t i = 0; i < t_Size; i++)
	{
		PerFrameCBuffer t_PFB;
		t_PFB.View = *t_MatrixLib->GetMatrix(m_View.at(i).camera.transformMatrixHandle);
		t_PFB.Proj = *t_MatrixLib->GetMatrix(m_View.at(i).camera.projectionMatrixHandle);
		XMMATRIX t_View = XMLoadFloat4x4(&t_PFB.View);
		XMMATRIX t_Proj = XMLoadFloat4x4(&t_PFB.Proj);
		XMMATRIX t_ViewProj = XMMatrixMultiply(t_View, t_Proj);
		XMStoreFloat4x4(&t_PFB.ViewProj, t_ViewProj);
		
		m_DeviceContext->UpdateSubresource(m_PerFrameCBuffer, 0, nullptr, &t_PFB, 0, 0);
	}
	
}
Example #16
0
void RenderableObject::SetWVPConstantBuffer(bool dynamic) {
	HRESULT hr;

	XMMATRIX worldMat = XMLoadFloat4x4(&worldMatrix);
	XMMATRIX viewProjMat = pD3DEngine->GetViewMatrix() * pD3DEngine->GetOrthoMatrix(); //2d test
	//XMMATRIX viewProjMat = pD3DEngine->GetViewMatrix() * pD3DEngine->GetProjectionMatrix();

	if (dynamic) {
	//Lock the constant buffer so it can be written to.
	D3D11_MAPPED_SUBRESOURCE mappedResource;
	#ifdef USING_BOOST_THREADS
	pD3DEngine->LockDeviceContextMutex();
	#endif
	hr = pDeviceContext->Map(pWVPConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
	#ifdef USING_BOOST_THREADS
	pD3DEngine->UnlockDeviceContextMutex();
	#endif
	

	//Get a pointer to the data in the constant buffer.
	WVPConstantBuffer* dataPtr;
	dataPtr = (WVPConstantBuffer*)mappedResource.pData;

	XMStoreFloat4x4(&dataPtr->worldMatrix, XMMatrixTranspose(worldMat));	
	XMStoreFloat4x4(&dataPtr->viewProjMatrix, XMMatrixTranspose(viewProjMat));	

	//Unlock the constant buffer.
	#ifdef USING_BOOST_THREADS
	pD3DEngine->LockDeviceContextMutex();
	#endif
	pDeviceContext->Unmap(pWVPConstantBuffer, 0);
	#ifdef USING_BOOST_THREADS
	pD3DEngine->UnlockDeviceContextMutex();
	#endif
	
	}
	else {
		WVPConstantBuffer cbPerObj;
		XMStoreFloat4x4(&cbPerObj.worldMatrix, XMMatrixTranspose(worldMat));	
		XMStoreFloat4x4(&cbPerObj.viewProjMatrix, XMMatrixTranspose(viewProjMat));	
		#ifdef USING_BOOST_THREADS
		pD3DEngine->LockDeviceContextMutex();
		#endif
		pDeviceContext->UpdateSubresource(pWVPConstantBuffer, 0, NULL, &cbPerObj, 0, 0 );
		#ifdef USING_BOOST_THREADS
		pD3DEngine->UnlockDeviceContextMutex();
		#endif
		
	}
	//Now set the constant buffer in the vertex shader with the updated values.
	#ifdef USING_BOOST_THREADS
	pD3DEngine->LockDeviceContextMutex();
	#endif
	pDeviceContext->VSSetConstantBuffers(0, 1, &pWVPConstantBuffer);
	#ifdef USING_BOOST_THREADS
	pD3DEngine->UnlockDeviceContextMutex();
	#endif
	
}
	void FogDemo::Render(const GameTime& gameTime)
	{
		ID3D11DeviceContext2* direct3DDeviceContext = mGame.GetDirectXContext().Get();
		direct3DDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
		direct3DDeviceContext->IASetInputLayout(mInputLayout.Get());

		UINT stride = sizeof(VertexPositionTextureNormal);
		UINT offset = 0;
		direct3DDeviceContext->IASetVertexBuffers(0, 1, mVertexBuffer.GetAddressOf(), &stride, &offset);
		direct3DDeviceContext->IASetIndexBuffer(mIndexBuffer.Get(), DXGI_FORMAT_R32_UINT, 0);

		direct3DDeviceContext->VSSetShader(mVertexShader.Get(), nullptr, 0);
		direct3DDeviceContext->PSSetShader(mPixelShader.Get(), nullptr, 0);

		XMMATRIX worldMatrix = XMLoadFloat4x4(&mWorldMatrix);
		XMMATRIX wvp = worldMatrix * mCamera->ViewProjectionMatrix();
		XMStoreFloat4x4(&mVertexCBufferPerObjectData.WorldViewProjection, XMMatrixTranspose(wvp));
		XMStoreFloat4x4(&mVertexCBufferPerObjectData.World, XMMatrixTranspose(worldMatrix));

		const XMFLOAT3& cameraPosition = mCamera->Position();
		mVertexCBufferPerFrameData.CameraPosition = XMFLOAT4(cameraPosition.x, cameraPosition.y, cameraPosition.z, 1.0f);
		mPixelCBufferPerFrameData.CameraPosition = mVertexCBufferPerFrameData.CameraPosition;

		direct3DDeviceContext->UpdateSubresource(mVertexCBufferPerFrame.Get(), 0, nullptr, &mVertexCBufferPerFrameData, 0, 0);
		direct3DDeviceContext->UpdateSubresource(mVertexCBufferPerObject.Get(), 0, nullptr, &mVertexCBufferPerObjectData, 0, 0);
		direct3DDeviceContext->UpdateSubresource(mPixelCBufferPerFrame.Get(), 0, nullptr, &mPixelCBufferPerFrameData, 0, 0);
		direct3DDeviceContext->UpdateSubresource(mPixelCBufferPerObject.Get(), 0, nullptr, &mPixelCBufferPerObjectData, 0, 0);

		static ID3D11Buffer* VSConstantBuffers[] = { mVertexCBufferPerFrame.Get(), mVertexCBufferPerObject.Get() };
		direct3DDeviceContext->VSSetConstantBuffers(0, ARRAYSIZE(VSConstantBuffers), VSConstantBuffers);

		static ID3D11Buffer* PSConstantBuffers[] = { mPixelCBufferPerFrame.Get(), mPixelCBufferPerObject.Get() };
		direct3DDeviceContext->PSSetConstantBuffers(0, ARRAYSIZE(PSConstantBuffers), PSConstantBuffers);

		direct3DDeviceContext->PSSetShaderResources(0, 1, mColorTexture.GetAddressOf());
		direct3DDeviceContext->PSSetSamplers(0, 1, mColorSampler.GetAddressOf());

		direct3DDeviceContext->DrawIndexed(mIndexCount, 0, 0);

		mProxyModel->Render(gameTime);

		mRenderStateHelper.SaveAll();

		mSpriteBatch->Begin();

		std::wostringstream helpLabel;

		helpLabel << "Ambient Intensity (+X/-Y): " << mPixelCBufferPerFrameData.AmbientColor.x << "\n";
		helpLabel << L"Specular Intensity (+DPadUp/-DPadDown): " << mPixelCBufferPerObjectData.SpecularColor.x << "\n";
		helpLabel << L"Specular Power (+RightShoulder/-LeftShoulder): " << mPixelCBufferPerObjectData.SpecularPower << "\n";
		helpLabel << L"Directional Light Intensity (+A/-B): " << mPixelCBufferPerFrameData.LightColor.x << "\n";
		helpLabel << L"Rotate Directional Light (Hold Left Trigger + Right Thumb Stick)";

		mSpriteFont->DrawString(mSpriteBatch.get(), helpLabel.str().c_str(), mTextPosition);

		mSpriteBatch->End();

		mRenderStateHelper.RestoreAll();
	}
Example #18
0
void Camera::moveCam()
{
	XMVECTOR tempRight = XMLoadFloat3(&mRight);
	XMVECTOR tempUp = XMLoadFloat3(&mUp);
	XMVECTOR tempPosition = XMLoadFloat3(&mPosition);
	XMVECTOR tempForward = XMLoadFloat3(&mLook);
	



	//set the camera to look at the character
	camTarget = playerPosition;






	XMVECTOR tempTarget = XMLoadFloat3(&camTarget);

	tempTarget = XMVectorSetY(tempTarget,10);


	
	//rotate camera around the character
	camRotationMatrix = XMMatrixRotationRollPitchYaw(-camPitch, camYaw, 0);
	tempPosition = XMVector3TransformNormal(PlayerForward, camRotationMatrix);
	tempPosition = XMVector3Normalize(tempPosition);


	tempPosition = (tempPosition * -50) + tempTarget;
		
	tempPosition = XMVectorSetY(tempPosition, 30.0f);

	tempForward = XMVector3Normalize(tempTarget - tempPosition);	// Get forward vector based on target
	tempForward = XMVectorSetY(tempForward, 0.0f);	// set forwards y component to 0 so it lays only on

	tempForward= XMVector3Normalize(tempForward);

	tempRight = XMVectorSet(XMVectorGetZ(-tempForward), 0.0f, XMVectorGetX(tempForward), 0.0f);

	tempUp = XMVector3Normalize(XMVector3Cross(XMVector3Normalize(tempPosition - tempTarget), tempRight));



	XMStoreFloat3(&mRight, tempRight);
	XMStoreFloat3(&mUp, tempUp);
	XMStoreFloat3(&mPosition, tempPosition);
	XMStoreFloat3(&mLook, tempForward);

	XMMATRIX tempView = XMLoadFloat4x4(&mView);


	tempView = XMMatrixLookAtLH(tempPosition, tempTarget, tempUp);

	XMStoreFloat4x4(&mView, tempView);

	///////////mising some code maybe
}
Example #19
0
void CrateApp::DrawScene()
{
	md3dImmediateContext->ClearRenderTargetView(mRenderTargetView,reinterpret_cast<const float*>(&Colors::LightSteelBlue));
	md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);

	md3dImmediateContext->IASetInputLayout(InputLayouts::Basic32);
	md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	UINT stride = sizeof(Vertex::Basic32);
	UINT offset = 0;

	XMMATRIX view = XMLoadFloat4x4(&mView);
	XMMATRIX proj  = XMLoadFloat4x4(&mProj);
	XMMATRIX viewProj = view*proj;

	//set cbuffer per frame
	Effects::BasicFX->SetDirLights(mDirLights);
	Effects::BasicFX->SetEyePosW(mEyePosW);

	ID3DX11EffectTechnique *activeTech = Effects::BasicFX->Light2TexTech;
	D3DX11_TECHNIQUE_DESC techDesc;
	activeTech->GetDesc(&techDesc);

	for(UINT p = 0; p < techDesc.Passes; ++p)
	{
		md3dImmediateContext->IASetVertexBuffers(0,1,&mBoxVB,&stride,&offset);
		md3dImmediateContext->IASetIndexBuffer(mBoxIB,DXGI_FORMAT_R32_UINT,0);

		XMMATRIX world = XMLoadFloat4x4(&mBoxWorld);
		XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
		XMMATRIX worldViewProj = world*view*proj;

		XMMATRIX texTransform = XMLoadFloat4x4(&mTexTransform);

		Effects::BasicFX->SetWorld(world);
		Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
		Effects::BasicFX->SetWorldViewProj(worldViewProj);
		Effects::BasicFX->SetTexTransform(texTransform);
		Effects::BasicFX->SetMaterial(mBoxMat);
		Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV);

		activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
		md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset);
	}
	HR(mSwapChain->Present(0, 0));
}
Example #20
0
	void ParticleRenderer::ExtractScreenSpaceUnitVectors(const XMFLOAT4X4& projWorldMatrix) {
		// inverse, so screen->world?
		XMFLOAT4X4 invProj;
		XMStoreFloat4x4(&invProj, XMMatrixTranspose(XMLoadFloat4x4(&projWorldMatrix)));
		XMStoreFloat3(&screenSpaceUnitX, XMVector3Normalize(XMLoadFloat3((XMFLOAT3*)&invProj._11)));
		XMStoreFloat3(&screenSpaceUnitY, XMVector3Normalize(XMLoadFloat3((XMFLOAT3*)&invProj._21)));
		XMStoreFloat3(&screenSpaceUnitZ, XMVector3Normalize(XMLoadFloat3((XMFLOAT3*)&invProj._31)));
	}
Example #21
0
XMFLOAT3 EliteEnemyShip::getPosition()
{
	XMFLOAT4 pos;
	XMFLOAT4 orig = XMFLOAT4(0,0,0,1);
	XMFLOAT4X4 mat = *(body->getWorldMatrix());
	XMStoreFloat4(&pos, XMVector4Transform(XMLoadFloat4(&orig), XMLoadFloat4x4(&mat)));
	return (XMFLOAT3(pos.x, pos.y, pos.z));
}
Example #22
0
bool TerrainShaderClass::SetShadowConstantBufferParamters(ID3D11DeviceContext* pDeviceContext, ObjectClass* pObject, CameraClass* pCamera, PointLightClass* pPointLight)
{
	HRESULT result;
	D3D11_MAPPED_SUBRESOURCE mappedResource;
	ShadowBuffer* dataPtr;
	unsigned int bufferNumber;

	// Lock the constant buffer so it can be written to.
	result = pDeviceContext->Map(mShadowBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
	if (FAILED(result))
	{
		return false;
	}

	// Get a pointer to the data in the constant buffer.
	dataPtr = (ShadowBuffer*)mappedResource.pData;
	
	XMMATRIX world = XMLoadFloat4x4(&pObject->GetWorldMatrix());

	XMMATRIX view = XMLoadFloat4x4(&pCamera->GetViewMatrix());
	XMMATRIX proj = XMLoadFloat4x4(&pCamera->GetProjMatrix());

	XMMATRIX lview = XMLoadFloat4x4(&pPointLight->GetViewMatrix());
	XMMATRIX lproj = XMLoadFloat4x4(&pPointLight->GetProjMatrix());

	XMMATRIX lWVP = XMMatrixTranspose(world*lview*lproj);
	XMMATRIX WVP = XMMatrixTranspose(world*view*proj);


	XMStoreFloat4x4(&dataPtr->worldViewProj, WVP);
	XMStoreFloat4x4(&dataPtr->world, world);
	XMStoreFloat4x4(&dataPtr->LightWorldViewProj, lWVP);
	XMFLOAT3 cP = pCamera->GetPosition();
	dataPtr->camPos = XMFLOAT4(cP.x, cP.y, cP.z, 0);

	// Unlock the constant buffer.
	pDeviceContext->Unmap(mShadowBuffer, 0);

	// Set the position of the constant buffer in the vertex shader.
	bufferNumber = 0;

	// Set the constant buffer in the shader with the updated values.
	pDeviceContext->GSSetConstantBuffers(bufferNumber, 1, &mShadowBuffer);

	return true;
}
Example #23
0
// рисовать модель
bool AnimModel::Draw(bool toShadowMap) {

	// установить константы
	myXMFLOAT3 positionJP = position - Mediator::camera->GetPosition();
	XMMATRIX W_JP = XMMatrixTranslation(positionJP.x, positionJP.y, positionJP.z);
	XMMATRIX R = XMLoadFloat4x4(&GetRotationMatrix());
	if (recreateFinalMatrices) {
		if (restCurClip) CreateFinalMatrices(curClip, curFrame[curClip], finalMatrices);
		else CreateFinalMatrices(curFrame, blendFactors, finalMatrices);
		recreateFinalMatrices = false;
	}
	UINT vertexStride = sizeof(VertPos3Nor2Tex2W1Bone2);
	UINT vertexOffset = 0;

	// установить параметры
	Mediator::pDevContext->IASetVertexBuffers(0, 1, &pVertexBuffer, &vertexStride, &vertexOffset);
	Mediator::pDevContext->IASetIndexBuffer(pIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
	Mediator::pDevContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	Mediator::pDevContext->IASetInputLayout(Mediator::pInputLayoutPos3Nor3Tex2W1Bone2);
	if (toShadowMap) {
		Mediator::pDevContext->VSSetShader(Mediator::pVSShadow, NULL, 0);
		Mediator::pDevContext->PSSetShader(Mediator::pPSEmpty, NULL, 0);
	}
	else {
		Mediator::pDevContext->PSSetShaderResources(TEXTURE_BUFFER, 1, &pSRtexture);
		Mediator::pDevContext->VSSetShader(Mediator::pVSPosNorTexWBone, NULL, 0);
		Mediator::pDevContext->PSSetShader(Mediator::pPSPosNorTex, NULL, 0);
	}

	// обновить константный буфер шейдера
	D3D11_MAPPED_SUBRESOURCE mappedData;
	HR(Mediator::pDevContext->Map(Mediator::cbufAnimModel, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedData));
	CbufAnimModel* cbuf = reinterpret_cast<CbufAnimModel*>(mappedData.pData);
	XMStoreFloat4x4(&cbuf->gWorld, XMMatrixTranspose(R * W_JP));
	for (UINT i(0); i < bonesAmount; i++) {
		XMStoreFloat4x4(&cbuf->gBones[i], XMMatrixTranspose(XMLoadFloat4x4(&finalMatrices[i])));
	}
	Mediator::pDevContext->Unmap(Mediator::cbufAnimModel, 0);
	Mediator::pDevContext->VSSetConstantBuffers(SR_ANIMMODEL, 1, &Mediator::cbufAnimModel);

	// рисование
	Mediator::pDevContext->DrawIndexed(indicesAmount, 0, 0);

	return true;

}
Example #24
0
	uint Texture2DShader::Render(ID3D11DeviceContext* pDeviceContext, GraphicSettings* settings, translationData* modelData, XMFLOAT4X4 view, XMFLOAT4X4 projection, XMFLOAT4X4 ortho)
	{
		uint result;
		XMMATRIX mWorld = XMLoadFloat4x4(&modelData->objectTranslation);
		XMMATRIX mOrtho = XMLoadFloat4x4(&ortho);

		XMMATRIX WO = XMMatrixTranspose(mWorld*mOrtho);

		TBuffer data;
		XMStoreFloat4x4(&data.mWO, WO);

		result = mBuffer->SetConstantBuffer(pDeviceContext, &data);
		iferr(result) return result;

		RenderShader(pDeviceContext, modelData->indexCount, modelData->indexStart);

		return 0;
	}
void Assignment5::DrawScene()
{
    XMFLOAT4 backgroundColor;
    XMStoreFloat4(&backgroundColor, Colors::LightSteelBlue);
    md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, 
        reinterpret_cast<float*>(&backgroundColor));
    md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
    drawToDisplay();
    md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);

    XMMATRIX view = XMLoadFloat4x4(&mView);
    XMMATRIX proj = XMLoadFloat4x4(&mProj);
    XMMATRIX viewProj = view*proj;

    m_Box.draw(md3dImmediateContext, viewProj);
    m_Phone.draw(md3dImmediateContext, viewProj);
    HR(mSwapChain->Present(0, 0));
}
Example #26
0
	//! Updates the view matrix.
	void Camera::UpdateViewMatrix()
	{
		// Update the right vector.
		XMVECTOR up = XMLoadFloat3(&mUp);
		XMVECTOR dir = XMLoadFloat3(&GetDirection());
		XMVECTOR right = XMVector3Cross(up, dir);
		right = XMVector3Normalize(right);
		XMStoreFloat3(&mRight, right);

		// Update the view matrix
		XMVECTOR pos = XMLoadFloat3(&mPosition);
		XMVECTOR target = XMLoadFloat3(&mTarget);
		XMStoreFloat4x4(&mView, XMMatrixLookAtLH(pos, target, up));

		XMFLOAT4X4 viewProj;
		XMStoreFloat4x4(&viewProj, XMLoadFloat4x4(&GetViewMatrix()) * XMLoadFloat4x4(&GetProjectionMatrix()));
		mFrustum.BuildFromViewProjection(viewProj);
	}
Example #27
0
float ObjectToCamera(XMFLOAT4X4* _objMatrix, XMFLOAT3 _cameraPos)
{
	XMVECTOR obj = XMVectorZero();
	obj = XMVector3Transform(obj, XMLoadFloat4x4(_objMatrix));
	float ObjtoCameraX = XMVectorGetX(obj) - _cameraPos.x;
	float ObjtoCameraY = XMVectorGetY(obj) - _cameraPos.y;
	float ObjtoCameraZ = XMVectorGetZ(obj) - _cameraPos.z;
	return ObjtoCameraX*ObjtoCameraX + ObjtoCameraY*ObjtoCameraY + ObjtoCameraZ*ObjtoCameraZ;
}
Example #28
0
void Application::Draw()
{
    // Clear the back buffer
    float ClearColor[4] = {0.1f, 0.1f, 0.1f, 1.0f}; // red,green,blue,alpha
    _pImmediateContext->ClearRenderTargetView(_pRenderTargetView, ClearColor);
	_pImmediateContext->ClearDepthStencilView(_depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);

	XMMATRIX world1 = XMLoadFloat4x4(&_cubbe1.GetWorld());
	XMMATRIX world2 = XMLoadFloat4x4(&_cubbe2.GetWorld());
	XMMATRIX view = XMLoadFloat4x4(&_view);
	XMMATRIX projection = XMLoadFloat4x4(&_projection);

	// Draw cube 1
    ConstantBuffer cb;
	cb.mWorld = XMMatrixTranspose(world1);
	cb.mView = XMMatrixTranspose(view);
	cb.mProjection = XMMatrixTranspose(projection);
	//cb.mEyePosW = _cam.GetPosition();
	cb.mLight = _light;


	_pImmediateContext->UpdateSubresource(_pConstantBuffer, 0, nullptr, &cb, 0, 0);

	//_pImmediateContext->VSSetShader(_pVertexShader, nullptr, 0);
	//_pImmediateContext->VSSetConstantBuffers(0, 1, &_pConstantBuffer);
	//_pImmediateContext->PSSetShader(_pPixelShader, nullptr, 0);
	//_pImmediateContext->DrawIndexed(36, 0, 0);        
	_cubbe1.Draw(_pd3dDevice, _pImmediateContext, _pConstantBuffer, &cb, _pVertexShader, _pPixelShader);
	// Draw cube 2
	cb.mWorld = XMMatrixTranspose(world2);
	cb.mView = XMMatrixTranspose(view);
	cb.mProjection = XMMatrixTranspose(projection);
	cb.mLight = _light;
	//cb.mEyePosW = _cam.GetPosition();

	_pImmediateContext->UpdateSubresource(_pConstantBuffer, 0, nullptr, &cb, 0, 0);
	
	//_pImmediateContext->VSSetShader(_pVertexShader, nullptr, 0);
	//_pImmediateContext->VSSetConstantBuffers(0, 1, &_pConstantBuffer);
	//_pImmediateContext->PSSetShader(_pPixelShader, nullptr, 0);
	//_pImmediateContext->DrawIndexed(36, 0, 0);*/
	_cubbe2.Draw(_pd3dDevice, _pImmediateContext, _pConstantBuffer, &cb, _pVertexShader, _pPixelShader);
    _pSwapChain->Present(0, 0);
}
Example #29
0
void CMinotaurSpawn::SetWorldMatrix(const XMFLOAT4X4 world)
{
	m_mWorld = world;
	for (size_t i = 0; i < meshes.size(); i++)
	{
		XMMATRIX newMatrix;
		XMMATRIX tempPrefabWorld = XMLoadFloat4x4(&m_mWorld);
		XMMATRIX tempObjectWorld = XMLoadFloat4x4(&meshLocalMatricies[i]);
		newMatrix = tempObjectWorld * tempPrefabWorld;
		XMFLOAT4X4 newWorld;
		XMStoreFloat4x4(&newWorld, newMatrix);
		m_vRenderMeshes[i]->GetPositionMatrix() = newWorld;
		FindDoorStartAndEnd(i, XMFLOAT3(newWorld._41, newWorld._42, newWorld._43));



	}



	for (unsigned int collider = 0; collider < m_pvColliders.size(); collider++)
		m_pvColliders[collider]->UpdatePosition(XMFLOAT3(m_mWorld._41, m_mWorld._42, m_mWorld._43));

	for (size_t i = 0; i < m_vObjects.size(); i++)
	{

		XMMATRIX newMatrix;
		XMMATRIX tempPrefabWorld = XMLoadFloat4x4(&m_mWorld);
		XMMATRIX tempObjectWorld = XMLoadFloat4x4(&m_vObjects[i]->GetWorldMatrix());
		newMatrix = tempObjectWorld * tempPrefabWorld;
		XMFLOAT4X4 newWorld;
		XMStoreFloat4x4(&newWorld, newMatrix);


		m_vObjects[i]->SetWorldMatrix(newWorld);


		for (unsigned int collider = 0; collider < m_vObjects[i]->GetColliders().size(); collider++)
			m_vObjects[i]->GetColliders()[collider]->UpdatePosition(XMFLOAT3(world._41, world._42, world._43));

	}


}
void D3DPBRApp::DrawScene(Camera& camera)
{
	md3dImmediateContext->IASetInputLayout(InputLayouts::Basic32);
	md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	md3dImmediateContext->RSSetViewports(1, &mScreenViewport);

	UINT stride = sizeof(Vertex::Basic32);
	UINT offset = 0;

	//

	XMMATRIX view     = camera.View();
	XMMATRIX proj     = camera.Proj();
	XMMATRIX viewProj = camera.ViewProj();




	// Set per frame constants.
	Effects::CommonPassFX->SetDirLights(mDirLights);
	Effects::CommonPassFX->SetEyePosW(mCam.GetPosition());
	Effects::CommonPassFX->SetEnvMap(mDynamicCubeMapSRV);

	ID3DX11EffectTechnique* activeMeshTech = Effects::CommonPassFX->Light1Tech;

	D3DX11_TECHNIQUE_DESC techDesc;
	activeMeshTech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
	{
		// Draw the Mesh.

		if( GetAsyncKeyState('1') & 0x8000 )
			md3dImmediateContext->RSSetState(RenderStates::WireframeRS);

		md3dImmediateContext->IASetVertexBuffers(0, 1, &m_pVB, &stride, &offset);
		md3dImmediateContext->IASetIndexBuffer(m_pIB, DXGI_FORMAT_R32_UINT, 0);

		XMMATRIX world = XMLoadFloat4x4(&mMeshWorld);
		XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
		XMMATRIX worldViewProj = world*view*proj;

		Effects::CommonPassFX->SetWorld(world);
		Effects::CommonPassFX->SetWorldInvTranspose(worldInvTranspose);
		Effects::CommonPassFX->SetWorldViewProj(worldViewProj);
		Effects::CommonPassFX->SetMaterial(mMeshMat);

		activeMeshTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
		md3dImmediateContext->DrawIndexed(m_indexnum, 0, 0);

		//m_pSky->Draw(md3dImmediateContext, camera);

		// Restore default
		md3dImmediateContext->RSSetState(0);
	}

}