|

楼主 |
发表于 2005-5-1 17:31:00
|
显示全部楼层
Re:OGRE教程(二):Cameras, Lights, and Shadows
6)灯光和阴影
6.1 OGRE支持的阴影类型
OGRE当前支持三种阴影:
1。调整纹理阴影(SHADOWTYPE_TEXTURE_MODULATIVE) - 是用的最常用的。这个用于建立黑白纹理阴影。
2,调整模版阴影(SHADOWTYPE_STENCIL_MODULATIVE) - 这种技术用于渲染所有在场景中不透明的物体。这种方法和附加模板阴影一样,不常用,但是很精确。
3,附加模板阴影 (SHADOWTYPE_STENCIL_ADDITIVE) - 这种技术用于渲染场景中、每个光线。这在图形卡上是非常困难的。
OGRE不将软阴影作为引擎的一部分。
6.2 在OGRE中使用阴影
在OGRE中使用阴影比较简单,SceneManager 中提供setShadowTechnique成员来设置阴影的类型。你也能用seCastShadows成员来设置投射阴影。
在这里,我们设置环境光为黑色,然后设置阴影。找到TutorialApplication::createScene成员,添加下面的代码:
mSceneMgr->setAmbientLight( ColourValue( 0, 0, 0 ) );
mSceneMgr->setShadowTechnique( SHADOWTYPE_STENCIL_ADDITIVE );
现在 SceneManager用调整纹理阴影,下面,我们建立一个物体,并使它投射阴影:
ent = mSceneMgr->createEntity( "Ninja", "ninja.mesh" );
ent->setCastShadows( true );
mSceneMgr->getRootSceneNode()->createChildSceneNode( )->attachObject( ent );
在这里,ninja.mesh被 ExampleApplication预先导入。为了让ninja.mesh能显示投射阴影,我们必须为它建立一个支持阴影的面。
(译者注:下面这段文字可能有问题,原文如下:
Again, the ninja.mesh has been preloaded for us by the ExampleApplication. We also need something for the Ninja to stand on (so that he has something to cast shadows onto). To do this we will create a simple plane for him to stand on. This is not meant to be a tutorial on using MeshManager, but we will go over the very basics since we have to use it to create a plane. First we need to define the Plane (http://www.ogre3d.org/docs/api/html/classOgre_1_1Plane.html) object itself, which is done by supplying a normal and the distance from the origin. We could (for example) use planes to make up parts of world geometry, in which case we would need to specify something other than 0 for our origin distance. For now we just want a plane to have the positive y axis as its normal (that means we want it to face up), and no distance from the origin:
)
首先,我们必须为它建立一个PLANE对象,这个对象支持法线和来自原点的距离。我们可以使面成为世界几何物体的一部分,在这种情况下,我们将表明我们到原点的距离。但是现在,我们使面的法线的轴指向正Y轴,没有到原点的距离:
Plane plane( Vector3::UNIT_Y, 0 );
现在,我们将存储这个面,以便宜我们在程序中用到它。而MeshManager 类用于保持我们导入场景中的所有网格的路径。createPlane方法用于生成Plane的定义,并按照这些定义值生成网格。代码如下:
MeshManager::getSingleton().createPlane("ground",
ResourceGroupManager: EFAULT_RESOURCE_GROUP_NAME, plane,
1500,1500,20,20,true,1,5,5,Vector3::UNIT_Z);
现在,也许你想知道MeshManager是如何使用的,但我现在并不想讲解。在这里,我们存储我们的面为1500X1500的网格,命名为“ground".下面建立这个网格并在场景中固定它:
ent = mSceneMgr->createEntity( "GroundEntity", "ground" );
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
在我们完成地面之前,我们需要做两件重要的事情。第一件事是告诉SceneManager 我们不想在不知道用什么阴影的情况下投射阴影。第二件事是地面的纹理。我们的机器人肯ninja 已经有材质脚本定义了。当我们建立我们的地面时,并没有为他建立文理。在这里我们用OGRE中的"Examples/Rockwall"中的材质脚本:
ent->setMaterialName("Examples/Rockwall");
ent->setCastShadows(false);
现在,我们在场景中有Ninja和地面,让我们编译和运行它。我们并没有看见任何物体!WHY?
那是因为我们没有添加灯光,下面让我们添加灯光。
|
|