Beispiel #1
0
bool Real::modifyWave(int id,Ogre::Vector2 dir, float A, float T, float p)
{
    if( (id < 0) || (id >= (int)mWaves.size()) ){
        HydraxLOG("Error (Real::eraseWave):\tCan't delete the wave.");
        HydraxLOG("\tIdentifier exceed the waves vector dimensions.");
        return false;
    }
    mWaves.at(id) = Wave(dir,A,T,p);
    return true;
}
	bool Noise::loadCfg(Ogre::ConfigFile &CfgFile)
	{
		if (CfgFile.getSetting("Noise") == mName)
		{
		    HydraxLOG(mName + " options entry found.");
			return true;
		}

        HydraxLOG("Error (Noise::loadCfg):\t" + mName + " options entry can not be found.");
		return false;
	}
Beispiel #3
0
	bool TextureManager::_updateNormalMap(Image &Image)
	{
		if (!mCreated)
		{
			HydraxLOG("Error in TextureManager::_updateNormalMap, create() does not called.");

			return false;
		}

		if (Image.getType() != Image::TYPE_RGB)
		{
			HydraxLOG("Error in TextureManager::_updateNormalMap, Image type isn't correct.");

			return false;
		}

		Ogre::TexturePtr &Texture = getTexture(TEX_NORMAL_ID);

		Size ImageSize = Image.getSize();
		
		if (Texture->getWidth()  != ImageSize.Width ||
			Texture->getHeight() != ImageSize.Height)
		{
			HydraxLOG("Error in TextureManager::update, Update size doesn't correspond to " + getTextureName(TEX_NORMAL_ID) + " texture size");

			return false;
		}

		Ogre::HardwarePixelBufferSharedPtr pixelBuffer = Texture->getBuffer();

        pixelBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL);
        const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock();

        Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data);

        int x, y;

        for (x = 0; x < ImageSize.Width; x++)
        {
            for (y = 0; y < ImageSize.Height; y++)
            {
                *pDest++ =   Image.getValue(x,y,2); // B
                *pDest++ =   Image.getValue(x,y,1); // G
                *pDest++ =   Image.getValue(x,y,0); // R
				*pDest++ =   255;                   // A
            }
        }

        pixelBuffer->unlock();

		return true;
	}
Beispiel #4
0
	void SimpleGrid::create()
	{
		HydraxLOG("Creating " + getName() + " module.");

		Module::create();

		int v, u;
		if (getNormalMode() == MaterialManager::NM_VERTEX)
		{
			mVertices = new Mesh::POS_NORM_VERTEX[mOptions.Complexity*mOptions.Complexity];	
			Mesh::POS_NORM_VERTEX* Vertices = static_cast<Mesh::POS_NORM_VERTEX*>(mVertices);

			for(v=0; v<mOptions.Complexity; v++)
			{
				for(u=0; u<mOptions.Complexity; u++)
				{
					Vertices[v*mOptions.Complexity + u].x  = (static_cast<float>(v)/(mOptions.Complexity-1)) * mOptions.MeshSize.Width;
					Vertices[v*mOptions.Complexity + u].z  = (static_cast<float>(u)/(mOptions.Complexity-1)) * mOptions.MeshSize.Height;

					Vertices[v*mOptions.Complexity + u].nx = 0;
					Vertices[v*mOptions.Complexity + u].ny = -1;
					Vertices[v*mOptions.Complexity + u].nz = 0;
				}
			}

			if (mOptions.ChoppyWaves)
			{
				mVerticesChoppyBuffer = new Mesh::POS_NORM_VERTEX[mOptions.Complexity*mOptions.Complexity];

				for(int i = 0; i < mOptions.Complexity*mOptions.Complexity; i++)
				{
					mVerticesChoppyBuffer[i] = Vertices[i];
				}
			}
		}
		else if (getNormalMode() == MaterialManager::NM_RTT)
		{
			mVertices = new Mesh::POS_VERTEX[mOptions.Complexity*mOptions.Complexity];	
			Mesh::POS_VERTEX* Vertices = static_cast<Mesh::POS_VERTEX*>(mVertices);

			for(v=0; v<mOptions.Complexity; v++)
			{
				for(u=0; u<mOptions.Complexity; u++)
				{
					Vertices[v*mOptions.Complexity + u].x  = (static_cast<float>(v)/(mOptions.Complexity-1)) * mOptions.MeshSize.Width;
					Vertices[v*mOptions.Complexity + u].z  = (static_cast<float>(u)/(mOptions.Complexity-1)) * mOptions.MeshSize.Height;
				}
			}
		}

		HydraxLOG(getName() + " created.");
	}
	Image::Pixel Image::getPixelLI(const float &x, const float &y) const
	{
#if HYDRAX_IMAGE_CHECK_PIXELS == 1
		if (x < 0 || x > mSize.Width ||
			y < 0 || y > mSize.Height)
		{
			HydraxLOG("Error in Image::getPixel, x = " + Ogre::StringConverter::toString(x)
				                             + " y = " + Ogre::StringConverter::toString(y));

			return Pixel(0);
		}
#endif

		float v[4];

		for(int k = 0; k < 4; k++)
		{
			if (mChannels >= k)
			{
			    v[k] = getValueLI(x, y, k);
			}
			else
			{
				v[k] = 0;
			}
		}

		return Pixel(v[0], v[1], v[2], v[3]);
	}
