当前位置: 首页>>代码示例>>C++>>正文


C++ Sky::Render方法代码示例

本文整理汇总了C++中Sky::Render方法的典型用法代码示例。如果您正苦于以下问题:C++ Sky::Render方法的具体用法?C++ Sky::Render怎么用?C++ Sky::Render使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sky的用法示例。


在下文中一共展示了Sky::Render方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GenerateHDRCubeMap

	//------------------------------------------------------------------------------------
	bool AmbientCube::GenerateHDRCubeMap(const VEC3& pos, const STRING& filename, Scene* pScene)
	{
		const uint32 ENV_MAP_SIZE = 256;
		ID3D11DeviceContext* pDeviceContext = g_pRenderSys->GetDeviceContext();
		ID3D11Device* pDevice = g_pRenderSys->GetDevice();
		ID3D11Texture2D* pCubeMap = nullptr;
		ID3D11Texture2D* pDepthTex = nullptr;
		ID3D11DepthStencilView* pDSV = nullptr;
		HRESULT hr = S_OK;

		// Create cube texture
		{
			CD3D11_TEXTURE2D_DESC desc(DXGI_FORMAT_R16G16B16A16_FLOAT, ENV_MAP_SIZE, ENV_MAP_SIZE);
			desc.ArraySize = 6;
			desc.MipLevels = 1;
			desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
			desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;

			V(pDevice->CreateTexture2D(&desc, nullptr, &pCubeMap));
		}

		{
			CD3D11_TEXTURE2D_DESC desc(DXGI_FORMAT_R32_TYPELESS, ENV_MAP_SIZE, ENV_MAP_SIZE);
			desc.Usage = D3D11_USAGE_DEFAULT;
			desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;

			V(pDevice->CreateTexture2D(&desc, nullptr, &pDepthTex));

			D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
			ZeroMemory(&descDSV, sizeof(descDSV));
			descDSV.Format = DXGI_FORMAT_D32_FLOAT;
			descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
			descDSV.Flags = 0;
			descDSV.Texture2D.MipSlice = 0;

			HRESULT hr = S_OK;
			V(pDevice->CreateDepthStencilView(pDepthTex, &descDSV, &pDSV));
		}

		// Setup camera for cube map rendering
		Camera* pSceneCam = g_env.pSceneMgr->GetCamera();
		Camera camCube(pSceneCam->GetNearClip(), pSceneCam->GetFarClip(), 90, 1, false);
		camCube._BuildProjMatrix();
		camCube.SetPosition(pos);
		VEC3 vLookDirection[6] = { VEC3::UNIT_X, VEC3::NEG_UNIT_X, VEC3::UNIT_Y, VEC3::NEG_UNIT_Y, VEC3::UNIT_Z, VEC3::NEG_UNIT_Z };
		VEC3 vUp[6] = { VEC3::UNIT_Y, VEC3::UNIT_Y, VEC3::NEG_UNIT_Z, VEC3::UNIT_Z, VEC3::UNIT_Y, VEC3::UNIT_Y };
		g_env.pSceneMgr->SetCamera(&camCube);

		g_env.pSceneMgr->SetCurRenderPhase(eRenderPhase_Forward);

		// Viewport
		D3D11_VIEWPORT vp = { 0, 0, ENV_MAP_SIZE, ENV_MAP_SIZE, 0, 1 };
		pDeviceContext->RSSetViewports(1, &vp);

		// For each face
		for (int i = 0; i < 6; ++i)
		{
			ID3D11RenderTargetView* pRTV = nullptr;
			D3D11_RENDER_TARGET_VIEW_DESC descRTV;
			descRTV.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
			descRTV.Format = DXGI_FORMAT_R16G16B16A16_FLOAT;
			descRTV.Texture2DArray.MipSlice = 0;
			descRTV.Texture2DArray.ArraySize = 1;
			descRTV.Texture2DArray.FirstArraySlice = i;

			V(pDevice->CreateRenderTargetView(pCubeMap, &descRTV, &pRTV));

			pDeviceContext->OMSetRenderTargets(1, &pRTV, pDSV);

			FLOAT color[4] = { 0 };
			pDeviceContext->ClearRenderTargetView(pRTV, color);
			pDeviceContext->ClearDepthStencilView(pDSV, D3D11_CLEAR_DEPTH, 1.0f, 0);

			camCube.SetUp(vUp[i]);
			camCube.SetDirection(vLookDirection[i]);
			camCube._BuildViewMatrix();
			g_env.pRenderer->Update(0);

			pScene->RenderOpaque();

			Sky* pSky = g_env.pSceneMgr->GetSky();

			if (pSky)
			{
				pSky->Render();
			}
		}

		g_pRenderSys->SwapBuffer();
		V(D3DX11SaveTextureToFileA(pDeviceContext, pCubeMap, D3DX11_IFF_DDS, filename.c_str()));

		// Restore
		g_env.pSceneMgr->SetCurRenderPhase(eRenderPhase_None);
		g_env.pSceneMgr->SetCamera(pSceneCam);
		g_pRenderSys->SetRenderTarget(nullptr, g_pRenderSys->GetDepthBuffer(), 1, false, false);
		g_env.pRenderer->RestoreViewport();
		SAFE_RELEASE(pCubeMap);

		return true;
//.........这里部分代码省略.........
开发者ID:mavaL,项目名称:NeoEngine,代码行数:101,代码来源:AmbientCube.cpp


注:本文中的Sky::Render方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。