Cartoon 3.6 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_CARTOON_
  15. #define OSGFX_CARTOON_
  16. #include <osgFX/Export>
  17. #include <osgFX/Effect>
  18. #include <osg/Material>
  19. #include <osg/LineWidth>
  20. namespace osgFX
  21. {
  22. /**
  23. This effect implements a technique called 'Cel-Shading' to produce a
  24. cartoon-style (non photorealistic) rendering. Two passes are required:
  25. the first one draws solid surfaces, the second one draws the outlines.
  26. A vertex program is used to setup texture coordinates for a sharp lighting
  27. texture on unit 0 which is generated on-the-fly.
  28. This effect requires the ARB_vertex_program extension.
  29. */
  30. class OSGFX_EXPORT Cartoon: public Effect {
  31. public:
  32. Cartoon();
  33. Cartoon(const Cartoon& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
  34. // effect class information
  35. META_Effect(
  36. osgFX,
  37. Cartoon,
  38. "Cartoon",
  39. "This effect implements a technique called 'Cel-Shading' to produce a "
  40. "cartoon-style (non photorealistic) rendering. Two passes are required: "
  41. "the first one draws solid surfaces, the second one draws the outlines. "
  42. "A vertex program is used to setup texture coordinates for a sharp lighting "
  43. "texture on unit 0 which is generated on-the-fly.\n"
  44. "This effect requires the ARB_vertex_program extension "
  45. "or OpenGL Shading Language.",
  46. "Marco Jez; OGLSL port by Mike Weiblen");
  47. /** get the outline color */
  48. inline const osg::Vec4& getOutlineColor() const;
  49. /** set the outline color */
  50. inline void setOutlineColor(const osg::Vec4& color);
  51. /** get the outline line width */
  52. inline float getOutlineLineWidth() const;
  53. /** set the outline line width */
  54. inline void setOutlineLineWidth(float w);
  55. /** get the OpenGL light number */
  56. inline int getLightNumber() const;
  57. /** set the OpenGL light number that will be used in lighting computations */
  58. inline void setLightNumber(int n);
  59. protected:
  60. virtual ~Cartoon() {}
  61. Cartoon& operator=(const Cartoon&) { return *this; }
  62. bool define_techniques();
  63. private:
  64. osg::ref_ptr<osg::Material> _wf_mat;
  65. osg::ref_ptr<osg::LineWidth> _wf_lw;
  66. int _lightnum;
  67. };
  68. // INLINE METHODS
  69. inline const osg::Vec4& Cartoon::getOutlineColor() const
  70. {
  71. return _wf_mat->getEmission(osg::Material::FRONT_AND_BACK);
  72. }
  73. inline void Cartoon::setOutlineColor(const osg::Vec4& color)
  74. {
  75. _wf_mat->setEmission(osg::Material::FRONT_AND_BACK, color);
  76. }
  77. inline float Cartoon::getOutlineLineWidth() const
  78. {
  79. return _wf_lw->getWidth();
  80. }
  81. inline void Cartoon::setOutlineLineWidth(float w)
  82. {
  83. _wf_lw->setWidth(w);
  84. }
  85. inline int Cartoon::getLightNumber() const
  86. {
  87. return _lightnum;
  88. }
  89. inline void Cartoon::setLightNumber(int n)
  90. {
  91. _lightnum = n;
  92. dirtyTechniques();
  93. }
  94. }
  95. #endif