HighlightMapGenerator 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSGUTIL_HIGHLIGHTMAPGENERATOR_
  14. #define OSGUTIL_HIGHLIGHTMAPGENERATOR_
  15. #include <osgUtil/Export>
  16. #include <osgUtil/CubeMapGenerator>
  17. namespace osgUtil
  18. {
  19. /** This cube map generator produces a specular highlight map.
  20. * The vector-color association is: C = (R dot (-L)) ^ n, where C is the
  21. * resulting color, R is the reflection vector, L is the light direction
  22. * and n is the specular exponent.
  23. */
  24. class OSGUTIL_EXPORT HighlightMapGenerator: public CubeMapGenerator {
  25. public:
  26. HighlightMapGenerator(
  27. const osg::Vec3 &light_direction,
  28. const osg::Vec4 &light_color,
  29. float specular_exponent,
  30. int texture_size = 64);
  31. HighlightMapGenerator(const HighlightMapGenerator &copy, const osg::CopyOp &copyop = osg::CopyOp::SHALLOW_COPY);
  32. protected:
  33. virtual ~HighlightMapGenerator() {}
  34. HighlightMapGenerator &operator=(const HighlightMapGenerator &) { return *this; }
  35. inline virtual osg::Vec4 compute_color(const osg::Vec3 &R) const;
  36. private:
  37. osg::Vec3 ldir_;
  38. osg::Vec4 lcol_;
  39. float sexp_;
  40. };
  41. // INLINE METHODS
  42. inline osg::Vec4 HighlightMapGenerator::compute_color(const osg::Vec3 &R) const
  43. {
  44. float v = -ldir_ * (R / R.length());
  45. if (v < 0) v = 0;
  46. osg::Vec4 color(lcol_ * powf(v, sexp_));
  47. color.w() = 1;
  48. return color;
  49. }
  50. }
  51. #endif