BumpMapping
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgFX - Copyright (C) 2003 Marco Jez
#ifndef OSGFX_BUMPMAPPING_
#define OSGFX_BUMPMAPPING_
#include <osgFX/Export>
#include <osgFX/Effect>
#include <osg/ref_ptr>
#include <osg/Texture2D>
namespace osgFX
{
class OSGFX_EXPORT BumpMapping: public Effect {
public:
BumpMapping();
BumpMapping(const BumpMapping& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
META_Effect(osgFX, BumpMapping,
"Bump Mapping",
"This effect makes surfaces appear bumpy. Children nodes must use two textures, "
"one for diffuse color and one for the normal map (which can be created "
"from a height map with tools like nVIDIA's normal map generator). Furthermore, "
"tangent-space basis vectors must be created and assigned to each Geometry; this "
"can be done quickly by calling BumpMapping::prepareChildren(). Note that both "
"diffuse and normal map textures must have corresponding UV maps defined in "
"Geometry objects.\n"
"This effect defines a preferred technique which uses ARB vertex & fragment "
"programs, and a fallback technique which doesn't use fragment programs. The "
"latter is more limited though since it can't handle ambient and specular "
"components.",
"Marco Jez");
inline int getLightNumber() const;
inline void setLightNumber(int n);
inline int getDiffuseTextureUnit() const;
inline void setDiffuseTextureUnit(int n);
inline int getNormalMapTextureUnit() const;
inline void setNormalMapTextureUnit(int n);
inline osg::Texture2D* getOverrideDiffuseTexture();
inline const osg::Texture2D* getOverrideDiffuseTexture() const;
inline void setOverrideDiffuseTexture(osg::Texture2D* texture);
inline osg::Texture2D* getOverrideNormalMapTexture();
inline const osg::Texture2D* getOverrideNormalMapTexture() const;
inline void setOverrideNormalMapTexture(osg::Texture2D* texture);
void prepareGeometry(osg::Geometry* geo);
void prepareNode(osg::Node* node);
void prepareChildren();
void setUpDemo();
protected:
virtual ~BumpMapping() {}
BumpMapping &operator=(const BumpMapping &) { return *this; }
bool define_techniques();
private:
int _lightnum;
int _diffuse_unit;
int _normal_unit;
osg::ref_ptr<osg::Texture2D> _diffuse_tex;
osg::ref_ptr<osg::Texture2D> _normal_tex;
};
// INLINE METHODS
inline int BumpMapping::getLightNumber() const
{
return _lightnum;
}
inline void BumpMapping::setLightNumber(int n)
{
_lightnum = n;
dirtyTechniques();
}
inline int BumpMapping::getDiffuseTextureUnit() const
{
return _diffuse_unit;
}
inline void BumpMapping::setDiffuseTextureUnit(int n)
{
_diffuse_unit = n;
dirtyTechniques();
}
inline int BumpMapping::getNormalMapTextureUnit() const
{
return _normal_unit;
}
inline void BumpMapping::setNormalMapTextureUnit(int n)
{
_normal_unit = n;
dirtyTechniques();
}
inline osg::Texture2D* BumpMapping::getOverrideDiffuseTexture()
{
return _diffuse_tex.get();
}
inline const osg::Texture2D* BumpMapping::getOverrideDiffuseTexture() const
{
return _diffuse_tex.get();
}
inline void BumpMapping::setOverrideDiffuseTexture(osg::Texture2D* texture)
{
_diffuse_tex = texture;
dirtyTechniques();
}
inline osg::Texture2D* BumpMapping::getOverrideNormalMapTexture()
{
return _normal_tex.get();
}
inline const osg::Texture2D* BumpMapping::getOverrideNormalMapTexture() const
{
return _normal_tex.get();
}
inline void BumpMapping::setOverrideNormalMapTexture(osg::Texture2D* texture)
{
_normal_tex = texture;
dirtyTechniques();
}
}
#endif
Effect
Texture2D
osgFX::BumpMapping::setDiffuseTextureUnit
void setDiffuseTextureUnit(int n)
Definition BumpMapping:147
osgFX::BumpMapping::BumpMapping
BumpMapping(const BumpMapping &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osgFX::BumpMapping::setLightNumber
void setLightNumber(int n)
Definition BumpMapping:136
osgFX::BumpMapping::getDiffuseTextureUnit
int getDiffuseTextureUnit() const
Definition BumpMapping:142
osgFX::BumpMapping::BumpMapping
BumpMapping()
osgFX::BumpMapping::operator=
BumpMapping & operator=(const BumpMapping &)
Definition BumpMapping:117
osgFX::BumpMapping::META_Effect
META_Effect(osgFX, BumpMapping, "Bump Mapping", "This effect makes surfaces appear bumpy. Children nodes must use two textures, " "one for diffuse color and one for the normal map (which can be created " "from a height map with tools like nVIDIA's normal map generator). Furthermore, " "tangent-space basis vectors must be created and assigned to each Geometry; this " "can be done quickly by calling BumpMapping::prepareChildren(). Note that both " "diffuse and normal map textures must have corresponding UV maps defined in " "Geometry objects.\n" "This effect defines a preferred technique which uses ARB vertex & fragment " "programs, and a fallback technique which doesn't use fragment programs. The " "latter is more limited though since it can't handle ambient and specular " "components.", "Marco Jez")
osgFX::BumpMapping::getOverrideNormalMapTexture
osg::Texture2D * getOverrideNormalMapTexture()
Definition BumpMapping:180
osgFX::BumpMapping::prepareChildren
void prepareChildren()
osgFX::BumpMapping::setOverrideNormalMapTexture
void setOverrideNormalMapTexture(osg::Texture2D *texture)
Definition BumpMapping:190
osgFX::BumpMapping::getOverrideDiffuseTexture
osg::Texture2D * getOverrideDiffuseTexture()
Definition BumpMapping:164
osgFX::BumpMapping::setUpDemo
void setUpDemo()
osgFX::BumpMapping::setOverrideDiffuseTexture
void setOverrideDiffuseTexture(osg::Texture2D *texture)
Definition BumpMapping:174
osgFX::BumpMapping::getLightNumber
int getLightNumber() const
Definition BumpMapping:131
osgFX::BumpMapping::~BumpMapping
virtual ~BumpMapping()
Definition BumpMapping:116
osgFX::BumpMapping::define_techniques
bool define_techniques()
osgFX::BumpMapping::setNormalMapTextureUnit
void setNormalMapTextureUnit(int n)
Definition BumpMapping:158
osgFX::BumpMapping::prepareNode
void prepareNode(osg::Node *node)
osgFX::BumpMapping::prepareGeometry
void prepareGeometry(osg::Geometry *geo)
osgFX::BumpMapping::getNormalMapTextureUnit
int getNormalMapTextureUnit() const
Definition BumpMapping:153
osgFX::Effect::Effect
Effect()
osgFX::Effect::dirtyTechniques
void dirtyTechniques()
Definition Effect:207
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Geometry
Definition Geometry:31
osg::Node
Definition Node:72
osg::Texture2D
Definition Texture2D:25
osg::ref_ptr
Definition ref_ptr:32
osgFX
Definition AnisotropicLighting:25
Export
OSGFX_EXPORT
#define OSGFX_EXPORT
Definition osgFX/Export:27
ref_ptr