HalfWayMapGenerator 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_HALFWAYMAPGENERATOR_
  14. #define OSGUTIL_HALFWAYMAPGENERATOR_
  15. #include <osgUtil/Export>
  16. #include <osgUtil/CubeMapGenerator>
  17. namespace osgUtil
  18. {
  19. /** This cube map generator produces an Half-way vector map, useful for
  20. * hardware-based specular lighting effects.
  21. * It computes: C = normalize(R - L), where C is the resulting color,
  22. * R is the reflection vector and L is the light direction.
  23. */
  24. class OSGUTIL_EXPORT HalfWayMapGenerator: public CubeMapGenerator {
  25. public:
  26. HalfWayMapGenerator(const osg::Vec3 &light_direction, int texture_size = 64);
  27. HalfWayMapGenerator(const HalfWayMapGenerator &copy, const osg::CopyOp &copyop);
  28. protected:
  29. virtual ~HalfWayMapGenerator() {}
  30. HalfWayMapGenerator &operator=(const HalfWayMapGenerator &) { return *this; }
  31. inline virtual osg::Vec4 compute_color(const osg::Vec3 &R) const;
  32. private:
  33. osg::Vec3 ldir_;
  34. };
  35. // INLINE METHODS
  36. inline osg::Vec4 HalfWayMapGenerator::compute_color(const osg::Vec3 &R) const
  37. {
  38. const osg::Vec3 V = (R / R.length()) - ldir_;
  39. return vector_to_color(V / V.length());
  40. }
  41. }
  42. #endif