Ogre Camera/ViewPort/Lights/Shadows基本理解

总结自:http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Basic+Tutorial+2&structure=Tutorials

void TutorialApplication::createCamera()
{
	// Ogre::Camera 继承自Frustum,但是camera可以添加到SceneNode,也可以像SceneNode一样进行变换
	// You can also attach it to a SceneNode. The Camera is not a SceneNode (it actually inherits from the Frustum class), 
	// but for movement and rotation, you can treat it like a SceneNode. 
	mCamera = mSceneMgr->createCamera("PlayerCam");
	mCamera->setPosition(Ogre::Vector3(0, 300, 500));
	mCamera->lookAt(Ogre::Vector3(0, 0, 0));
	mCamera->setNearClipDistance(5);

	mCameraMan = new OgreBites::SdkCameraMan(mCamera);
}

void TutorialApplication::createViewports()
{
	// 一个Root可以有多个场景,同样可以有多个camera,但是一个camera对应一个viewPort.
	// 要了解渲染,需要understanding how Ogre renders a scene: the Camera, the SceneManager, and the RenderWindow.
	// 要实现窗口分割,那么需要从RenderWindow做改变。具体的渲染窗口设置和窗口分割需要通过设置viewPort就可以了。
	// viewPort描述了设备坐标系到屏幕坐标系的变换映射方式。
	Ogre::Viewport* vp = mWindow->addViewport(mCamera);
	vp->setBackgroundColour(Ogre::ColourValue(0, 0, 0));

	mCamera->setAspectRatio( Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()) );
}

void TutorialApplication::creareSceneLightAndShadow()
{
	// Create your scene here :)
	Ogre::Entity* ninjaEntity = mSceneMgr->createEntity("ninja.mesh");
	// we are asking the mesh to cast shadows this time. And notice that 
	// we have created a child scene node and attached the ninjaEntity all in one call this time. 
	ninjaEntity->setCastShadows(true);
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ninjaEntity);

	// We will also create something for the ninja to be standing on
	Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0);
	Ogre::MeshManager::getSingleton().createPlane(
		"ground",
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		plane,
		1500, 1500, 20, 20,
		true,
		1, 5, 5,
		Ogre::Vector3::UNIT_Z);
	Ogre::Entity* groundEntity = mSceneMgr->createEntity("ground");
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(groundEntity);
	// this means the ground won't cast a shadow, it doesn't mean we can't cast shadows on to the ground. 
	groundEntity->setCastShadows(false);

	// we need to give our ground a material.
	// Make sure you add the texture for the material and the Examples.material script to your resource loading path. In our case, the texture is called 'rockwall.tga'. 
	// You can find the name yourself by reading the entry in the material script. 
	groundEntity->setMaterialName("Examples/Rockwall");

	mSceneMgr->setAmbientLight(Ogre::ColourValue(0, 0, 0));
	// Then whenever we create an Entity, we call setCastShadows to choose which Entities will cast shadows. 
	// Now the SceneManager will use additive stencil shadows. 
	//Ogre currently supports three types of Shadows :
	//Ogre::SHADOWTYPE_TEXTURE_MODULATIVE - This is the least computationally expensive type.A black and white render
	//	- to- texture is created using all of the shadow casters.This is then applied to the scene.
	//	Ogre::SHADOWTYPE_STENCIL_MODULATIVE - This technique renders all shadow volumes as a modulation after all 
	//	non - transparent objects have been rendered to the scene.This is not as intensive as Ogre::SHADOWTYPE_STENCIL_ADDITIVE, 
	//	but it is also less accurate.
	//	Ogre::SHADOWTYPE_STENCIL_ADDITIVE - This technique renders each light as a separate additive pass on the 
	//	scene.This is very hard on the graphics card because each additional light requires an additional rendering 
	//	pass.

	//	Try experimenting with the different shadow types.There are also other shadow - related methods in the 
	//	SceneManager(external link) class that you can play with.
	//	Ogre does not provide soft shadows as part of the engine.You can write your own vertex and
	//	fragment programs to implement soft shadows and many other things.The Ogre Manual(external link) has
	//	a full description of shadows.
	// 纹理阴影性能最高,模板阴影性能比较差
	mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_MODULATIVE/*Ogre::SHADOWTYPE_STENCIL_ADDITIVE*/);

	/*Ogre provides three types of lighting.
	Ogre::Light::LT_POINT - This Light speads out equally in all directions from a point.
	Ogre::Light::LT_SPOTLIGHT - This Light works like a flashlight.It produces a solid cylinder of light that is
	brighter at the center and fades off.Ogre::Light::LT_DIRECTIONAL - This Light simulates a huge source that is
	very far away - like daylight.Light hits the entire scene at the same angle everywhere.

	The Light(external link) class has a wide range of properties.Two of the most important are the diffuse and
	specular color.Each material script defines how much specular and diffuse lighting a material reflects.*/
	Ogre::Light* spotLight = mSceneMgr->createLight("SpotLight");
	spotLight->setDiffuseColour(0, 0, 1.0);
	spotLight->setSpecularColour(0, 0, 1.0);
	spotLight->setType(Ogre::Light::LT_SPOTLIGHT);
	spotLight->setPosition(Ogre::Vector3(200, 200, 0));
	spotLight->setDirection(-1, -1, 0);
	spotLight->setSpotlightRange(Ogre::Degree(35), Ogre::Degree(50));

	Ogre::Light* directionalLight = mSceneMgr->createLight("DirectionalLight");
	directionalLight->setType(Ogre::Light::LT_DIRECTIONAL);
	directionalLight->setDiffuseColour(Ogre::ColourValue(.4, 0, 0));
	directionalLight->setSpecularColour(Ogre::ColourValue(.4, 0, 0));
	directionalLight->setDirection(Ogre::Vector3(0, -1, 1));

	Ogre::Light* pointLight = mSceneMgr->createLight("PointLight");
	pointLight->setType(Ogre::Light::LT_POINT);
	pointLight->setDiffuseColour(.3, .3, .3);
	pointLight->setSpecularColour(.3, .3, .3);
	pointLight->setPosition(Ogre::Vector3(0, 150, 250));
}


你可能感兴趣的:(Ogre Camera/ViewPort/Lights/Shadows基本理解)