2010年6月17日木曜日

OGRE - 影の描画

OGRE で影を描画する方法についての自分メモ。

1.モデリングソフトでモデルをエクスポートする際に、「Mesh」の「Build edges list (for Shadows)」にチェックを入れてエクスポートする。(影を落とす地面側のモデルは別に必要ない)

2.シーン初期化に次のようなものを追加する(パラメータはそれぞれ必要に応じて変更)。

this->sceneMain->setShadowTechnique( Ogre::SHADOWTYPE_STENCIL_MODULATIVE );
this->sceneMain->setShadowColour( Ogre::ColourValue(0.4f, 0.4f, 0.4f) );
this->sceneMain->setShadowTextureCasterMaterial( Ogre::StringUtil::BLANK );
this->sceneMain->setShadowTextureReceiverMaterial( Ogre::StringUtil::BLANK );
this->sceneMain->setShadowTextureSettings( 512, 2, Ogre::PF_X8R8G8B8 );
this->sceneMain->setShadowTextureSelfShadow( false );
this->sceneMain->setAmbientLight( Ogre::ColourValue(0.6f, 0.6f, 0.6f) );

3.ライトを作成し、影を有効にする(ここでは平行光源)。

Ogre::Light* light = this->sceneMain->createLight( "SunLight" );
light->setType( Ogre::Light::LT_DIRECTIONAL );
Ogre::Vector3 dir( -0.5f, -1.0f, -0.5f );
dir.normalise();
light->setDirection( dir );
light->setDiffuseColour( 0.95f, 0.95f, 0.95f );
light->setSpecularColour( 0.95f, 0.95f, 0.95f );
light->setCastShadows( true );

4.後は普通に描画すれば自動的に影を描画してくれる。影を落としたくない Entity は、Entity のメンバsetCastShadows() で false を渡せば描画されなくなるはず。(デフォルトではすべて true になっている)

0 件のコメント:

コメントを投稿