第二章 Cameras, Lights, and Shadows

本文介绍了使用Ogre游戏引擎创建场景的过程,并详细探讨了三种不同的阴影效果:ModulativeTextureShadows、ModulativeStencilShadows 和 AdditiveStencilShadows 的实现方式及特性。

由于第二章写出的时候还没有把wizzard搞出来,所以这个项目是手动生成,估计后面我都会用WIZZARD来生成

#include "BaseTutorial2.h"
BasicTutorial2::BasicTutorial2(void)
{

}
BasicTutorial2::~BasicTutorial2(void)
{
	
}
void BasicTutorial2::createCamera(void)
{
	mCamera=mSceneMgr->createCamera("PlayerCam");//you can use getCamera retrieves a pointer to the named camera.
	mCamera->setPosition(Ogre::Vector3(0,10,500));
	mCamera->lookAt(Ogre::Vector3(0,0,0));
	mCamera->setNearClipDistance(5);
	//though you should not use a far clip distance with Stencil Shadows
	mCameraMan=new OgreBites::SdkCameraMan(mCamera);
	//The Ogre Wiki Tutorial Framework uses OgreBites for GUI widgets and camera handling. 
	//It uses it because OgreBites - the Ogre sample framework - is included in every Ogre SDK, and because it simplifies things a lot.
	
}
void BasicTutorial2::createViewports(void)
{
	Ogre::Viewport* vp=mWindow->addViewport(mCamera);
	vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
	mCamera->setAspectRatio(Ogre::Real(vp->getActualWidth())/Ogre::Real(vp->getActualHeight()));

}
void BasicTutorial2::createScene(void)
{
	mSceneMgr->setAmbientLight(Ogre::ColourValue(0,0,0));
	mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);
	//Ogre currently supports three types of Shadows:
	//1.Modulative Texture Shadows (Ogre::SHADOWTYPE_TEXTURE_MODULATIVE) - The least computationally expensive of 
	//the three. This creates a black and white render-to-texture of shadow casters, which is then applied to the scene.
	//2.Modulative Stencil Shadows (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 
	//Additive Stencil Shadows, but it is also not as accurate.
	//3.Additive Stencil Shadows (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 pass at rendering the scene.
	//Ogre does not support soft shadows as part of the engine. If you want soft shadows you will need to write your own vertex and fragment programs. 
	Ogre::Entity* entNinja=mSceneMgr->createEntity("Ninja","ninja.mesh");
	entNinja->setCastShadows(true);
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entNinja);
	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* entGround = mSceneMgr->createEntity("GroundEntity","ground");
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entGround);
	entGround->setMaterialName("Examples/Rockwall");
	entGround->setCastShadows(false);

	//Now that we have a Ninja and ground in the scene, let's compile and run the program. 
	//We see... nothing! What's going on? In the previous tutorial we added entities and they displayed fine. 
	//The reason the Ninja doesn't show up is that the scene's ambient light has been set to total darkness. 
	//So let's add a light to see what is going on.
	Ogre::Light* pointLight = mSceneMgr->createLight("pointLight");
	pointLight->setType(Ogre::Light::LT_POINT);
	pointLight->setPosition(Ogre::Vector3(0,150,250));
	pointLight->setDiffuseColour(1.0f,0.0f,0.0f);
	pointLight->setSpecularColour(1.0f,0.0f,0.0f);
	Ogre::Light* directionalLight=mSceneMgr->createLight("directionalLight");
	directionalLight->setType(Ogre::Light::LT_DIRECTIONAL);
	directionalLight->setDiffuseColour(Ogre::ColourValue(.25f,.25f,0));
	directionalLight->setSpecularColour(Ogre::ColourValue(.25f,.25f,0));
	directionalLight->setDirection(Ogre::Vector3( 0,-1,1));
	Ogre::Light* spotLight=mSceneMgr->createLight("spotLight");
	spotLight->setType(Ogre::Light::LT_SPOTLIGHT);
	spotLight->setDiffuseColour(0,0,1.0f);
	spotLight->setSpecularColour(0,0,1.0f);
	spotLight->setDirection(-1,-1,0);
	spotLight->setPosition(Ogre::Vector3(300,300,0));
	spotLight->setSpotlightRange(Ogre::Degree(35),Ogre::Degree(35));
}

//2 end



#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
    int main(int argc, char *argv[])
#endif
    {
        // Create application object
        BasicTutorial2 app;

        try {
            app.go();
        } catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
            MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
            std::cerr << "An exception has occured: " <<
                e.getFullDescription().c_str() << std::endl;
#endif
        }

        return 0;
    }

#ifdef __cplusplus
}
#endif


三种不同的阴影效果:



于2024年4月-2025年9月期间,研究团队在贵州习水国家级自然保护区制定39条样线,涵盖灌木林、常绿阔叶林、针叶林、常绿落叶阔叶混交林、针阔混交林等不同植被类型,每条样线分春夏秋冬4个季节采集样品,用真菌采集软件记录经纬度、海拔、采集地点、时间、生境等信息,使用佳能相机(R6 mark Ⅱ)对大型真菌进行拍照,并采集标本,标本存放于贵州省生物研究所大型真菌标本馆(HGAMF)。 通过形态学初步鉴定,结合分子生物学最终鉴定,参考已]报道的中国毒蘑菇名录开展毒蘑菇的认定。 调查到保护区内有毒真菌7目25科64种,导致中毒的主要类型有急性肾衰竭型、神经精神型和胃肠炎型。最终形成贵州习水国家级自然保护区大型有毒真菌图片数据集,它由以下2个部分组成。 (1)附件1包含78张原始照片(.JPG),照片名字包括了大型有毒真菌的拉丁名和中文名,若无中文名的直接用拉丁名。 (2)附件2是一个压缩文件,包含了2张工作表,其中一张表是大型有毒真菌39条样线的信息,另一张表是大型有毒真菌的中毒类型。 照片采用佳能相机R6 mark Ⅱ拍摄,物种鉴定通过多种文献核实,并经两位以上专家鉴定确认。该数据集可为研究地及周边的普通人识别有毒大型真菌提供参考,通过及时的图片对比,能有效避免误采误食大型有毒真菌,同时为因误食大型真菌可能引发的身体损伤进行了总结,能为患者及时治疗提供参考。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值