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_ANISOTROPICLIGHTING_
|
|
|
|
#define OSGFX_ANISOTROPICLIGHTING_
|
|
|
|
|
|
|
|
#include <osgFX/Export>
|
|
|
|
#include <osgFX/Effect>
|
|
|
|
|
|
|
|
#include <osg/ref_ptr>
|
|
|
|
#include <osg/Texture2D>
|
|
|
|
|
|
|
|
namespace osgFX
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2012-03-22 01:36:20 +08:00
|
|
|
This single-pass effect implements a sort of anisotropic
|
2003-08-27 06:09:15 +08:00
|
|
|
lighting that replaces the standard OpenGL lighting model.
|
2012-03-22 01:36:20 +08:00
|
|
|
The final color of vertices is not computed directly, it is
|
|
|
|
the result of a texture lookup on a user-supplied lighting
|
|
|
|
image map. A vertex program is used to compute the s and t
|
|
|
|
texture coordinates as follows: s = (N dot H) ; t = (N dot L)
|
|
|
|
where N is the vertex normal, L is the light-to-vertex vector,
|
|
|
|
H is the half-way vector. This is a good example of how you
|
|
|
|
can use the State::getInitialViewMatrix() method to retrieve
|
|
|
|
the view matrix and perform view-dependant effects without
|
2003-08-27 06:09:15 +08:00
|
|
|
fakes of any kind.
|
|
|
|
This effect requires the ARB_vertex_program extension.
|
|
|
|
*/
|
|
|
|
class OSGFX_EXPORT AnisotropicLighting: public Effect {
|
|
|
|
public:
|
|
|
|
AnisotropicLighting();
|
2005-04-29 14:32:13 +08:00
|
|
|
AnisotropicLighting(const AnisotropicLighting& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
2003-08-27 06:09:15 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
META_Effect(osgFX, AnisotropicLighting,
|
|
|
|
|
|
|
|
"Anisotropic Lighting",
|
|
|
|
|
2003-08-27 06:09:15 +08:00
|
|
|
"This single-pass effect implements a sort of anisotropic "
|
|
|
|
"lighting that replaces the standard OpenGL lighting model.\n"
|
|
|
|
"The final color of vertices is not computed directly, it is "
|
|
|
|
"the result of a texture lookup on a user-supplied lighting "
|
|
|
|
"image map. A vertex program is used to compute the s and t "
|
|
|
|
"texture coordinates as follows: s = (N dot H) ; t = (N dot L) "
|
|
|
|
"where N is the vertex normal, L is the light-to-vertex vector, "
|
|
|
|
"H is the half-way vector. This is a good example of how you "
|
|
|
|
"can use the State::getInitialViewMatrix() method to retrieve "
|
|
|
|
"the view matrix and perform view-dependant effects without "
|
|
|
|
"fakes of any kind.\n"
|
2012-03-22 01:36:20 +08:00
|
|
|
"This effect requires the ARB_vertex_program extension.",
|
|
|
|
|
2003-08-27 06:09:15 +08:00
|
|
|
"Marco Jez");
|
2012-03-22 01:36:20 +08:00
|
|
|
|
|
|
|
|
2003-08-27 06:09:15 +08:00
|
|
|
/** get the lighting map */
|
2005-04-29 14:32:13 +08:00
|
|
|
inline osg::Image* getLightingMap();
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-08-27 06:09:15 +08:00
|
|
|
/** get the const lighting map */
|
2005-04-29 14:32:13 +08:00
|
|
|
inline const osg::Image* getLightingMap() const;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-08-27 06:09:15 +08:00
|
|
|
/** set the lighting map */
|
2005-04-29 14:32:13 +08:00
|
|
|
inline void setLightingMap(osg::Image* image);
|
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 ~AnisotropicLighting() {}
|
2005-04-29 14:32:13 +08:00
|
|
|
AnisotropicLighting& operator=(const AnisotropicLighting&) { return *this; }
|
2003-08-27 06:09:15 +08:00
|
|
|
|
|
|
|
bool define_techniques();
|
|
|
|
|
|
|
|
private:
|
2005-04-29 14:32:13 +08:00
|
|
|
int _lightnum;
|
|
|
|
osg::ref_ptr<osg::Texture2D> _texture;
|
2003-08-27 06:09:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// INLINE METHODS
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-04-29 14:32:13 +08:00
|
|
|
inline osg::Image* AnisotropicLighting::getLightingMap()
|
2003-08-27 06:09:15 +08:00
|
|
|
{
|
2005-04-29 14:32:13 +08:00
|
|
|
return _texture->getImage();
|
2003-08-27 06:09:15 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-04-29 14:32:13 +08:00
|
|
|
inline const osg::Image* AnisotropicLighting::getLightingMap() const
|
2003-08-27 06:09:15 +08:00
|
|
|
{
|
2005-04-29 14:32:13 +08:00
|
|
|
return _texture->getImage();
|
2003-08-27 06:09:15 +08:00
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-04-29 14:32:13 +08:00
|
|
|
inline void AnisotropicLighting::setLightingMap(osg::Image* image)
|
2003-08-27 06:09:15 +08:00
|
|
|
{
|
2005-04-29 14:32:13 +08:00
|
|
|
_texture->setImage(image);
|
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 AnisotropicLighting::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 AnisotropicLighting::setLightNumber(int n)
|
|
|
|
{
|
2005-04-29 14:32:13 +08:00
|
|
|
_lightnum = n;
|
2003-08-27 06:09:15 +08:00
|
|
|
dirtyTechniques();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|