Beispiel #1
0
int main()
{
	SDeviceContextSettings settings;
	settings.MultiSamplingCount = 4;
	settings.MultiSamplingQuality = 32;

	IApplication* device = gf::createDevice(EDT_DIRECT3D11, SCREEN_WIDTH, SCREEN_HEIGHT, EWS_NONE, true, settings);
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->createSceneManager();
	IMeshManager* meshManager = driver->getMeshManager();
	IMaterialManager* materialManager = driver->getMaterialManager();
	ITextureManager* textureManager = driver->getTextureManager();

	IResourceGroupManager* resourceGroupManager = driver->getResourceGroupManager();
	resourceGroupManager->init("Resources.cfg");
//	resourceGroupManager->loadResourceGroup("General");

	ILightNode* light = smgr->addDirectionalLight(1, nullptr, XMFLOAT3(3.0f, -2.0f, 1.5f));
	light->setSpecular(XMFLOAT4(1.0f, 1.0f, 1.0f, 32.0f));
	light->setDiffuse(XMFLOAT4(0.4f, 0.4f, 0.4f, 1.0f));

	ILightNode* light2 = smgr->addDirectionalLight(2, nullptr, XMFLOAT3(-2.0f, -3.0f, -2.0f));
	light2->setSpecular(XMFLOAT4(1.0f, 1.0f, 1.0f, 32.0f));
	light2->setDiffuse(XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f));

	ICameraNode* camera = smgr->addFpsCameraNode(1, nullptr, XMFLOAT3(0, 30.0f, -4.0f), XMFLOAT3(0, 30.0f, 0.0f), XMFLOAT3(0, 1.0f, 0), true);
	camera->setViewWidth(300);
	camera->setViewHeight(200);

	char caption[200];
	
	std::string rawFileName("heightmap.raw");
	ITerrainMesh* mesh = meshManager->createTerrainMesh("terrain", rawFileName,
		3.0f, 0.4f, false, true, 1.0f);

	ITerrainNode* terrainNode = smgr->addTerrainNode(mesh);
	//terrainNode->setMaterialName("terrain/tessellation_material");
	terrainNode->setMaterialName("terrain/terrain_material");

	ITextureCube* skyTexture = textureManager->loadCubeTexture("Snow.dds");
	smgr->setSkyDome(skyTexture);

	
	IRenderTarget* pRenderTarget = textureManager->getRenderTarget("target1");

		
	ITimer* timer = device->getTimer();
	timer->reset();

	while (device->run())
	{
		const float clearColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
		driver->beginScene(true, true, clearColor);

		u32 ms = timer->tick();
		float dt = ms * 0.001f;
		updateCamera(camera, dt);

		XMFLOAT3 camPos = camera->getPosition();
		float terrainHeight = terrainNode->getHeight(camPos.x, camPos.z, true);
		camPos.y = terrainHeight + 3.0f;
		//camera->setPosition(camPos);

		smgr->update(ms);
		smgr->drawAll();

		driver->endScene();

		u32 num = smgr->getRenderedMeshNum();

		sprintf(caption, "FPS:%f num:%d", getFps(dt), num);
		device->setWindowCaption(caption);
	}

	smgr->destroy();
	device->drop();

	return 0;
}
Beispiel #2
0
void EditorScene::setupInitialScene()
{
	math::SAxisAlignedBox aabb;
	aabb.Center = XMFLOAT3(0, 0.0f, 0);
	aabb.Extents = XMFLOAT3(3000.0f, 1000.0f, 3000.0f);

	ISceneManager* smgr = mDevice->createSceneManager(aabb);
	mSceneManager = smgr;

	ITextureCube* skyTexture = mTextureManager->loadCubeTexture("skybox1.dds");
	smgr->setSkyDome(skyTexture);
	IMeshNode* skyNode = mSceneManager->getSkyNode();
	if (skyNode)
		skyNode->setMaterialName("skydome_material");

	mTimer = mDevice->getTimer();

	ISimpleMesh* cubeMesh = mMeshManager->createCubeMesh("cube1");

	mSelectedCubeNode = smgr->addMeshNode(cubeMesh, nullptr, nullptr, false);
	mSelectedCubeNode->setMaterialName("selected_cube_material");
	mSelectedCubeNode->setVisible(false);
	mSelectedCubeNode->setTag(WIRE_NODE_TAG);

	mPickingCubeNode = smgr->addMeshNode(cubeMesh, nullptr, nullptr, false);
	mPickingCubeNode->setMaterialName("picking_cube_material");
	mPickingCubeNode->setVisible(false);
	mPickingCubeNode->setTag(WIRE_NODE_TAG);

	ISimpleMesh* sphereMesh = mMeshManager->createSphereMesh("pointlight_mesh", 1.0f, 10, 10);
	
	mPointLightCollectionNode = smgr->addInstanceCollectionNode(sphereMesh, 
		nullptr, 4000, sizeof(XMFLOAT4));
	mPointLightCollectionNode->setMaterialName("multi_wire_material");
	mPointLightCollectionNode->setTag(WIRE_NODE_TAG);
	mPointLightCollectionNode->setVisible(false);

	mSceneManager->update(0);
	

	IVideoDriver* driver = IVideoDriver::getInstance();
	mVideoDriver->setDeferredShading(true);
	driver->setDeferredShadingAlgorithm(EDSA_CS_TILE_BASED_DEFERRED_SHADING);

	IShaderManager* shaderManager = IShaderManager::getInstance();
	mTileBasedDSShader = shaderManager->load(EST_COMPUTE_SHADER, "defer_shader_cs.hlsl", "cs_main");
	smgr->setTileBasedDeferredShadingCS(mTileBasedDSShader);

	if (!CFileParser::ReadScene("main.scene"))
	{
		setupTerrain();

		ILightNode* light = smgr->addDirectionalLight(1, nullptr, XMFLOAT3(3.0f, -2.0f, 1.5f));
		light->setSpecular(XMFLOAT4(1.0f, 1.0f, 1.0f, 32.0f));
		light->setDiffuse(XMFLOAT4(0.8f, 0.8f, 0.8f, 1.0f));
		light->enableShadow(true);
		mDirectionalLightNode = light;

		smgr->setAmbient(XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f));

		mCamera = smgr->addFpsCameraNode(1, nullptr, XMFLOAT3(0, 30.0f, -4.0f),
			XMFLOAT3(0, 30.0f, 0.0f), XMFLOAT3(0, 1.0f, 0), true);
		mCamera->setShadowRange(300.0f);

		mVideoDriver->setDeferredShading(true);
		mDeferredShading = true;
	}

	UpdateGlobalLighting();
	
	smgr->update();
}
Beispiel #3
0
int _tmain(int argc, _TCHAR* argv[])
{
	SDeviceContextSettings settings;
	settings.MultiSamplingCount = 4;
	settings.MultiSamplingQuality = 32;

	IDevice* device = gf::createDevice(EDT_DIRECT3D11, SCREEN_WIDTH, SCREEN_HEIGHT, EWS_NONE, true, settings);
	IVideoDriver* driver = device->getVideoDriver();

	math::SAxisAlignedBox aabb;
	aabb.Center = XMFLOAT3(0, 0.0f, 0);
	aabb.Extents = XMFLOAT3(3000.0f, 1000.0f, 3000.0f);

	ISceneManager* smgr = device->createSceneManager(aabb);
	IMeshManager* meshManager = driver->getMeshManager();
	IMaterialManager* materialManager = driver->getMaterialManager();
	ITextureManager* textureManager = driver->getTextureManager();

	IResourceGroupManager* resourceGroupManager = driver->getResourceGroupManager();
	resourceGroupManager->init("Resources.cfg");

	ILightNode* light = smgr->addDirectionalLight(1, nullptr, XMFLOAT3(3.0f, -2.0f, 1.5f));
	light->setSpecular(XMFLOAT4(1.0f, 1.0f, 1.0f, 32.0f));
	light->setDiffuse(XMFLOAT4(0.4f, 0.4f, 0.4f, 1.0f));
	light->enableShadow(true);

	ICameraNode* camera = smgr->addFpsCameraNode(1, nullptr, XMFLOAT3(0, 30.0f, -4.0f), 
		XMFLOAT3(0, 30.0f, 0.0f), XMFLOAT3(0, 1.0f, 0), true);
	camera->setShadowRange(200.0f);

	buildGrassLand(smgr);

	ISimpleMesh* groundMesh = meshManager->createPlaneMesh("ground", GROUND_SIZE, GROUND_SIZE, 50, 50, 10.0f, 10.0f);
	IMeshNode* groundNode = smgr->addMeshNode(groundMesh, nullptr, nullptr, false);
	groundNode->setMaterialName("ground_material");

	ITextureCube* skyTexture = textureManager->loadCubeTexture("skybox1.dds");
	smgr->setSkyDome(skyTexture);

	ITimer* timer = device->getTimer();
	timer->reset();
	char caption[200];
	while (device->run())
	{
		const float clearColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
		driver->beginScene(true, true, clearColor);

		f32 dt = timer->tick();
		updateCamera(camera, dt);
		g_grassLand->update(dt);

		smgr->update(dt);
		smgr->drawAll();

		driver->endScene();

		u32 num = smgr->getRenderedMeshNum();

		sprintf(caption, "FPS:%f num:%d", getFps(dt), num);
		device->setWindowCaption(caption);
	}

	smgr->destroy();
	device->drop();

	return 0;
}