AnisotropicLighting 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. //osgFX - Copyright (C) 2003 Marco Jez
  14. #ifndef OSGFX_ANISOTROPICLIGHTING_
  15. #define OSGFX_ANISOTROPICLIGHTING_
  16. #include <osgFX/Export>
  17. #include <osgFX/Effect>
  18. #include <osg/ref_ptr>
  19. #include <osg/Texture2D>
  20. namespace osgFX
  21. {
  22. /**
  23. This single-pass effect implements a sort of anisotropic
  24. lighting that replaces the standard OpenGL lighting model.
  25. The final color of vertices is not computed directly, it is
  26. the result of a texture lookup on a user-supplied lighting
  27. image map. A vertex program is used to compute the s and t
  28. texture coordinates as follows: s = (N dot H) ; t = (N dot L)
  29. where N is the vertex normal, L is the light-to-vertex vector,
  30. H is the half-way vector. This is a good example of how you
  31. can use the State::getInitialViewMatrix() method to retrieve
  32. the view matrix and perform view-dependant effects without
  33. fakes of any kind.
  34. This effect requires the ARB_vertex_program extension.
  35. */
  36. class OSGFX_EXPORT AnisotropicLighting: public Effect {
  37. public:
  38. AnisotropicLighting();
  39. AnisotropicLighting(const AnisotropicLighting& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
  40. META_Effect(osgFX, AnisotropicLighting,
  41. "Anisotropic Lighting",
  42. "This single-pass effect implements a sort of anisotropic "
  43. "lighting that replaces the standard OpenGL lighting model.\n"
  44. "The final color of vertices is not computed directly, it is "
  45. "the result of a texture lookup on a user-supplied lighting "
  46. "image map. A vertex program is used to compute the s and t "
  47. "texture coordinates as follows: s = (N dot H) ; t = (N dot L) "
  48. "where N is the vertex normal, L is the light-to-vertex vector, "
  49. "H is the half-way vector. This is a good example of how you "
  50. "can use the State::getInitialViewMatrix() method to retrieve "
  51. "the view matrix and perform view-dependant effects without "
  52. "fakes of any kind.\n"
  53. "This effect requires the ARB_vertex_program extension.",
  54. "Marco Jez");
  55. /** get the lighting map */
  56. inline osg::Image* getLightingMap();
  57. /** get the const lighting map */
  58. inline const osg::Image* getLightingMap() const;
  59. /** set the lighting map */
  60. inline void setLightingMap(osg::Image* image);
  61. /** get the OpenGL light number */
  62. inline int getLightNumber() const;
  63. /** set the OpenGL light number that will be used in lighting computations */
  64. inline void setLightNumber(int n);
  65. protected:
  66. virtual ~AnisotropicLighting() {}
  67. AnisotropicLighting& operator=(const AnisotropicLighting&) { return *this; }
  68. bool define_techniques();
  69. private:
  70. int _lightnum;
  71. osg::ref_ptr<osg::Texture2D> _texture;
  72. };
  73. // INLINE METHODS
  74. inline osg::Image* AnisotropicLighting::getLightingMap()
  75. {
  76. return _texture->getImage();
  77. }
  78. inline const osg::Image* AnisotropicLighting::getLightingMap() const
  79. {
  80. return _texture->getImage();
  81. }
  82. inline void AnisotropicLighting::setLightingMap(osg::Image* image)
  83. {
  84. _texture->setImage(image);
  85. }
  86. inline int AnisotropicLighting::getLightNumber() const
  87. {
  88. return _lightnum;
  89. }
  90. inline void AnisotropicLighting::setLightNumber(int n)
  91. {
  92. _lightnum = n;
  93. dirtyTechniques();
  94. }
  95. }
  96. #endif