Mercator
GrassShader.h
00001 // This file may be redistributed and modified only under the terms of
00002 // the GNU General Public License (See COPYING for details).
00003 // Copyright (C) 2003 Alistair Riddoch
00004 
00005 #ifndef MERCATOR_FILL_GRASS_SHADER_H
00006 #define MERCATOR_FILL_GRASS_SHADER_H
00007 
00008 #include <Mercator/Shader.h>
00009 #include <Mercator/Surface.h>
00010 
00011 /* alpha ^
00012  *       |
00013  *     1 |_______________________ cutoff
00014  *       |                       \ 
00015  *       |                        \ 
00016  *       |                         \ 
00017  *       |                          \ 
00018  *       |                           \ 
00019  *       |                            \ 
00020  *       |                             \ 
00021  *       |                              \ 
00022  *       |                               \ 
00023  *       |                                \  intercept
00024  *     0 |_________________________________\_________________________> slope
00025  *
00026  * This shader is used to add grassy vegetation to some terrain.
00027  * The mask generated by this shader depends on two factors. The altitude
00028  * of the terrain, and its slope. Two parameter specify the low and high
00029  * altitude values between which vegetation grows. The low value will typically
00030  * be just above sea level, and the high value could be anything up to the
00031  * height above which plants cannot grow.
00032  *
00033  * The cutoff parameter specifies the slope below which the vegetation is
00034  * completely opaque. The intercept parameter specifies the slope above which
00035  * vegetetation will not grow on the terrain. Between these values the
00036  * vegetation is blended onto the terrain to give an impression of a light
00037  * covering.
00038  */
00039 
00040 namespace Mercator {
00041 
00050 class GrassShader : public Shader {
00051   private:
00053     float m_lowThreshold;
00055     float m_highThreshold;
00057     float m_cutoff;
00059     float m_intercept;
00060 
00067     ColorT slopeToAlpha(float height, float slope) const;
00068   public:
00070     static const std::string key_lowThreshold;
00072     static const std::string key_highThreshold;
00074     static const std::string key_cutoff;
00076     static const std::string key_intercept;
00077 
00079     static const float default_lowThreshold;
00081     static const float default_highThreshold;
00083     static const float default_cutoff;
00085     static const float default_intercept;
00086 
00093     explicit GrassShader(float lowThreshold = default_lowThreshold,
00094                          float highThreshold = default_highThreshold,
00095                          float cutoff = default_cutoff,
00096                          float intercept = default_intercept);
00100     explicit GrassShader(const Parameters & params);
00101     virtual ~GrassShader();
00102 
00104     const float lowThreshold() const { return m_lowThreshold; }
00106     const float highThreshold() const { return m_highThreshold; }
00108     const float cutoff() const { return m_cutoff; }
00110     const float intercept() const { return m_intercept; }
00111 
00112     virtual bool checkIntersect(const Segment &) const;
00113     virtual void shade(Surface &) const;
00114 };
00115 
00116 } // namespace Mercator
00117 
00118 #endif // MERCATOR_FILL_GRASS_SHADER_H