2
This file is part of Caelum.
3
See http://www.ogre3d.org/wiki/index.php/Caelum
5
Copyright (c) 2006-2007 Caelum team. See Contributors.txt for details.
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.
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.
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/>.
21
#ifndef LAYEREDCLOUDS_H
22
#define LAYEREDCLOUDS_H
24
#include "CaelumPrerequisites.h"
25
#include "CameraBoundElement.h"
29
/** Class for layered clouds.
30
* @note This is tighly integrated with LayeredCloud.cg and LayeredClouds.material.
31
* There are two "cloud mass" layers blended to create animating clouds and an extra
33
* Most of the parameters in this class are direct wrappers from GPU shader params.
35
* Cloud offsets and speeds are not in any meaningful world units. Maybe they should
36
* be in radians or something?
38
class CAELUM_EXPORT LayeredClouds: public CameraBoundElement {
40
/** Standard constructor.
41
* @param scene: Scene to add cloud dome to. This class takes control
42
* of the scene's skydome.
43
* @param material: Name of the material to load. It would be a lot
44
* more consistent to generate the material in code.
47
Ogre::SceneManager* scene,
48
Ogre::SceneNode *caelumRootNode,
49
const Ogre::String &resourceGroupName="Caelum",
50
const Ogre::String &materialName="CaelumLayeredClouds",
51
const Ogre::String &meshName="CaelumLayeredClouds",
52
const Ogre::String &entityName="CaelumLayeredClouds");
56
/** Update cloud material.
57
* @param timePassed Time passed since last update.
58
* @param sunDirection Vector towards the sun.
59
* @param sunColour Colour of the sun.
62
Ogre::Real timePassed,
63
const Ogre::Vector3& sunDirection,
64
const Ogre::ColourValue& sunColour,
65
const Ogre::ColourValue& fogColour);
67
/** Sets cloud cover, between 0 (completely clear) and 1 (completely covered)
68
* @param cloudCover Cloud cover between 0 and 1
70
void setCloudCover (const Ogre::Real cloudCover);
72
/** Gets the current cloud cover.
73
* @return Cloud cover, between 0 and 1
75
Ogre::Real getCloudCover () const;
77
/** Set the image used to lookup the cloud coverage threshold.
78
* This image is used to calculate the cloud coverage threshold
79
* based on the desired cloud cover.
81
* The cloud coverage threshold is substracted from cloud intensity
82
* at any point; to generate fewer or more clouds. That threshold is
83
* not linear, a lookup is required to ensure that setCloudCover(0.1)
84
* will actually have 10% the clouds at setCloudCover(1).
86
* The lookup is the inverse of the sum on the histogram, and was
87
* calculated with a small hacky tool.
89
void setCloudCoverLookup (const Ogre::String& fileName);
91
/** Disable any cloud cover lookup.
92
* @see setCloudCoverLookup.
94
void disableCloudCoverLookup ();
97
/** Sets blending factor between the two cloud mass layers.
99
void setCloudMassBlend (const Ogre::Real cloudCover);
101
/** Gets the current blending factor between the two cloud mass layers
103
Ogre::Real getCloudMassBlend () const;
105
/** Sets current offset(translation) of the cloud mass on the sky.
107
void setCloudMassOffset (const Ogre::Vector2 &cloudMassOffset);
109
/** Gets current offset(translation) of the cloud mass on the sky.
111
Ogre::Vector2 getCloudMassOffset () const;
113
/** Sets current offset(translation) of cloud details on the sky.
115
void setCloudDetailOffset (const Ogre::Vector2 &cloudMassOffset);
117
/** Gets current offset(translation) of cloud details on the sky.
119
Ogre::Vector2 getCloudDetailOffset () const;
122
/** If the cloud layer is animating itself.
123
* @note If this is true then parameters like cloudMassBlend and offsets
124
* are set every update().
126
bool isAnimating () const;
128
/** Switch internal animation on/off
130
void setAnimating (bool animating);
132
/** Sets cloud movement speed.
133
* @param cloudSpeed Cloud movement speed.
135
void setCloudSpeed (const Ogre::Vector2 &cloudSpeed);
137
/** Gets cloud movement speed.
138
* @param cloudSpeed Cloud movement speed.
140
Ogre::Vector2 getCloudSpeed () const;
142
/** Sets the time it takes to blend two cloud shaped together, in seconds.
143
* @param cloudCover Cloud shape blend time in seconds
145
void setCloudBlendTime (const Ogre::Real cloudBlendTime);
147
/** Gets the time it takes to blend two cloud shaped together, in seconds.
148
* @return Cloud shape blend time in seconds
150
Ogre::Real getCloudBlendTime () const;
153
/// Shortcut function for fragment program parameters
154
Ogre::GpuProgramParametersSharedPtr getFpParams();
156
/// Shortcut function for fragment program parameters
157
Ogre::GpuProgramParametersSharedPtr getVpParams();
159
/// Shortcut function for texture unit state parameters
160
Ogre::TextureUnitState* getTUS(unsigned short num);
162
/// Set the sunDirection parameter in the shaders.
163
void setSunDirection(const Ogre::Vector3 &sunDirection);
165
/// Set the sunColour parameter in the shaders.
166
void setSunColour(const Ogre::ColourValue &sunColour);
168
/// Set the fogColour parameter in the shaders.
169
void setFogColour(const Ogre::ColourValue &fogColour);
171
/// Sets inverse Haze height.
172
void setInvHazeHeight (const Ogre::Real invHazeHeight);
174
/// Current cloud coverage
175
Ogre::Real mCloudCover;
177
/// Current cloud blend factor
178
Ogre::Real mCloudMassBlend;
180
/// Current cloud layer offset.
181
Ogre::Vector2 mCloudMassOffset;
183
/// Current cloud detail layer offset.
184
Ogre::Vector2 mCloudDetailOffset;
186
/// Lookup used for cloud coverage.
187
/// see setCloudCoverLookup.
188
std::auto_ptr<Ogre::Image> mCloudCoverLookup;
191
/// If this class controls animation for itself.
194
/// Current cloud blend time.
195
Ogre::Real mCloudBlendTime;
197
/** If true then CloudMassBlend is increased in animation; otherwise it's
198
* decreased. This is changed each time it reaches the end.
200
bool mCloudBlendAnimationDirection;
202
/// Current cloud speed
203
Ogre::Vector2 mCloudSpeed;
207
Ogre::MaterialPtr mMaterial;
209
/// True if selected technique has shaders.
210
bool mShadersEnabled;
213
Ogre::SceneNode *mNode;
215
/// Cloud plane entity
216
Ogre::Entity *mEntity;
218
/// Reference to scene manager.
219
Ogre::SceneManager *mSceneMgr;
222
/// Handle camera change.
223
virtual void notifyCameraChanged (Ogre::Camera *cam);
226
/// Handle far radius.
227
virtual void setFarRadius (Ogre::Real radius);
229
} // namespace caelum
231
#endif // LAYEREDCLOUDS_H