Beispiel #6
0
    void Module::setNoise(Noise::Noise* Noise, GPUNormalMapManager* g, const bool& DeleteOldNoise)
    {
      if(DeleteOldNoise)
      {
        delete mNoise;
      }

      mNoise = Noise;

      if(mCreated)
      {
        if(!mNoise->isCreated())
        {
          mNoise->create();
        }

        if(getNormalMode() == MaterialManager::NM_RTT)
        {
          if(!mNoise->createGPUNormalMapResources(g))
          {
            HydraxLOG(mNoise->getName() + " doesn't support GPU Normal map generation");
          }
        }
        else
        {
          mNoise->removeGPUNormalMapResources(g);
        }
      }
      else
      {
        mNoise->removeGPUNormalMapResources(g);
      }
    }
Beispiel #7
0
Real::~Real()
{
    remove();
    delete mPerlinNoise;

    HydraxLOG(getName() + " destroyed.");
}
	void GodRaysManager::addDepthTechnique(Ogre::Technique *Technique, const bool& AutoUpdate)
	{
		if (!Ogre::MaterialManager::getSingleton().resourceExists(_def_GodRaysDepth_Material_Name))
		{
			HydraxLOG("GodRaysManager::addDepthTechnique(...) Objects intersection must be enabled and Hydrax::create() already called, skipping...");
		
			return;
		}

		Technique->removeAllPasses();
		Technique->createPass();
		Technique->setSchemeName("HydraxGodRaysDepth");

		Ogre::Pass *DM_Technique_Pass0 = Technique->getPass(0);

		DM_Technique_Pass0->setVertexProgram(_def_GodRaysDepth_Shader_VP_Name);
		DM_Technique_Pass0->setFragmentProgram(_def_GodRaysDepth_Shader_FP_Name);

		Ogre::GpuProgramParametersSharedPtr VP_Parameters = DM_Technique_Pass0->getVertexProgramParameters();
		Ogre::GpuProgramParametersSharedPtr FP_Parameters = DM_Technique_Pass0->getFragmentProgramParameters();

		VP_Parameters->setNamedAutoConstant("uWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
		VP_Parameters->setNamedAutoConstant("uWorld", Ogre::GpuProgramParameters::ACT_WORLD_MATRIX);
		
		FP_Parameters->setNamedConstant("uLightPosition", mProjectorSN->getPosition());
		FP_Parameters->setNamedConstant("uLightFarClipDistance", mProjectorCamera->getFarClipDistance());

		if (AutoUpdate)
		{
		    mDepthTechniques.push_back(Technique);
		}
	}
Beispiel #9
0
bool Real::eraseWave(int id)
{
    if( (id < 0) || (id >= (int)mWaves.size()) ){
        HydraxLOG("Error (Real::eraseWave):\tCan't delete the wave.");
        HydraxLOG("\tIdentifier exceed the waves vector dimensions.");
        return false;
    }
    size_t Size = mWaves.size();
    mWaves.erase(mWaves.begin() + id);
    if(mWaves.size() == Size){
        HydraxLOG("Error (Real::eraseWave):\tCan't delete the wave.");
        HydraxLOG("\tThe size before deletion matchs with the size after the operation.");
        return false;
    }
    return true;
}
Beispiel #10
0
	bool TextureManager::_createTexture(Ogre::TexturePtr &Texture, const Ogre::String &Name, const Size &Size)
	{
		try
		{
			Ogre::TextureManager::getSingleton().remove(Name);

			Texture = Ogre::TextureManager::getSingleton().
				createManual(Name,
				HYDRAX_RESOURCE_GROUP, 
				Ogre::TEX_TYPE_2D,
				Size.Width, Size.Height,
				0,
				Ogre::PF_BYTE_BGRA,
				Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);

			Texture->load();
		}
		catch(Ogre::Exception &e)
		{
			HydraxLOG(e.getFullDescription());

			return false;
		}

		return true;
	}
Beispiel #11
0
	void Hydrax::DeviceRestoredListener::eventOccurred(const Ogre::String& eventName, const Ogre::NameValuePairList *parameters)
	{
		if (eventName == "DeviceRestored")
		{
			// Restore mesh
			HydraxLOG("Restoring water mesh...");
			if (mHydrax->mMesh->isCreated())
			{
				Ogre::String MaterialNameTmp = mHydrax->mMesh->getMaterialName();
				Mesh::Options MeshOptionsTmp = mHydrax->mMesh->getOptions();

				HydraxLOG("Updating water mesh...");

				HydraxLOG("Deleting water mesh...");
				delete mHydrax->mMesh;
				HydraxLOG("Water mesh deleted.");

				HydraxLOG("Creating water mesh...");
				mHydrax->mMesh = new Mesh(mHydrax);
				mHydrax->mMesh->setOptions(MeshOptionsTmp);
				mHydrax->mMesh->setMaterialName(MaterialNameTmp);
				mHydrax->mMesh->create();
				mHydrax->setPosition(mHydrax->mPosition);
				mHydrax->mModule->update(0); // ???
				HydraxLOG("Water mesh created.");
			}
			HydraxLOG("Water mesh restored.");
		}
	}
Beispiel #12
0
bool Real::loadCfg(Ogre::ConfigFile &CfgFile)
{
    if (!Noise::loadCfg(CfgFile))
    {
        return false;
    }

    HydraxLOG("\tReading options...");
    mPerlinNoise->setOptions(
        Perlin::Options(CfgFileManager::_getIntValue(CfgFile,"Perlin_Octaves"),
                CfgFileManager::_getFloatValue(CfgFile,"Perlin_Scale"),
                CfgFileManager::_getFloatValue(CfgFile,"Perlin_Falloff"),
                CfgFileManager::_getFloatValue(CfgFile,"Perlin_Animspeed"),
                CfgFileManager::_getFloatValue(CfgFile,"Perlin_Timemulti"),
                CfgFileManager::_getFloatValue(CfgFile,"Perlin_GPU_Strength"),
                CfgFileManager::_getVector3Value(CfgFile,"Perlin_GPU_LODParameters")));
    HydraxLOG("\tOptions readed.");

    return true;
}
Beispiel #13
0
  void Hydrax::rotate(const Ogre::Quaternion &q)
  {
    if(!mCreated)
    {
      HydraxLOG("Hydrax::rotate(...) must be called after Hydrax::create(), skipping...");
      return;
    }

    mMesh->getSceneNode()->rotate(q);
    mRttManager->getPlanesSceneNode()->rotate(q);
    // For world-space -> object-space conversion
    setSunPosition(mSunPosition);
  }
	void Image::setPixel(const int &x, const int &y, const Pixel &p)
	{
#if HYDRAX_IMAGE_CHECK_PIXELS == 1
		if (x < 0 || x > mSize.Width ||
			y < 0 || y > mSize.Height)
		{
			HydraxLOG("Error in Image::setPixel, x = " + Ogre::StringConverter::toString(x)
				                             + " y = " + Ogre::StringConverter::toString(y));

			return;
		}
#endif

		switch(mChannels)
		{
		    case 1:
			{
				setValue(x, y, 0, p.red);
			}
			break;

			case 2:
			{
				setValue(x, y, 0, p.red);
				setValue(x, y, 1, p.green);
			}
			break;

			case 3:
			{
				setValue(x, y, 0, p.red);
				setValue(x, y, 1, p.green);
				setValue(x, y, 2, p.blue);
			}
			break;

			case 4:
			{
				setValue(x, y, 0, p.red);
				setValue(x, y, 1, p.green);
				setValue(x, y, 2, p.blue);
				setValue(x, y, 3, p.alpha);
			}
			break;
		}
	}
	const float& Image::getValue(const int &x, const int &y, const int &c) const
	{
#if HYDRAX_IMAGE_CHECK_PIXELS == 1
		if (c < 0 || c > mChannels ||
			x < 0 || x > mSize.Width ||
			y < 0 || y > mSize.Height)
		{
			HydraxLOG("Error in Image::getValue, x = " + Ogre::StringConverter::toString(x)
				                             + " y = " + Ogre::StringConverter::toString(y)
											 + " Channel = " + Ogre::StringConverter::toString(c));

			return 0;
		}
#endif

		return mData[(y*mSize.Width+x)*mChannels+c];
	}
Beispiel #16
0
	Hydrax::Hydrax(Ogre::SceneManager *sm, Ogre::Camera *c, Ogre::Viewport *v)
            : mSceneManager(sm)
            , mCamera(c)
			, mViewport(v)
            , mCreated(false)
			, mVisible(true)
			, mPolygonMode(Ogre::PM_SOLID)
			, mShaderMode(MaterialManager::SM_HLSL)
            , mPosition(Ogre::Vector3(0,0,0))
            , mPlanesError(0)
            , mFullReflectionDistance(99999997952.0)
            , mGlobalTransparency(0.05)
			, mWaterColor(Ogre::Vector3(0,0.1,0.172))
            , mNormalDistortion(0.09)
            , mSunPosition(Ogre::Vector3(5000,3000,1))
            , mSunStrength(1.75)
            , mSunArea(150)
            , mSunColor(Ogre::Vector3(1,0.75,0.25))
            , mFoamMaxDistance(75000000.0)
            , mFoamScale(0.0075)
            , mFoamStart(0)
            , mFoamTransparency(1)
            , mDepthLimit(0)
            , mDistLimit(0)
            , mSmoothPower(30)
            , mCausticsScale(20)
            , mCausticsPower(15)
            , mCausticsEnd(0.55)
			, mGodRaysExposure(Ogre::Vector3(0.76,2.46,2.29))
			, mGodRaysIntensity(0.015)
			, mUnderwaterCameraSwitchDelta(1.25f)
			, mCurrentFrameUnderwater(false)
            , mMesh(new Mesh(this))
			, mMaterialManager(new MaterialManager(this))
			, mRttManager(new RttManager(this))
			, mTextureManager(new TextureManager(this))
			, mGodRaysManager(new GodRaysManager(this))
			, mDecalsManager(new DecalsManager(this))
			, mGPUNormalMapManager(new GPUNormalMapManager(this))
			, mCfgFileManager(new CfgFileManager(this))
			, mModule(0)
            , mComponents(HYDRAX_COMPONENTS_NONE)
    {
        HydraxLOG("Hydrax created.");
    }
Beispiel #17
0
  Hydrax::~Hydrax()
  {
    remove();

    if(mModule)
    {
      delete mModule;
    }

    delete mTextureManager;
    delete mMaterialManager;
    delete mGPUNormalMapManager;
    delete mDecalsManager;
    delete mGodRaysManager;
    delete mRttManager;
    delete mCfgFileManager;
    delete mMesh;
    HydraxLOG("Hydrax object removed.");
  }
	float Image::getValueLI(const float &x, const float &y, const int &c) const
	{
#if HYDRAX_IMAGE_CHECK_PIXELS == 1
		if (c < 0 || c > mChannels ||
			x < 0 || x > mSize.Width ||
			y < 0 || y > mSize.Height)
		{
			HydraxLOG("Error in Image::getValue, x = " + Ogre::StringConverter::toString(x)
				                             + " y = " + Ogre::StringConverter::toString(y)
											 + " Channel = " + Ogre::StringConverter::toString(c));

			return 0;
		}
#endif

		int xINT = static_cast<int>(x),
		    yINT = static_cast<int>(y);

		float xDIFF = x-xINT,
			  yDIFF = y-yINT,
			  _xDIFF = 1-xDIFF,
			  _yDIFF = 1-yDIFF;

		//   A      B
		//
		//
		//   C      D
		float A = mData[(yINT*mSize.Width+xINT)*mChannels+c],
			  B = mData[(yINT*mSize.Width+xINT+1)*mChannels+c],
			  C = mData[((yINT+1)*mSize.Width+xINT)*mChannels+c],
			  D = mData[((yINT+1)*mSize.Width+xINT+1)*mChannels+c];

		return A*_xDIFF*_yDIFF +
			   B* xDIFF*_yDIFF +
			   C*_xDIFF* yDIFF +
			   D* xDIFF* yDIFF;
	}
Beispiel #19
0
	void SimpleGrid::setOptions(const Options &Options)
	{
		mMeshOptions.MeshSize     = Options.MeshSize;
		mMeshOptions.MeshStrength = Options.Strength;
		mMeshOptions.MeshComplexity = Options.Complexity;

		mHydrax->getMesh()->setOptions(mMeshOptions);
		mHydrax->_setStrength(Options.Strength);

		if (isCreated())
		{
			if (Options.Complexity != mOptions.Complexity || Options.ChoppyWaves != Options.ChoppyWaves)
			{
				remove();
				mOptions = Options;
				create();

				if (mNormalMode == MaterialManager::NM_RTT)
				{
					if (!mNoise->createGPUNormalMapResources(mHydrax->getGPUNormalMapManager()))
					{
						HydraxLOG(mNoise->getName() + " doesn't support GPU Normal map generation.");
					}
				}

				Ogre::String MaterialNameTmp = mHydrax->getMesh()->getMaterialName();
				mHydrax->getMesh()->remove();
				
				mHydrax->getMesh()->setOptions(getMeshOptions());
				mHydrax->getMesh()->setMaterialName(MaterialNameTmp);
				mHydrax->getMesh()->create();

				return;
			}

			mOptions = Options;

			int v, u;
			if (getNormalMode() == MaterialManager::NM_VERTEX)
			{
				Mesh::POS_NORM_VERTEX* Vertices = static_cast<Mesh::POS_NORM_VERTEX*>(mVertices);

				for(v=0; v<mOptions.Complexity; v++)
				{
					for(u=0; u<mOptions.Complexity; u++)
					{
						Vertices[v*mOptions.Complexity + u].x  = (static_cast<float>(v)/(mOptions.Complexity-1)) * mOptions.MeshSize.Width;
						Vertices[v*mOptions.Complexity + u].z  = (static_cast<float>(u)/(mOptions.Complexity-1)) * mOptions.MeshSize.Height;
					}
				}

				if (mOptions.ChoppyWaves && mVerticesChoppyBuffer)
			    {
				    for(int i = 0; i < mOptions.Complexity*mOptions.Complexity; i++)
				    {
					    mVerticesChoppyBuffer[i] = Vertices[i];
				    }
				}
			}
			else if (getNormalMode() == MaterialManager::NM_RTT)
			{
				Mesh::POS_VERTEX* Vertices = static_cast<Mesh::POS_VERTEX*>(mVertices);

				for(v=0; v<mOptions.Complexity; v++)
				{
					for(u=0; u<mOptions.Complexity; u++)
					{
						Vertices[v*mOptions.Complexity + u].x  = (static_cast<float>(v)/(mOptions.Complexity-1)) * mOptions.MeshSize.Width;
						Vertices[v*mOptions.Complexity + u].z  = (static_cast<float>(u)/(mOptions.Complexity-1)) * mOptions.MeshSize.Height;
					}
				}
			}
			
			return;
		} 

		mOptions = Options;
	}
	void Hydrax::setModule(Module::Module* Module, const bool& DeleteOldModule)
	{
		if (mModule)
		{
			if (mModule->getNormalMode() != Module->getNormalMode())
			{
				mMaterialManager->createMaterials(mComponents, MaterialManager::Options(mShaderMode, Module->getNormalMode()));

		        mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName());
			}

			if (mModule->getNormalMode() == MaterialManager::NM_RTT && mModule->isCreated() && mModule->getNoise()->areGPUNormalMapResourcesCreated())
			{
				mModule->getNoise()->removeGPUNormalMapResources(mGPUNormalMapManager);
			}

			if (DeleteOldModule)
			{
			    delete mModule;
			}
			else
			{
				mModule->remove();
			}

			// Due to modules can change -internally- scene nodes position,
			// just reset them to the original position.
			setPosition(mPosition);
		}

		mModule = Module;

		if (mCreated)
		{
			if (!mModule->isCreated())
			{
				mModule->create();

				if (mModule->getNormalMode() == MaterialManager::NM_RTT)
				{
					if (!mModule->getNoise()->createGPUNormalMapResources(mGPUNormalMapManager))
					{
						HydraxLOG(mModule->getNoise()->getName() + " doesn't support GPU Normal map generation.");
					}
				}
			}
			else
			{
				if (mModule->getNormalMode() == MaterialManager::NM_RTT)
				{
					if (!mModule->getNoise()->areGPUNormalMapResourcesCreated())
					{
						if (!mModule->getNoise()->createGPUNormalMapResources(mGPUNormalMapManager))
						{
							HydraxLOG(mModule->getNoise()->getName() + " doesn't support GPU Normal map generation.");
						}
					}
				}
				else
				{
					if (mModule->getNoise()->areGPUNormalMapResourcesCreated())
					{
						mModule->getNoise()->removeGPUNormalMapResources(mGPUNormalMapManager);
					}
				}
			}

		    HydraxLOG("Updating water mesh...");
		    Ogre::String MaterialNameTmp = mMesh->getMaterialName();

		    HydraxLOG("Deleting water mesh...");
		    mMesh->remove();
		    HydraxLOG("Water mesh deleted.");

		    HydraxLOG("Creating water mesh...");
		    mMesh->setOptions(mModule->getMeshOptions());
		    mMesh->setMaterialName(MaterialNameTmp);
		    mMesh->create();
		    setPosition(mPosition);
		    HydraxLOG("Water mesh created.");

		    HydraxLOG("Module set.");
		}
	}
    void Hydrax::setComponents(const HydraxComponent &Components)
    {
        mComponents = Components;

        if (isComponent(HYDRAX_COMPONENT_SMOOTH) || isComponent(HYDRAX_COMPONENT_CAUSTICS) || isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
        {
			// Delete smooth and/or caustics components wich needs depth component
            if (!isComponent(HYDRAX_COMPONENT_DEPTH))
            {
				HydraxComponent s  = HYDRAX_COMPONENTS_NONE,
			                    f  = HYDRAX_COMPONENTS_NONE,
								u  = HYDRAX_COMPONENTS_NONE,
				                ur = HYDRAX_COMPONENTS_NONE;

				if (isComponent(HYDRAX_COMPONENT_SUN))
				{
					s = HYDRAX_COMPONENT_SUN;
				}
				if (isComponent(HYDRAX_COMPONENT_FOAM))
				{
					f = HYDRAX_COMPONENT_FOAM;
				}
				if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
				{
					u = HYDRAX_COMPONENT_UNDERWATER;
				}
				if (isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS))
				{
					ur = HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS;
				}

				if (isComponent(HYDRAX_COMPONENT_SMOOTH))
				{
					HydraxLOG("Smooth component needs depth component... smooth component desactivated.");
				}
				if (isComponent(HYDRAX_COMPONENT_CAUSTICS))
				{
					HydraxLOG("Caustics component needs depth component... caustics component desactivated.");
				}
				if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
				{
					HydraxLOG("God rays component needs depth component... god rays component desactivated.");
				}

		        mComponents = static_cast<HydraxComponent>(s|f|u|ur);
            }
        }

		if (isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS) || isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
		{
			// Delete underwater reflections components wich needs underwater component
			if (!isComponent(HYDRAX_COMPONENT_UNDERWATER))
			{
				HydraxComponent s  = HYDRAX_COMPONENTS_NONE,
			                    f  = HYDRAX_COMPONENTS_NONE,
								d  = HYDRAX_COMPONENTS_NONE,
								sm = HYDRAX_COMPONENTS_NONE,
								c  = HYDRAX_COMPONENTS_NONE;

				if (isComponent(HYDRAX_COMPONENT_SUN))
				{
					s = HYDRAX_COMPONENT_SUN;
				}
				if (isComponent(HYDRAX_COMPONENT_FOAM))
				{
					f = HYDRAX_COMPONENT_FOAM;
				}
				if (isComponent(HYDRAX_COMPONENT_DEPTH))
				{
					d = HYDRAX_COMPONENT_DEPTH;
				}
				if (isComponent(HYDRAX_COMPONENT_SMOOTH))
				{
					sm = HYDRAX_COMPONENT_SMOOTH;
				}
				if (isComponent(HYDRAX_COMPONENT_CAUSTICS))
				{
					c = HYDRAX_COMPONENT_CAUSTICS;
				}

				if (isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS))
				{
					HydraxLOG("Underwater reflections component needs underwater component... underwater reflections component desactivated.");
				}
				if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
				{
					HydraxLOG("God rays component needs underwater component... god rays component desactivated.");
				}

				mComponents = static_cast<HydraxComponent>(s|f|d|sm|c);
			}

			if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS) && !isComponent(HYDRAX_COMPONENT_SUN))
			{
				HydraxLOG("God rays component needs sun component... god rays component desactivated.");

				HydraxComponent f  = HYDRAX_COMPONENTS_NONE,
								d  = HYDRAX_COMPONENTS_NONE,
								c  = HYDRAX_COMPONENTS_NONE,
								sm = HYDRAX_COMPONENTS_NONE,
								u  = HYDRAX_COMPONENTS_NONE,
				                ur = HYDRAX_COMPONENTS_NONE;

				if (isComponent(HYDRAX_COMPONENT_FOAM))
				{
					f = HYDRAX_COMPONENT_FOAM;
				}
				if (isComponent(HYDRAX_COMPONENT_DEPTH))
				{
					d = HYDRAX_COMPONENT_DEPTH;
				}
				if (isComponent(HYDRAX_COMPONENT_SMOOTH))
				{
					sm = HYDRAX_COMPONENT_SMOOTH;
				}
				if (isComponent(HYDRAX_COMPONENT_CAUSTICS))
				{
					c = HYDRAX_COMPONENT_CAUSTICS;
				}
				if (isComponent(HYDRAX_COMPONENT_UNDERWATER))
				{
					u = HYDRAX_COMPONENT_UNDERWATER;
				}
				if (isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS))
				{
					ur = HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS;
				}

				mComponents = static_cast<HydraxComponent>(f|d|sm|c|u|ur);
			}
		}

		int NumberOfDepthChannels = 0;

	    if (isComponent(HYDRAX_COMPONENT_DEPTH))
		{
			NumberOfDepthChannels++;

			if (isComponent(HYDRAX_COMPONENT_CAUSTICS))
		    {
			    NumberOfDepthChannels++;
		    }

			if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
		    {
			    NumberOfDepthChannels++;
		    }
		}

		if (NumberOfDepthChannels > 0)
		{
		    mRttManager->setNumberOfChannels(RttManager::RTT_DEPTH, static_cast<RttManager::NumberOfChannels>(NumberOfDepthChannels));
		}

		if (!mCreated || !mModule)
		{
			return;
		}

		if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
		{
			mGodRaysManager->create(mComponents);
		}
		else
		{
			mGodRaysManager->remove();
		}

		// Check for Rtt's
		if (mCurrentFrameUnderwater && isComponent(HYDRAX_COMPONENT_UNDERWATER) && !isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS))
		{
			mRttManager->remove(RttManager::RTT_REFLECTION);
		}
		else
		{
			mRttManager->initialize(RttManager::RTT_REFLECTION);
		}

		if (!isComponent(HYDRAX_COMPONENT_DEPTH))
		{
			mRttManager->remove(RttManager::RTT_DEPTH);
			mRttManager->remove(RttManager::RTT_DEPTH_REFLECTION);
		}
		else
		{
			mRttManager->initialize(RttManager::RTT_DEPTH);

			if (isComponent(HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS) && mCurrentFrameUnderwater)
			{
				mRttManager->initialize(RttManager::RTT_DEPTH_REFLECTION);
			}
			else
			{
				mRttManager->remove(RttManager::RTT_DEPTH_REFLECTION);
			}
		}
		if (!isComponent(HYDRAX_COMPONENT_UNDERWATER) && mCurrentFrameUnderwater)
		{
			mRttManager->getTexture(RttManager::RTT_REFRACTION)->
				getBuffer()->getRenderTarget()->getViewport(0)->
					 setSkiesEnabled(false);

			mRttManager->getTexture(RttManager::RTT_REFLECTION)->
				getBuffer()->getRenderTarget()->getViewport(0)->
					 setSkiesEnabled(true);
		}

		mMesh->setMaterialName("BaseWhiteNoLighting");
		mMaterialManager->createMaterials(mComponents, MaterialManager::Options(mShaderMode, mModule->getNormalMode()));

		if (!isComponent(HYDRAX_COMPONENT_UNDERWATER))
		{
			mCurrentFrameUnderwater = false;
		}

		mMesh->setMaterialName(mCurrentFrameUnderwater ?
			mMaterialManager->getMaterial(MaterialManager::MAT_UNDERWATER)->getName() :
		    mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName());

		if (mCurrentFrameUnderwater)
		{
			mMaterialManager->setCompositorEnable(MaterialManager::COMP_UNDERWATER, true);
		}
    }
    void Hydrax::create()
    {
		if (!mModule)
		{
			HydraxLOG("Module isn't set, skipping...");

            return;
		}

        if (mCreated)
        {
            HydraxLOG("Hydrax is alredy created, skipping...");

            return;
        }

        HydraxLOG("Creating module...");
        mModule->create();

		if (mModule->getNormalMode() == MaterialManager::NM_RTT)
		{
			if (!mModule->getNoise()->createGPUNormalMapResources(mGPUNormalMapManager))
			{
				HydraxLOG(mModule->getNoise()->getName() + " doesn't support GPU Normal map generation.");
			}
		}
		else
		{
			if (mModule->getNoise()->areGPUNormalMapResourcesCreated())
			{
			    mModule->getNoise()->removeGPUNormalMapResources(mGPUNormalMapManager);
			}
		}
        HydraxLOG("Module created.");

		HydraxLOG("Initializating RTT Manager...");
		mRttManager->initialize(RttManager::RTT_REFLECTION);
		mRttManager->initialize(RttManager::RTT_REFRACTION);
		if (isComponent(HYDRAX_COMPONENT_DEPTH))
		{
			mRttManager->initialize(RttManager::RTT_DEPTH);
		}
        HydraxLOG("RTT manager initialized.");

		HydraxLOG("Registring device restored listener...");
		mDeviceListener.mHydrax = this;
		Ogre::Root::getSingleton().getRenderSystem()->addListener(&mDeviceListener);
		HydraxLOG("Device restored listener registred.");

		HydraxLOG("Creating materials...");
		mMaterialManager->createMaterials(mComponents, MaterialManager::Options(mShaderMode, mModule->getNormalMode()));
		mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName());
		HydraxLOG("Materials created.");

		if (isComponent(HYDRAX_COMPONENT_UNDERWATER_GODRAYS))
		{
			HydraxLOG("Creating god rays...");
			mGodRaysManager->create(mComponents);
			HydraxLOG("God rays created.");
		}

        HydraxLOG("Creating water mesh...");
		mMesh->setOptions(mModule->getMeshOptions());
        mMesh->create();
        HydraxLOG("Water mesh created.");

        mCreated = true;

		// Hide if !mVisible
		_checkVisible();
		// Check for underwater
		_checkUnderwater(0);
    }
Beispiel #23
0
	SimpleGrid::~SimpleGrid()
	{
		remove();

		HydraxLOG(getName() + " destroyed.");
	}