Mercator
GrassShader.h
1 // This file may be redistributed and modified only under the terms of
2 // the GNU General Public License (See COPYING for details).
3 // Copyright (C) 2003 Alistair Riddoch
4 
5 #ifndef MERCATOR_FILL_GRASS_SHADER_H
6 #define MERCATOR_FILL_GRASS_SHADER_H
7 
8 #include <Mercator/Shader.h>
9 #include <Mercator/Surface.h>
10 
11 /* alpha ^
12  * |
13  * 1 |_______________________ cutoff
14  * | \
15  * | \
16  * | \
17  * | \
18  * | \
19  * | \
20  * | \
21  * | \
22  * | \
23  * | \ intercept
24  * 0 |_________________________________\_________________________> slope
25  *
26  * This shader is used to add grassy vegetation to some terrain.
27  * The mask generated by this shader depends on two factors. The altitude
28  * of the terrain, and its slope. Two parameter specify the low and high
29  * altitude values between which vegetation grows. The low value will typically
30  * be just above sea level, and the high value could be anything up to the
31  * height above which plants cannot grow.
32  *
33  * The cutoff parameter specifies the slope below which the vegetation is
34  * completely opaque. The intercept parameter specifies the slope above which
35  * vegetetation will not grow on the terrain. Between these values the
36  * vegetation is blended onto the terrain to give an impression of a light
37  * covering.
38  */
39 
40 namespace Mercator {
41 
50 class GrassShader : public Shader {
51  private:
57  float m_cutoff;
59  float m_intercept;
60 
67  ColorT slopeToAlpha(float height, float slope) const;
68  public:
70  static const std::string key_lowThreshold;
72  static const std::string key_highThreshold;
74  static const std::string key_cutoff;
76  static const std::string key_intercept;
77 
79  static const float default_lowThreshold;
81  static const float default_highThreshold;
83  static const float default_cutoff;
85  static const float default_intercept;
86 
93  explicit GrassShader(float lowThreshold = default_lowThreshold,
94  float highThreshold = default_highThreshold,
95  float cutoff = default_cutoff,
96  float intercept = default_intercept);
100  explicit GrassShader(const Parameters & params);
101  virtual ~GrassShader();
102 
104  const float lowThreshold() const { return m_lowThreshold; }
106  const float highThreshold() const { return m_highThreshold; }
108  const float cutoff() const { return m_cutoff; }
110  const float intercept() const { return m_intercept; }
111 
112  virtual bool checkIntersect(const Segment &) const;
113  virtual void shade(Surface &) const;
114 };
115 
116 } // namespace Mercator
117 
118 #endif // MERCATOR_FILL_GRASS_SHADER_H
virtual bool checkIntersect(const Segment &) const
Check whether this Shader has any effect on the given Segment.
Definition: GrassShader.cpp:80
static const float default_highThreshold
Default level below which the shader renders.
Definition: GrassShader.h:81
static const std::string key_lowThreshold
Key string used when specifying the low threshold parameter.
Definition: GrassShader.h:70
Definition: Area.cpp:20
ColorT slopeToAlpha(float height, float slope) const
Determine the alpha value for grass for a given slope.
Definition: GrassShader.cpp:67
Data store for terrain surface data.
Definition: Surface.h:22
float m_cutoff
The slope below which grass is opaque.
Definition: GrassShader.h:57
virtual void shade(Surface &) const
Populate a Surface with data.
Definition: GrassShader.cpp:90
std::map< std::string, float > Parameters
STL map of parameter values for a shader constructor.
Definition: Shader.h:63
float m_intercept
The slope steeper than which no grass grows.
Definition: GrassShader.h:59
static const float default_cutoff
Default slope below which grass is opaque.
Definition: GrassShader.h:83
static const std::string key_intercept
Key string used when specifying the intercept parameter.
Definition: GrassShader.h:76
Class storing heightfield and other data for a single fixed size square area of terrain defined by fo...
Definition: Segment.h:36
const float intercept() const
Accessor for slope steeper than which no grass grows.
Definition: GrassShader.h:110
float m_lowThreshold
The level above which the shader renders.
Definition: GrassShader.h:53
Base class for Shader objects which create surface data for use when rendering terrain.
Definition: Shader.h:29
const float lowThreshold() const
Accessor for level above which the shader renders.
Definition: GrassShader.h:104
float m_highThreshold
The level below which the shader renders.
Definition: GrassShader.h:55
static const std::string key_cutoff
Key string used when specifying the cutoff parameter.
Definition: GrassShader.h:74
const float cutoff() const
Accessor for slope below which grass is opaque.
Definition: GrassShader.h:108
static const float default_lowThreshold
Default level above which the shader renders.
Definition: GrassShader.h:79
Shader for adding grass to the terrain.
Definition: GrassShader.h:50
static const float default_intercept
Default slope steeper than which no grass grows.
Definition: GrassShader.h:85
static const std::string key_highThreshold
Key string used when specifying the high threshold parameter.
Definition: GrassShader.h:72
const float highThreshold() const
Accessor for level below which the shader renders.
Definition: GrassShader.h:106
GrassShader(float lowThreshold=default_lowThreshold, float highThreshold=default_highThreshold, float cutoff=default_cutoff, float intercept=default_intercept)
Constructor.
Definition: GrassShader.cpp:30