Ejemplo n.º 1
0
void CGUIShaderDX::ApplyChanges(void)
{
  ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context();
  D3D11_MAPPED_SUBRESOURCE res;

  if (m_bIsWVPDirty)
  {
    if (SUCCEEDED(pContext->Map(m_pWVPBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &res)))
    {
      XMMATRIX worldView = XMMatrixMultiply(m_cbWorldViewProj.world, m_cbWorldViewProj.view);
      XMMATRIX worldViewProj = XMMatrixMultiplyTranspose(worldView, m_cbWorldViewProj.projection);

      cbWorld* buffer = (cbWorld*)res.pData;
      buffer->wvp = worldViewProj;
      buffer->blackLevel = (g_Windowing.UseLimitedColor() ? 16.f / 255.f : 0.f);
      buffer->colorRange = (g_Windowing.UseLimitedColor() ? (235.f - 16.f) / 255.f : 1.0f);

      pContext->Unmap(m_pWVPBuffer, 0);
      m_bIsWVPDirty = false;
    }
  }

  // update view port buffer
  if (m_bIsVPDirty)
  {
    if (SUCCEEDED(pContext->Map(m_pVPBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &res)))
    {
      *(cbViewPort*)res.pData = m_cbViewPort;
      pContext->Unmap(m_pVPBuffer, 0);
      m_bIsVPDirty = false;
    }
  }
}
Ejemplo n.º 2
0
void BoneModel::PlayVMD(float time){
	if (!mBoneAssetDataPtr)return;
	if (mMotion.empty())return;
	VMDAnimation(time);

	// ボーン差分行列の作成、定数バッファに転送
	for (UINT ib = 0; ib<mBone.size(); ++ib){
		XMVECTOR Determinant;
		XMMATRIX invmtx = XMMatrixInverse(&Determinant, mBone[ib].mMtxPoseInit);
		XMMATRIX mtx = XMMatrixMultiplyTranspose(invmtx, mBone[ib].mMtxPose);
		mCBBoneMatrix.mParam[ib].BoneMatrix[0] = XMFLOAT4(mtx.r[0].x, mtx.r[0].y, mtx.r[0].z, mtx.r[0].w);//mtx.r[0];
		mCBBoneMatrix.mParam[ib].BoneMatrix[1] = XMFLOAT4(mtx.r[1].x, mtx.r[1].y, mtx.r[1].z, mtx.r[1].w);//mtx.r[1];
		mCBBoneMatrix.mParam[ib].BoneMatrix[2] = XMFLOAT4(mtx.r[2].x, mtx.r[2].y, mtx.r[2].z, mtx.r[2].w);//mtx.r[2];
	}

	mCBBoneMatrix.UpdateSubresource();
}
Ejemplo n.º 3
0
void GameSystem::Render()
{
	gameTime.Update();
	//gameTime.ShowFPS();

	cam.Update();
	//UPPDATING MATRIXBUFFER
	//Check for input
	cam.Input(gameTime.DeltaTime(), mainHwnd.getHWND());

	//--------------UPDATING MATRIXES-----------------------------
	XMFLOAT3 Pos = cam.getPos();
	if (!cam.flying)
	{
	Pos.y = hMap.HMap(Pos.x, Pos.z) + 10.0f;
	cam.setPos(Pos);
	}

	XMStoreFloat4x4(&matrix.View, XMMatrixTranspose(cam.GetViewMa()));
	XMStoreFloat4x4(&matrix.Proj, XMMatrixTranspose(cam.GetProjMa()));

	D3D11_MAPPED_SUBRESOURCE MapDATA;
	Matrix* temp;
	ZeroMemory(&MapDATA, sizeof(MapDATA));

	deviceContext->Map(MatrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &MapDATA);

	temp = (Matrix*)MapDATA.pData;
	temp->World = matrix.World;
	temp->View =  matrix.View;
	temp->Proj = matrix.Proj;
	deviceContext->Unmap(MatrixBuffer, 0);
	ZeroMemory(&MapDATA, sizeof(MapDATA));

	deviceContext->Map(GeomBuff, 0, D3D11_MAP_WRITE_DISCARD, 0, &MapDATA);
	memcpy(MapDATA.pData,&Pos, sizeof(XMFLOAT3));
	deviceContext->Unmap(GeomBuff, 0);
	//--------------UPDATING MATRIXES-----------------------------
	//TEST
	//testView = XMMatrixLookAtLH(XMVectorSet(0.0, -100, 0.0, 1.0), XMVectorSet(Pos.x,Pos.y,Pos.z,1), XMVectorSet(0, 1, 0, 1));
	//TEST

	//Shadow
	DeferedRendering.setLayout(deviceContext);

	deviceContext->VSSetConstantBuffers(1, 1, &SunBuffer);
	shadow.prepRun(deviceContext);

	//hMap.renderFrustCull(deviceContext, cam.GetProjMa(), cam.GetViewMa());
	hMap.render(deviceContext); 
	obj.render(deviceContext);

	shadow.close(deviceContext);

	deviceContext->VSSetConstantBuffers(0, 1, &MatrixBuffer);

	DeferedRendering.setGBufferShaders(deviceContext);
	DeferedRendering.clearBuffer(deviceContext);

	DeferedRendering.OMSetRender(device, deviceContext, directX.getDepthView(deviceContext));

	deviceContext->VSSetConstantBuffers(0, 1, &MatrixBuffer);

	//draw obj
	if (GetAsyncKeyState('L') & 0x8000)
	{
		if (frustLock)
			frustLock = false;
		else
			frustLock = true;
	}

	if (!frustLock)
	{
		viewLock = cam.GetViewMa();
	}




	hMap.renderFrustCull(deviceContext, cam.GetProjMa(),viewLock);

	//hMap.render(deviceContext);
	obj.render(deviceContext);

	DeferedRendering.nullRender(deviceContext);
	DeferedRendering.setShaderResources(deviceContext);

	//SSAO
	XMFLOAT4X4 oTemp;

	XMStoreFloat4x4(&oTemp, XMMatrixMultiplyTranspose(cam.GetViewMa(), cam.GetProjMa()));
	
	Ssao.renderPass(device, deviceContext, oTemp);

	//Finalising and drawing
	DeferedRendering.setBackBufferShaders(deviceContext);

	//Rendertarget
	DeferedRendering.OMSetBackBuff(deviceContext);

	deviceContext->PSSetConstantBuffers(0, 1, &LightBuffer);
	deviceContext->PSSetConstantBuffers(3, 1, &SunBuffer);
	DeferedRendering.Render(device, deviceContext);

	//kolla shadowmappen
	swapChain->Present(0, 0);

	XMFLOAT3 posT = cam.getPos();

	std::cout <<"Curreny Position: X:"<< posT.x<<" Y: " <<posT.y<<"Z: "<< posT.z<< endl;

	DeferedRendering.CloseBuffers(deviceContext);
}