bool SimpleWater::initialize() { try { Ogre::Plane waterPlane(Ogre::Vector3::UNIT_Y, 0); // create a water plane/scene node Ogre::MeshManager::getSingleton().createPlane("SimpleWaterPlane", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, waterPlane, 10000, 10000, 5, 5, true, 1, 1000, 1000, Ogre::Vector3::UNIT_Z); mWaterNode = mSceneMgr.getRootSceneNode()->createChildSceneNode("water"); mWaterEntity = mSceneMgr.createEntity("water", "SimpleWaterPlane"); mWaterEntity->setMaterialName("/global/environment/water/ocean"); //Render the water very late on, so that any transparent entity which is half submerged is already rendered. mWaterEntity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8); mWaterEntity->setCastShadows(false); mWaterEntity->setQueryFlags(MousePicker::CM_NATURE); mWaterNode->attachObject(mWaterEntity); return true; } catch (const std::exception& ex) { S_LOG_FAILURE("Error when creating simple water." << ex); return false; } }
bool SimpleWater::initialize() { try { Ogre::Plane waterPlane(Ogre::Vector3::UNIT_Y, 0); Ogre::Real farClipDistance = mCamera.getFarClipDistance(); float textureSize = 10.0f; float planeSize = (farClipDistance + textureSize) * 2; // create a water plane/scene node Ogre::MeshManager::getSingleton().createPlane("SimpleWaterPlane", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, waterPlane, planeSize, planeSize, 5, 5, true, 1, planeSize / textureSize, planeSize / textureSize, Ogre::Vector3::UNIT_Z); mWaterNode = mSceneMgr.getRootSceneNode()->createChildSceneNode("water"); mWaterBobbingNode = mWaterNode->createChildSceneNode(); mWaterEntity = mSceneMgr.createEntity("water", "SimpleWaterPlane"); mWaterEntity->setMaterialName("/global/environment/water/ocean"); //Render the water very late on, so that any transparent entity which is half submerged is already rendered. mWaterEntity->setRenderQueueGroup(Ogre::RENDER_QUEUE_8); mWaterEntity->setCastShadows(false); mWaterEntity->setQueryFlags(MousePicker::CM_NATURE); mWaterBobbingNode->attachObject(mWaterEntity); mRenderTargetListener = new WaterAdjustRenderTargetListener(mWaterNode, textureSize, textureSize); mMainRenderTarget.addListener(mRenderTargetListener); Ogre::ControllerFunctionRealPtr func(OGRE_NEW Ogre::WaveformControllerFunction(Ogre::WFT_SINE, 0, 0.1)); Ogre::ControllerValueRealPtr dest(OGRE_NEW NodeAnimator(*mWaterBobbingNode, Ogre::Vector3(0, 1, 0))); Ogre::ControllerManager& cm = Ogre::ControllerManager::getSingleton(); mWaterBobbingController = cm.createController(cm.getFrameTimeSource(), dest, func); return true; } catch (const std::exception& ex) { S_LOG_FAILURE("Error when creating simple water." << ex); return false; } }
/** * @brief Initializes the water. You must call this in order for the water to show up. * @return True if the water technique could be setup, else false. */ bool Water::initialize() { try { Ogre::Plane waterPlane(Ogre::Vector3::UNIT_Y, 0); // create a water plane/scene node /* waterPlane.normal = ; waterPlane.d = 0; */ Ogre::MeshManager::getSingleton().createPlane( "WaterPlane", "environment", waterPlane, 10000, 10000, 5, 5, true, 1, 1000, 1000, Ogre::Vector3::UNIT_Z ); mWaterNode = mSceneMgr.getRootSceneNode()->createChildSceneNode("water"); mRefractionListener = new RefractionTextureListener(); mReflectionListener = new ReflectionTextureListener(); Ogre::TexturePtr texture = TextureManager::getSingleton().createManual("Refraction", "General", TEX_TYPE_2D, 512, 512, 0, PF_A8R8G8B8, TU_RENDERTARGET); RenderTexture* rttTex = texture->getBuffer()->getRenderTarget(); /* RenderTexture* rttTex = EmberOgre::getSingleton().getOgreRoot()->getRenderSystem()->createRenderTexture( "Refraction", 512, 512 );*/ { Viewport *v = rttTex->addViewport( &mCamera ); Ogre::MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/FresnelReflectionRefraction"); if (!mat.isNull()) { mat->getTechnique(0)->getPass(0)->getTextureUnitState(2)->setTextureName("Refraction"); v->setOverlaysEnabled(false); rttTex->addListener(mRefractionListener); } } texture = TextureManager::getSingleton().createManual("Reflection", "General", TEX_TYPE_2D, 512, 512, 0, PF_A8R8G8B8, TU_RENDERTARGET); rttTex = texture->getBuffer()->getRenderTarget(); { Viewport *v = rttTex->addViewport( &mCamera ); Ogre::MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/FresnelReflectionRefraction"); if (!mat.isNull()) { mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName("Reflection"); v->setOverlaysEnabled(false); rttTex->addListener(mReflectionListener); } } // Define a floor plane mesh /* reflectionPlane.normal = Vector3::UNIT_Y; reflectionPlane.d = 0;*/ /* MeshManager::getSingleton().createPlane("ReflectPlane",reflectionPlane, 1500,1500,10,10,true,1,5,5,Vector3::UNIT_Z);*/ mWaterEntity = mSceneMgr.createEntity( "plane", "WaterPlane" ); mWaterEntity->setMaterialName("Examples/FresnelReflectionRefraction"); mRefractionListener->setPlaneEntity(mWaterEntity); mReflectionListener->setPlaneEntity(mWaterEntity); mReflectionListener->setReflectionPlane(mReflectionPlane); mReflectionListener->setCamera(&mCamera); mWaterNode->attachObject(mWaterEntity); return true; } catch (const std::exception& ex) { S_LOG_FAILURE("Error when creating water." << ex); return false; } }