21 #include "CaelumPrecompiled.h" 22 #include "GroundFog.h" 23 #include "CaelumExceptions.h" 24 #include "InternalUtilities.h" 28 const Ogre::String GroundFog::DEFAULT_PASS_NAME =
"CaelumGroundFog";
31 Ogre::SceneManager *sceneMgr,
32 Ogre::SceneNode *caelumRootNode,
33 const Ogre::String &domeMaterialName,
34 const Ogre::String &domeEntityName):
40 mDomeParams.setup(mDomeMaterial->getTechnique(0)->getPass(0)->getFragmentProgramParameters());
45 mDomeEntity.
reset (mScene->createEntity (domeEntityName, Ogre::SceneManager::PT_SPHERE));
46 mDomeEntity->setMaterialName (mDomeMaterial->getName ());
47 mDomeEntity->setCastShadows (
false);
48 mDomeEntity->setRenderQueueGroup (CAELUM_RENDER_QUEUE_GROUND_FOG);
49 sceneMgr->getRenderQueue()->getQueueGroup(CAELUM_RENDER_QUEUE_GROUND_FOG)->setShadowsEnabled(
false);
52 mDomeNode.
reset (caelumRootNode->createChildSceneNode ());
53 mDomeNode->attachObject (mDomeEntity.get());
59 mFogColour = Ogre::ColourValue::Black;
78 Ogre::MaterialManager *matManager = Ogre::MaterialManager::getSingletonPtr();
79 Ogre::MaterialManager::ResourceMapIterator matIt = matManager->getResourceIterator();
80 while (matIt.hasMoreElements()) {
82 #if OGRE_VERSION >= 0x00010900 83 Ogre::MaterialPtr mat = matIt.getNext().staticCast<Ogre::Material>();
85 Ogre::MaterialPtr mat = matIt.getNext();
88 Ogre::Material::TechniqueIterator techIt = mat->getTechniqueIterator();
89 while (techIt.hasMoreElements()) {
90 Ogre::Technique *tech = techIt.getNext();
91 Ogre::Technique::PassIterator passIt = tech->getPassIterator();
92 while (passIt.hasMoreElements()) {
93 Ogre::Pass *pass = passIt.getNext();
94 if (pass->getName() == passName) {
104 if (Ogre::Math::Abs(mDensity - density) > 0.000001) {
105 for (PassFogParamsVector::const_iterator it = mPassFogParams.begin(), end = mPassFogParams.end(); it != end; ++it) {
106 it->fogDensity.set(it->fpParams, density);
119 Ogre::Math::Abs(mFogColour.r - colour.r) > 0.001 ||
120 Ogre::Math::Abs(mFogColour.g - colour.g) > 0.001 ||
121 Ogre::Math::Abs(mFogColour.b - colour.b) > 0.001 ||
122 Ogre::Math::Abs(mFogColour.a - colour.a) > 0.001;
124 for (PassFogParamsVector::const_iterator it = mPassFogParams.begin(), end = mPassFogParams.end(); it != end; ++it) {
125 it->fogColour.set(it->fpParams, colour);
137 if (Ogre::Math::Abs(mVerticalDecay - verticalDecay) > 0.000001) {
138 for (PassFogParamsVector::const_iterator it = mPassFogParams.begin(), end = mPassFogParams.end(); it != end; ++it) {
139 it->fogVerticalDecay.set(it->fpParams, verticalDecay);
141 mVerticalDecay = verticalDecay;
147 return mVerticalDecay;
151 if (Ogre::Math::Abs(mGroundLevel - groundLevel) > 0.000001) {
152 for (PassFogParamsVector::const_iterator it = mPassFogParams.begin(), end = mPassFogParams.end(); it != end; ++it) {
153 it->fogGroundLevel.set(it->fpParams, groundLevel);
155 mGroundLevel = groundLevel;
164 void GroundFog::updateSkyFogging() {
165 mDomeParams.fogDensity.set(mDomeParams.fpParams, mDensity);
166 mDomeParams.fogVerticalDecay.set(mDomeParams.fpParams, mVerticalDecay);
167 mDomeParams.fogGroundLevel.set(mDomeParams.fpParams, mGroundLevel);
168 mDomeParams.fogColour.set(mDomeParams.fpParams, mFogColour);
173 updatePassFogParams();
174 for (PassFogParamsVector::const_iterator it = mPassFogParams.begin(), end = mPassFogParams.end(); it != end; ++it) {
175 const PassFogParams& params = *it;
176 params.fogDensity.set(params.fpParams, mDensity);
177 params.fogVerticalDecay.set(params.fpParams, mVerticalDecay);
178 params.fogGroundLevel.set(params.fpParams, mGroundLevel);
179 params.fogColour.set(params.fpParams, mFogColour);
184 void GroundFog::updatePassFogParams ()
186 mPassFogParams.clear();
187 for (PassSet::const_iterator it = mPasses.begin(), end = mPasses.end(); it != end; ++it) {
188 mPassFogParams.push_back(PassFogParams((*it)->getFragmentProgramParameters()));
190 std::sort(mPassFogParams.begin(), mPassFogParams.end(), PassFogParams::lessThanByParams);
191 std::unique(mPassFogParams.begin(), mPassFogParams.end(), PassFogParams::equalByParams);
194 void GroundFog::FogParamsBase::setup(Ogre::GpuProgramParametersSharedPtr fpParams) {
195 this->fpParams = fpParams;
196 fogDensity.bind(fpParams,
"fogDensity");
197 fogVerticalDecay.bind(fpParams,
"fogVerticalDecay");
198 fogGroundLevel.bind(fpParams,
"fogGroundLevel");
199 fogColour.bind(fpParams,
"fogColour");
202 void GroundFog::DomeFogParams::setup(Ogre::GpuProgramParametersSharedPtr fpParams) {
203 FogParamsBase::setup(fpParams);
204 cameraHeight.bind(fpParams,
"cameraHeight");
212 float cameraHeight = cam->getDerivedPosition().dotProduct(mDomeNode->_getDerivedOrientation() * Ogre::Vector3::UNIT_Y);
213 mDomeParams.cameraHeight.set(mDomeParams.fpParams, cameraHeight);
220 mDomeNode->setScale(Ogre::Vector3::UNIT_SCALE * radius / 50.0);
void setGroundLevel(Ogre::Real GroundLevela)
Sets the ground level.
virtual void notifyCameraChanged(Ogre::Camera *cam)=0
Notify new camera conditions.
virtual void setFarRadius(Ogre::Real radius)
Handle far radius.
const Ogre::ColourValue getColour() const
Gets fog colour.
void setDensity(Ogre::Real density)
Sets the fog density multiplier.
virtual ~GroundFog()
Virtual destructor.
static const Ogre::String pointerToString(void *pointer)
Quickly format a pointer as a string; in hex.
void findFogPassesByName(const Ogre::String &passName=DEFAULT_PASS_NAME)
Find caelum fog passes to control by name.
static Ogre::MaterialPtr checkLoadMaterialClone(const Ogre::String &originalName, const Ogre::String &cloneName)
Creates a private clone of a material from a script.
virtual void setFarRadius(Ogre::Real radius)
Abstract method to set the radius for this elements Derived classes should override this and resize t...
void setColour(const Ogre::ColourValue &colour)
Sets fog colour.
std::set< Ogre::Pass * > PassSet
Typedef for easier manipulation of a set of Passes.
void forceUpdate()
Forces an update of all the passes.
void reset(const InnerPointerType &newInner=TraitsT::getNullValue())
Change the inner value.
PassSet & getPasses()
Get the set of currently controlled passes.
virtual void notifyCameraChanged(Ogre::Camera *cam)
Handle camera change.
void setVerticalDecay(Ogre::Real verticalDecay)
Sets the vertical fog decay constant.
Ogre::Real getDensity() const
Get the fog density multiplier.
Ogre::Real getVerticalDecay() const
Get the vertical fog decay constant.
Ogre::Real getGroundLevel() const
Get the ground level.
GroundFog(Ogre::SceneManager *scene, Ogre::SceneNode *caelumRootNode, const Ogre::String &domeMaterialName="CaelumGroundFogDome", const Ogre::String &domeEntityName="CaelumGroundFogDome")
Constructor.