Caelum
GroundFog.h
1 /*
2 This file is part of Caelum.
3 See http://www.ogre3d.org/wiki/index.php/Caelum
4 
5 Copyright (c) 2006-2007 Caelum team. See Contributors.txt for details.
6 
7 Caelum is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Caelum is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License
18 along with Caelum. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef GROUNDFOG_H
22 #define GROUNDFOG_H
23 
24 #include "CaelumPrerequisites.h"
25 #include "CameraBoundElement.h"
26 #include "PrivatePtr.h"
27 #include "FastGpuParamRef.h"
28 
29 namespace Caelum
30 {
47  class CAELUM_EXPORT GroundFog: public CameraBoundElement
48  {
49  public:
50  static const Ogre::String DEFAULT_PASS_NAME;
51 
54  GroundFog (Ogre::SceneManager *scene,
55  Ogre::SceneNode *caelumRootNode,
56  const Ogre::String &domeMaterialName = "CaelumGroundFogDome",
57  const Ogre::String &domeEntityName = "CaelumGroundFogDome");
58 
61  virtual ~GroundFog ();
62 
65  typedef std::set<Ogre::Pass *> PassSet;
66 
71  PassSet& getPasses();
72 
77  const PassSet& getPasses () const;
78 
83  void findFogPassesByName (const Ogre::String& passName = DEFAULT_PASS_NAME);
84 
86  void setDensity (Ogre::Real density);
87 
89  Ogre::Real getDensity () const;
90 
92  void setColour (const Ogre::ColourValue &colour);
93 
95  const Ogre::ColourValue getColour () const;
96 
98  void setVerticalDecay (Ogre::Real verticalDecay);
99 
101  Ogre::Real getVerticalDecay () const;
102 
106  void setGroundLevel (Ogre::Real GroundLevela);
107 
110  Ogre::Real getGroundLevel () const;
111 
115  void forceUpdate ();
116 
117  private:
119  Ogre::Real mDensity;
120 
122  Ogre::Real mVerticalDecay;
123 
125  Ogre::Real mGroundLevel;
126 
128  Ogre::ColourValue mFogColour;
129 
130  private:
132  Ogre::SceneManager* mScene;
133 
135  PrivateMaterialPtr mDomeMaterial;
136 
138  PrivateSceneNodePtr mDomeNode;
139 
141  PrivateEntityPtr mDomeEntity;
142 
143  // Called whenever something changes to update the sky dome.
144  void updateSkyFogging();
145 
146  protected:
148  virtual void setFarRadius (Ogre::Real radius);
149 
150  public:
152  virtual void notifyCameraChanged (Ogre::Camera *cam);
153 
154  void setQueryFlags (uint flags) { mDomeEntity->setQueryFlags (flags); }
155  uint getQueryFlags () const { return mDomeEntity->getQueryFlags (); }
156  void setVisibilityFlags (uint flags) { mDomeEntity->setVisibilityFlags (flags); }
157  uint getVisibilityFlags () const { return mDomeEntity->getVisibilityFlags (); }
158 
159  private:
161  PassSet mPasses;
162 
164  struct FogParamsBase
165  {
166  void setup(Ogre::GpuProgramParametersSharedPtr fpParams);
167 
168  Ogre::GpuProgramParametersSharedPtr fpParams;
169 
170  FastGpuParamRef fogDensity;
171  FastGpuParamRef fogColour;
172  FastGpuParamRef fogVerticalDecay;
173  FastGpuParamRef fogGroundLevel;
174 
175  };
176 
177  struct DomeFogParams: public FogParamsBase {
178  void setup(Ogre::GpuProgramParametersSharedPtr fpParams);
179  FastGpuParamRef cameraHeight;
180  } mDomeParams;
181 
182  struct PassFogParams: public FogParamsBase {
183  PassFogParams(Ogre::GpuProgramParametersSharedPtr fpParams) { setup(fpParams); }
184 
185  static inline bool lessThanByParams(const PassFogParams& a, const PassFogParams& b) {
186  return a.fpParams.get() <= b.fpParams.get();
187  }
188 
189  static inline bool equalByParams(const PassFogParams& a, const PassFogParams& b) {
190  return a.fpParams.get() == b.fpParams.get();
191  }
192  };
193 
194  typedef std::vector<PassFogParams> PassFogParamsVector;
195  PassFogParamsVector mPassFogParams;
196 
198  void updatePassFogParams();
199  };
200 }
201 
202 #endif //GROUNDFOG_H
Exponential ground fog system implementation.
Definition: GroundFog.h:47
std::set< Ogre::Pass * > PassSet
Typedef for easier manipulation of a set of Passes.
Definition: GroundFog.h:65
A camera-bound element.
An optimized reference to a gpu shared parameter.
Caelum namespace.
Definition: Astronomy.cpp:24