コード例 #1
0
ファイル: OcTree.cpp プロジェクト: colinchen1984/fury3d
	void OcTree::GetRenderQuery(const Collidable &collider, const std::shared_ptr<RenderQuery> &renderQuery) const
	{
		renderQuery->Clear();

		WalkScene(collider, [&](const SceneNode::Ptr &sceneNode)
		{
			if (sceneNode->GetComponent<Light>() != nullptr)
				renderQuery->AddLight(sceneNode);
			
			if (auto render = sceneNode->GetComponent<MeshRender>())
			{
				if (render->GetRenderable())
					renderQuery->AddRenderable(sceneNode);
			}
		});
	}
コード例 #2
0
ファイル: Main.cpp プロジェクト: rezanour/rendering
HRESULT GfxInitialize()
{
    UINT dxgiFlags = 0;
#ifdef _DEBUG
    dxgiFlags |= DXGI_CREATE_FACTORY_DEBUG;
#endif
    HRESULT hr = CreateDXGIFactory2(dxgiFlags, IID_PPV_ARGS(&Factory));
    CHECKHR(hr);

    bool createDebug = false;
#ifdef _DEBUG
    createDebug = true;
#endif

    Graphics = std::make_shared<GraphicsDevice>();
    hr = Graphics->Initialize(Factory, nullptr, createDebug);
    CHECKHR(hr);

    Presenter = std::make_unique<DxgiPresenter>(Graphics, AppWindow);
    hr = Presenter->Initialize();
    CHECKHR(hr);

    //Renderer = std::make_unique<LPFRenderer>(Graphics);
    Renderer = std::make_unique<ForwardPlusRenderer>(Graphics);
    hr = Renderer->Initialize();
    CHECKHR(hr);

    TheScene = std::make_shared<Scene>();

    std::vector<std::shared_ptr<Visual>> visuals;
    Assets = std::make_shared<AssetLoader>(Graphics, L"..\\ProcessedContent");
    hr = Assets->LoadModel(L"crytek-sponza\\sponza.model", &visuals);
    CHECKHR(hr);

    for (auto& visual : visuals)
    {
        TheScene->AddVisual(visual);
    }

#ifdef USE_HEADLIGHT
    Headlight = std::make_shared<DirectionalLight>();
    Headlight->SetColor(XMFLOAT3(1.f, 1.f, 1.f));
    Headlight->SetOrientation(QuaternionFromViewDirection(XMVector3Normalize(XMVectorSet(1, -1, 1, 0)), XMVectorSet(0, 1, 0, 0)));
    TheScene->AddLight(Headlight);
#else
    // Add some lights
    std::shared_ptr<Light> light = std::make_shared<DirectionalLight>();
    light->SetColor(XMFLOAT3(0.6f, 0.6f, 0.4f));
    light->SetOrientation(QuaternionFromViewDirection(XMVector3Normalize(XMVectorSet(-1, -1, -1, 0)), XMVectorSet(0, 1, 0, 0)));
    //TheScene->AddLight(light);

    light = std::make_shared<DirectionalLight>();
    light->SetColor(XMFLOAT3(0.4f, 0.4f, 0.6f));
    light->SetOrientation(QuaternionFromViewDirection(XMVector3Normalize(XMVectorSet(1, -1, 1, 0)), XMVectorSet(0, 1, 0, 0)));
    //TheScene->AddLight(light);

    srand(0);
    for (float y = 50; y < 500; y +=100)
    {
        for (float x = -1000; x < 1000; x += 100)
        {
            for (float z = -500; z < 500; z += 100)
            {
                float r = (rand() % 256) / 256.f;
                float g = (rand() % 256) / 256.f;
                float b = (rand() % 256) / 256.f;
                light = std::make_shared<PointLight>();
                light->SetColor(XMFLOAT3(r, g, b));
                light->SetPosition(XMFLOAT3(x, y, z));
                ((PointLight*)light.get())->SetRadius(100.f);
                TheScene->AddLight(light);
            }
        }
    }

#endif

    Renderer->SetScene(TheScene);

    BackBufferRT.Texture = Presenter->GetBackBuffer();
    BackBufferRT.Viewport.Width = static_cast<float>(BackBufferRT.Texture->GetDesc().Width);
    BackBufferRT.Viewport.Height = static_cast<float>(BackBufferRT.Texture->GetDesc().Height);
    BackBufferRT.Viewport.MaxDepth = 1.f;

    View.NearClipDistance = 1.f;
    View.FarClipDistance = 5000.f;

    XMStoreFloat4x4(&View.ViewToProjection,
        XMMatrixPerspectiveFovLH(
            XMConvertToRadians(60.f),
            ClientWidth / (float)ClientHeight,
            View.NearClipDistance,
            View.FarClipDistance));

    return hr;
}