2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-08-27 06:09:15 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2003-08-27 06:09:15 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-08-27 06:09:15 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-08-27 06:09:15 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
//osgFX - Copyright (C) 2003 Marco Jez
|
|
|
|
|
|
|
|
#ifndef OSGFX_CARTOON_
|
|
|
|
#define OSGFX_CARTOON_
|
|
|
|
|
|
|
|
#include <osgFX/Export>
|
|
|
|
#include <osgFX/Effect>
|
|
|
|
|
|
|
|
#include <osg/Material>
|
|
|
|
#include <osg/LineWidth>
|
|
|
|
|
|
|
|
namespace osgFX
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2012-03-22 01:36:20 +08:00
|
|
|
This effect implements a technique called 'Cel-Shading' to produce a
|
|
|
|
cartoon-style (non photorealistic) rendering. Two passes are required:
|
|
|
|
the first one draws solid surfaces, the second one draws the outlines.
|
|
|
|
A vertex program is used to setup texture coordinates for a sharp lighting
|
2003-08-27 06:09:15 +08:00
|
|
|
texture on unit 0 which is generated on-the-fly.
|
|
|
|
This effect requires the ARB_vertex_program extension.
|
|
|
|
*/
|
|
|
|
class OSGFX_EXPORT Cartoon: public Effect {
|
|
|
|
public:
|
|
|
|
Cartoon();
|
2005-04-29 14:32:13 +08:00
|
|
|
Cartoon(const Cartoon& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
2003-08-27 06:09:15 +08:00
|
|
|
|
2018-04-21 00:18:22 +08:00
|
|
|
// effect class information
|
2003-08-27 06:09:15 +08:00
|
|
|
META_Effect(
|
2012-03-22 01:36:20 +08:00
|
|
|
osgFX,
|
|
|
|
Cartoon,
|
|
|
|
|
|
|
|
"Cartoon",
|
|
|
|
|
2003-08-27 06:09:15 +08:00
|
|
|
"This effect implements a technique called 'Cel-Shading' to produce a "
|
|
|
|
"cartoon-style (non photorealistic) rendering. Two passes are required: "
|
|
|
|
"the first one draws solid surfaces, the second one draws the outlines. "
|
|
|
|
"A vertex program is used to setup texture coordinates for a sharp lighting "
|
|
|
|
"texture on unit 0 which is generated on-the-fly.\n"
|
2003-10-05 19:42:26 +08:00
|
|
|
"This effect requires the ARB_vertex_program extension "
|
|
|
|
"or OpenGL Shading Language.",
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-10-05 19:42:26 +08:00
|
|
|
"Marco Jez; OGLSL port by Mike Weiblen");
|
2003-08-27 06:09:15 +08:00
|
|
|
|
|
|
|
/** get the outline color */
|
2005-04-29 14:32:13 +08:00
|
|
|
inline const osg::Vec4& getOutlineColor() const;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-08-27 06:09:15 +08:00
|
|
|
/** set the outline color */
|
2005-04-29 14:32:13 +08:00
|
|
|
inline void setOutlineColor(const osg::Vec4& color);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-08-27 06:09:15 +08:00
|
|
|
/** get the outline line width */
|
|
|
|
inline float getOutlineLineWidth() const;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-08-27 06:09:15 +08:00
|
|
|
/** set the outline line width */
|
|
|
|
inline void setOutlineLineWidth(float w);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-08-27 06:09:15 +08:00
|
|
|
/** get the OpenGL light number */
|
|
|
|
inline int getLightNumber() const;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-08-27 06:09:15 +08:00
|
|
|
/** set the OpenGL light number that will be used in lighting computations */
|
|
|
|
inline void setLightNumber(int n);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~Cartoon() {}
|
2005-04-29 14:32:13 +08:00
|
|
|
Cartoon& operator=(const Cartoon&) { return *this; }
|
2003-08-27 06:09:15 +08:00
|
|
|
|
|
|
|
bool define_techniques();
|
|
|
|
|
|
|
|
private:
|
2005-04-29 14:32:13 +08:00
|
|
|
osg::ref_ptr<osg::Material> _wf_mat;
|
|
|
|
osg::ref_ptr<osg::LineWidth> _wf_lw;
|
|
|
|
int _lightnum;
|
2003-08-27 06:09:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// INLINE METHODS
|
|
|
|
|
2005-04-29 14:32:13 +08:00
|
|
|
inline const osg::Vec4& Cartoon::getOutlineColor() const
|
2003-08-27 06:09:15 +08:00
|
|
|
{
|
2005-04-29 14:32:13 +08:00
|
|
|
return _wf_mat->getEmission(osg::Material::FRONT_AND_BACK);
|
2003-08-27 06:09:15 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 14:32:13 +08:00
|
|
|
inline void Cartoon::setOutlineColor(const osg::Vec4& color)
|
2003-08-27 06:09:15 +08:00
|
|
|
{
|
2005-04-29 14:32:13 +08:00
|
|
|
_wf_mat->setEmission(osg::Material::FRONT_AND_BACK, color);
|
2003-08-27 06:09:15 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-08-27 06:09:15 +08:00
|
|
|
inline float Cartoon::getOutlineLineWidth() const
|
|
|
|
{
|
2005-04-29 14:32:13 +08:00
|
|
|
return _wf_lw->getWidth();
|
2003-08-27 06:09:15 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-08-27 06:09:15 +08:00
|
|
|
inline void Cartoon::setOutlineLineWidth(float w)
|
|
|
|
{
|
2005-04-29 14:32:13 +08:00
|
|
|
_wf_lw->setWidth(w);
|
2003-08-27 06:09:15 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-08-27 06:09:15 +08:00
|
|
|
inline int Cartoon::getLightNumber() const
|
|
|
|
{
|
2005-04-29 14:32:13 +08:00
|
|
|
return _lightnum;
|
2003-08-27 06:09:15 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-08-27 06:09:15 +08:00
|
|
|
inline void Cartoon::setLightNumber(int n)
|
|
|
|
{
|
2005-04-29 14:32:13 +08:00
|
|
|
_lightnum = n;
|
2003-08-27 06:09:15 +08:00
|
|
|
dirtyTechniques();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|