mercator 0.4.0
A terrain generation library for the Worldforge system.
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 "Shader.h"
9#include "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
40namespace Mercator {
41
50class GrassShader : public Shader {
51 private:
53 float m_lowThreshold;
55 float m_highThreshold;
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
95 float cutoff = default_cutoff,
100 explicit GrassShader(const Parameters & params);
101 ~GrassShader() override;
102
104 float lowThreshold() const { return m_lowThreshold; }
106 float highThreshold() const { return m_highThreshold; }
108 float cutoff() const { return m_cutoff; }
110 float intercept() const { return m_intercept; }
111
112 bool checkIntersect(const Segment &) const override;
113 void shade(Surface &) const override;
114};
115
116} // namespace Mercator
117
118#endif // MERCATOR_FILL_GRASS_SHADER_H
Shader for adding grass to the terrain.
Definition: GrassShader.h:50
static const std::string key_lowThreshold
Key string used when specifying the low threshold parameter.
Definition: GrassShader.h:70
static const std::string key_cutoff
Key string used when specifying the cutoff parameter.
Definition: GrassShader.h:74
static const float default_lowThreshold
Default level above which the shader renders.
Definition: GrassShader.h:79
void shade(Surface &) const override
Populate a Surface with data.
Definition: GrassShader.cpp:88
float cutoff() const
Accessor for slope below which grass is opaque.
Definition: GrassShader.h:108
GrassShader(float lowThreshold=default_lowThreshold, float highThreshold=default_highThreshold, float cutoff=default_cutoff, float intercept=default_intercept)
Constructor.
Definition: GrassShader.cpp:30
static const float default_highThreshold
Default level below which the shader renders.
Definition: GrassShader.h:81
bool checkIntersect(const Segment &) const override
Check whether this Shader has any effect on the given Segment.
Definition: GrassShader.cpp:78
static const float default_intercept
Default slope steeper than which no grass grows.
Definition: GrassShader.h:85
float highThreshold() const
Accessor for level below which the shader renders.
Definition: GrassShader.h:106
static const std::string key_highThreshold
Key string used when specifying the high threshold parameter.
Definition: GrassShader.h:72
static const float default_cutoff
Default slope below which grass is opaque.
Definition: GrassShader.h:83
float intercept() const
Accessor for slope steeper than which no grass grows.
Definition: GrassShader.h:110
float lowThreshold() const
Accessor for level above which the shader renders.
Definition: GrassShader.h:104
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:37
Base class for Shader objects which create surface data for use when rendering terrain.
Definition: Shader.h:25
std::map< std::string, float > Parameters
STL map of parameter values for a shader constructor.
Definition: Shader.h:59
Data store for terrain surface data.
Definition: Surface.h:23