SpecularHighlights 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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_SPECULARHIGHLIGHTS_
  15. #define OSGFX_SPECULARHIGHLIGHTS_
  16. #include <osgFX/Export>
  17. #include <osgFX/Effect>
  18. namespace osgFX
  19. {
  20. /**
  21. This effect applies additive specular highlights at fragment level (instead
  22. of OpenGL's vertex-level lighting) by using a cube map and reflective texgen.
  23. A texture matrix is computed to rotate the cube map automatically; this makes
  24. the specular effect consistent with respect to view direction and light position.
  25. The user can choose which light should be used to compute the texture matrix.
  26. This effect requires the GL_ARB_texture_env_add extension and one of the cube map
  27. extensions (GL_EXT_texture_cube_map, GL_ARB_texture_cube_map or OpenGL v1.3).
  28. */
  29. class OSGFX_EXPORT SpecularHighlights: public Effect {
  30. public:
  31. SpecularHighlights();
  32. SpecularHighlights(const SpecularHighlights& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
  33. META_Effect(osgFX, SpecularHighlights,
  34. "Specular Highlights",
  35. "This effect applies additive specular highlights at fragment level (instead "
  36. "of OpenGL's vertex-level lighting) by using a cube map and reflective texgen. "
  37. "A texture matrix is computed to rotate the cube map automatically; this makes "
  38. "the specular effect consistent with respect to view direction and light position. "
  39. "The user can choose which light should be used to compute the texture matrix.\n"
  40. "This effect requires the GL_ARB_texture_env_add extension and one of the cube map "
  41. "extensions (GL_EXT_texture_cube_map, GL_ARB_texture_cube_map or OpenGL v1.3).",
  42. "Marco Jez");
  43. /** get the OpenGL light number */
  44. inline int getLightNumber() const;
  45. /** set the OpenGL light number that will be used in lighting computations */
  46. inline void setLightNumber(int n);
  47. /** get the texture unit number */
  48. inline int getTextureUnit() const;
  49. /** set the texture unit that will be used to apply the cube map */
  50. inline void setTextureUnit(int n);
  51. /** get the specular color */
  52. inline const osg::Vec4& getSpecularColor() const;
  53. /** set the specular color */
  54. inline void setSpecularColor(const osg::Vec4& color);
  55. /** get the specular exponent */
  56. inline float getSpecularExponent() const;
  57. /** set the specular exponent */
  58. inline void setSpecularExponent(float e);
  59. protected:
  60. virtual ~SpecularHighlights() {}
  61. SpecularHighlights& operator=(const SpecularHighlights&) { return *this; }
  62. bool define_techniques();
  63. private:
  64. int _lightnum;
  65. int _unit;
  66. osg::Vec4 _color;
  67. float _sexp;
  68. };
  69. // INLINE METHODS
  70. inline int SpecularHighlights::getLightNumber() const
  71. {
  72. return _lightnum;
  73. }
  74. inline void SpecularHighlights::setLightNumber(int n)
  75. {
  76. _lightnum = n;
  77. dirtyTechniques();
  78. }
  79. inline int SpecularHighlights::getTextureUnit() const
  80. {
  81. return _unit;
  82. }
  83. inline void SpecularHighlights::setTextureUnit(int n)
  84. {
  85. _unit = n;
  86. dirtyTechniques();
  87. }
  88. inline const osg::Vec4& SpecularHighlights::getSpecularColor() const
  89. {
  90. return _color;
  91. }
  92. inline void SpecularHighlights::setSpecularColor(const osg::Vec4& color)
  93. {
  94. _color = color;
  95. dirtyTechniques();
  96. }
  97. inline float SpecularHighlights::getSpecularExponent() const
  98. {
  99. return _sexp;
  100. }
  101. inline void SpecularHighlights::setSpecularExponent(float e)
  102. {
  103. _sexp = e;
  104. dirtyTechniques();
  105. }
  106. }
  107. #endif