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 
00042 class GrassShader : public Shader {
00043   private:
00044     float m_lowThreshold;
00045     float m_highThreshold;
00046     float m_cutoff;
00047     float m_intercept;
00048 
00049     ColorT slopeToAlpha(float height, float slope) const;
00050   public:
00051     static const std::string key_lowThreshold;
00052     static const std::string key_highThreshold;
00053     static const std::string key_cutoff;
00054     static const std::string key_intercept;
00055 
00056     static const float default_lowThreshold;
00057     static const float default_highThreshold;
00058     static const float default_cutoff;
00059     static const float default_intercept;
00060 
00061     explicit GrassShader(float lowThreshold = default_lowThreshold,
00062                          float highThreshold = default_highThreshold,
00063                          float cutoff = default_cutoff,
00064                          float intercept = default_intercept);
00065     explicit GrassShader(const Parameters & params);
00066     virtual ~GrassShader();
00067 
00068     const float lowThreshold() const { return m_lowThreshold; }
00069     const float highThreshold() const { return m_highThreshold; }
00070     const float cutoff() const { return m_cutoff; }
00071     const float intercept() const { return m_intercept; }
00072 
00073     virtual bool checkIntersect(const Segment &) const;
00074     virtual void shade(Surface &) const;
00075 };
00076 
00077 } // namespace Mercator
00078 
00079 #endif // MERCATOR_FILL_GRASS_SHADER_H

Generated on Wed Sep 12 22:21:34 2007 for Mercator by  doxygen 1.5.2