/* ----------------------------------------------------------------------------- This source file is part of OGRE (Object-oriented Graphics Rendering Engine) For the latest info, see http://www.ogre3d.org/ Copyright (c) 2000-2005 The OGRE Team Also see acknowledgements in Readme.html You may use this sample code for anything you like, it is not covered by the LGPL like the rest of the engine. ----------------------------------------------------------------------------- */ /** \file Lighting.h \brief Shows lighting support in OGRE. Also demonstrates the use of billboards and controllers for automatic time-relative behaviour. */ #include "ExampleApplication.h" #include "OgreIlluminationManager.h" #include "SpriteParticleRenderer.h" float causize = 10; float cauintens = 1; // Listener class for frame updates class RaytraceDemoListener : public ExampleFrameListener { protected: SceneNode* goldSphereNode; SceneNode* silverSphereNode; SceneNode* copperSphereNode; SceneNode* aluSphereNode; SceneNode* centerSphereNode; SceneNode* lightNode; Light* light; unsigned long framecount; public: RaytraceDemoListener(RenderWindow* window, Camera* maincam,SceneNode* lightNode, SceneNode* goldSphereNode, SceneNode* silverSphereNode, SceneNode* copperSphereNode, SceneNode* aluSphereNode, SceneNode* centerSphereNode, Light* light) :ExampleFrameListener(window, maincam) { framecount = 0; this->goldSphereNode = goldSphereNode; this->silverSphereNode = silverSphereNode; this->copperSphereNode = copperSphereNode; this->aluSphereNode = aluSphereNode; this->centerSphereNode = centerSphereNode; this->lightNode = lightNode; this->light = light; } bool processUnbufferedKeyInput(const FrameEvent& evt) { /* MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/Caustic/CauCube_PointSpritecenterHead_SE_0_clone"); GpuProgramParameters* Vparams = mat->getTechnique(0)->getPass(0)->getVertexProgramParameters().getPointer(); GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer(); if (mInputDevice->isKeyDown(KC_SUBTRACT)) { cauintens -= 0.5; cauintens = std::max(cauintens, 1.0f); float intensity = cauintens; float causticColor[] = {1.0, 1.0, 1.0, intensity}; Fparams->setNamedConstant("CausticColor", causticColor, 4); } if (mInputDevice->isKeyDown(KC_ADD)) { cauintens += 0.5; cauintens = std::min(cauintens, 100.0f); float intensity = pow( cauintens / 100.0f, 2 ); float causticColor[] = {1.0, 1.0, 1.0, intensity}; Fparams->setNamedConstant("CausticColor", causticColor, 4); } if (mInputDevice->isKeyDown(KC_MULTIPLY)) { causize = std::max(causize - 0.1, 0.0); Vparams->setNamedConstant("CauSpriteSize", causize); } if (mInputDevice->isKeyDown(KC_DIVIDE)) { causize = causize + 0.1; Vparams->setNamedConstant("CauSpriteSize", causize); } */ return ExampleFrameListener::processUnbufferedKeyInput(evt); } bool frameStarted(const FrameEvent& evt) { static bool first = true; if(first) { /* MaterialPtr mat = MaterialManager::getSingleton().getByName("GTP/Caustic/CauCube_PointSpritecenterHead_SE_0_clone"); GpuProgramParameters* Vparams = mat->getTechnique(0)->getPass(0)->getVertexProgramParameters().getPointer(); GpuProgramParameters* Fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters().getPointer(); float intensity = cauintens; float causticColor[] = {1.0, 1.0, 1.0, intensity}; Fparams->setNamedConstant("CausticColor", causticColor, 4); Vparams->setNamedConstant("CauSpriteSize", causize); first = false;*/ } lightNode->setPosition( 100.0 * Vector3(cos(-(float)framecount/500.0),2.0,sin(-(float)framecount/500.0))); light->setDirection(Vector3(0,100,0)-lightNode->getPosition()); goldSphereNode->setPosition( 100.0 * Vector3( cos((float)framecount/700.0), 1.0, sin((float)framecount/700.0))); silverSphereNode->setPosition( 100.0 * Vector3( cos((float)framecount/700.0 + Math::PI / 2.0), 1.0, sin((float)framecount/700.0 + Math::PI / 2.0))); copperSphereNode->setPosition( 100.0 * Vector3( cos((float)framecount/700.0 + Math::PI ), 1.0, sin((float)framecount/700.0 + Math::PI))); aluSphereNode->setPosition( 100.0 * Vector3( cos((float)framecount/700.0 + 3 * Math::PI / 2.0), 1.0, sin((float)framecount/700.0+ 3 * Math::PI / 2.0))); bool result = ExampleFrameListener::frameStarted(evt); framecount++; return result; } }; /** Application class */ class RaytraceDemoApplication : public ExampleApplication { public: protected: SceneNode* kupolaNode; SceneNode* mainLightNode; SceneNode* goldSphereNode; SceneNode* silverSphereNode; SceneNode* copperSphereNode; SceneNode* aluSphereNode; SceneNode* centerSphereNode; Light* mainLight; void loadResources(void) { // Initialise, parse scripts etc ResourceGroupManager::getSingleton().initialiseResourceGroup("Bootstrap"); ResourceGroupManager::getSingleton().initialiseResourceGroup("General"); ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Basic"); ResourceGroupManager::getSingleton().initialiseResourceGroup("PostProc"); ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_EnvMap"); ResourceGroupManager::getSingleton().initialiseResourceGroup("GTP_Caustic"); } void createPostproc() { CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0), "GTP/PostProc/Glow"); CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0), "GTP/PostProc/Glow", true); CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0), "GTP/PostProc/ToneMap"); CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0), "GTP/PostProc/ToneMap", true); } void chooseSceneManager() { mSceneMgr = mRoot->createSceneManager("OctreeSceneManager"); //mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager"); } void createScene(void) { //createPostproc(); std::string occlusion_cfg("OcclusionCulling.cfg"); //mSceneMgr->setWorldGeometry(occlusion_cfg); OgreIlluminationManager::getSingleton().setMainCamera(mCamera); OgreIlluminationManager::getSingleton().setMainViewport(mWindow->getViewport(0)); OgreIlluminationManager::getSingleton().setMaxJoinRadius(1000); Root::getSingleton()._setCurrentSceneManager(mSceneMgr); mCamera->setPosition(0,100,240); mCamera->setFOVy(Radian(Degree(80))); //mCamera->setFarClipDistance(1000); // Set ambient light mSceneMgr->setAmbientLight(ColourValue(1, 1, 1)); // Skybox mSceneMgr->setSkyBox(true, "Examples/MorningSkyBox"); SceneNode* rootNode = mSceneMgr->getRootSceneNode(); //init objects Entity* kupola = mSceneMgr->createEntity("kupola", "kupola.mesh"); Entity* centerHead = mSceneMgr->createEntity("centerHead", "head.mesh"); Entity* goldHead = mSceneMgr->createEntity("goldHead", "head.mesh"); Entity* silverHead = mSceneMgr->createEntity("silverHead", "head.mesh"); Entity* copperHead = mSceneMgr->createEntity("copperHead", "head.mesh"); Entity* aluHead = mSceneMgr->createEntity("aluHead", "head.mesh"); kupola->setCastShadows(false); MeshPtr kmesh = kupola->getMesh(); kmesh->buildTangentVectors(0,1); //init nodes centerSphereNode = rootNode->createChildSceneNode("centerSphere"); centerSphereNode->setPosition(0, 100,0); centerSphereNode->attachObject(centerHead); centerSphereNode->setScale(3.2, 3.2, 3.2); goldSphereNode = rootNode->createChildSceneNode( "goldSphere" ); goldSphereNode->scale(2.4, 2.4, 2.4); goldSphereNode->attachObject(goldHead); silverSphereNode = rootNode->createChildSceneNode( "silverSphere" ); silverSphereNode->scale(2.4, 2.4, 2.4); silverSphereNode->attachObject(silverHead); aluSphereNode = rootNode->createChildSceneNode( "aluSphere" ); aluSphereNode->scale(2.4, 2.4, 2.4); aluSphereNode->attachObject(aluHead); copperSphereNode = rootNode->createChildSceneNode( "copperSphere" ); copperSphereNode->scale(2.4, 2.4, 2.4); copperSphereNode->attachObject(copperHead); goldSphereNode->_updateBounds(); silverSphereNode->_updateBounds(); aluSphereNode->_updateBounds(); copperSphereNode->_updateBounds(); kupolaNode = rootNode->createChildSceneNode( "kupola" ); kupolaNode->rotate(Vector3(0,1,0),Radian(Degree(90))); kupolaNode->attachObject( kupola ); kupolaNode->scale(25,21,25); //kupolaNode->scale(2,2,2); //kupolaNode->setPosition(0,100,0); kupolaNode->_updateBounds(); centerSphereNode->_updateBounds(); //Init lights mainLight = mSceneMgr->createLight("MainLight"); mainLight->setType(Light::LT_POINT); mainLight->setDiffuseColour(ColourValue::White); mainLight->setSpecularColour(ColourValue::White); //mainLight->setSpotlightRange(Radian(Degree(175)),Radian(Degree(180))); mainLightNode = rootNode->createChildSceneNode(); mainLightNode->setPosition(0,0,0); mainLight->setPosition(mainLightNode->getWorldPosition()); mainLightNode->attachObject(mainLight); BillboardSet* bbs = mSceneMgr->createBillboardSet("bb", 1); bbs->setDefaultDimensions(10,10); bbs->createBillboard(Vector3::ZERO, ColourValue::White); bbs->setMaterialName("Flare"); mainLightNode->attachObject(bbs); aluHead->setMaterialName("GTP/EnvMap/Alu"); copperHead->setMaterialName("GTP/EnvMap/Copper"); goldHead->setMaterialName("GTP/EnvMap/Gold"); silverHead->setMaterialName("GTP/EnvMap/Silver"); centerHead->setMaterialName("GTP/Caustic/Glass_PointSprite"); OgreIlluminationManager::getSingleton().initTechniques(); } void createFrameListener(void) { // This is where we instantiate our own frame listener mFrameListener= new RaytraceDemoListener(mWindow, mCamera, mainLightNode, goldSphereNode, silverSphereNode, copperSphereNode, aluSphereNode, centerSphereNode, mainLight); mFrameListener->setPriority(1); OgreIlluminationManager::getSingleton().setPriority(2); mRoot->addFrameListener(mFrameListener); mRoot->addFrameListener(&OgreIlluminationManager::getSingleton()); } };