2003-09-02 05:53:53 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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
|
|
|
|
{
|
|
|
|
|
2003-11-28 06:06:11 +08:00
|
|
|
/**
|
2003-09-09 19:54:05 +08:00
|
|
|
This effect makes surfaces appear bumpy. Children nodes must use two textures,
|
2003-09-02 05:53:53 +08:00
|
|
|
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
|
2003-09-09 19:54:05 +08:00
|
|
|
can be done quickly by calling BumpMapping::prepareChildren(). Note that both
|
2003-09-02 05:53:53 +08:00
|
|
|
diffuse and normal map textures must have corresponding UV maps defined in
|
|
|
|
Geometry objects.
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
class OSGFX_EXPORT BumpMapping: public Effect {
|
|
|
|
public:
|
|
|
|
BumpMapping();
|
|
|
|
BumpMapping(const BumpMapping ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY);
|
|
|
|
|
|
|
|
META_Effect(osgFX, BumpMapping,
|
|
|
|
|
|
|
|
"Bump Mapping",
|
|
|
|
|
2003-09-09 19:54:05 +08:00
|
|
|
"This effect makes surfaces appear bumpy. Children nodes must use two textures, "
|
2003-09-02 05:53:53 +08:00
|
|
|
"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 "
|
2003-09-09 19:54:05 +08:00
|
|
|
"can be done quickly by calling BumpMapping::prepareChildren(). Note that both "
|
2003-09-02 05:53:53 +08:00
|
|
|
"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");
|
|
|
|
|
|
|
|
|
|
|
|
/** get the OpenGL light number */
|
|
|
|
inline int getLightNumber() const;
|
|
|
|
|
|
|
|
/** set the OpenGL light number that will be used in lighting computations */
|
|
|
|
inline void setLightNumber(int n);
|
|
|
|
|
|
|
|
/** get the texture unit that contains diffuse color texture. Default is 1 */
|
|
|
|
inline int getDiffuseTextureUnit() const;
|
|
|
|
|
|
|
|
/** set the texture unit that contains diffuse color texture. Default is 1 */
|
|
|
|
inline void setDiffuseTextureUnit(int n);
|
|
|
|
|
|
|
|
/** get the texture unit that contains normal map texture. Default is 0 */
|
|
|
|
inline int getNormalMapTextureUnit() const;
|
|
|
|
|
|
|
|
/** set the texture unit that contains normal map texture. Default is 0 */
|
|
|
|
inline void setNormalMapTextureUnit(int n);
|
|
|
|
|
2003-09-09 19:54:05 +08:00
|
|
|
/** get the diffuse color texture that overrides children's texture */
|
2003-09-02 05:53:53 +08:00
|
|
|
inline osg::Texture2D *getOverrideDiffuseTexture();
|
|
|
|
|
2003-09-09 19:54:05 +08:00
|
|
|
/** get the const diffuse color texture that overrides children's texture */
|
2003-09-02 05:53:53 +08:00
|
|
|
inline const osg::Texture2D *getOverrideDiffuseTexture() const;
|
|
|
|
|
2003-09-09 19:54:05 +08:00
|
|
|
/** set the diffuse color texture that overrides children's texture */
|
2003-09-02 05:53:53 +08:00
|
|
|
inline void setOverrideDiffuseTexture(osg::Texture2D *texture);
|
|
|
|
|
2003-09-09 19:54:05 +08:00
|
|
|
/** get the normal map texture that overrides children's texture */
|
2003-09-02 05:53:53 +08:00
|
|
|
inline osg::Texture2D *getOverrideNormalMapTexture();
|
|
|
|
|
2003-09-09 19:54:05 +08:00
|
|
|
/** get the const normal map texture that overrides children's texture */
|
2003-09-02 05:53:53 +08:00
|
|
|
inline const osg::Texture2D *getOverrideNormalMapTexture() const;
|
|
|
|
|
2003-09-09 19:54:05 +08:00
|
|
|
/** set the normal map texture that overrides children's texture */
|
2003-09-02 05:53:53 +08:00
|
|
|
inline void setOverrideNormalMapTexture(osg::Texture2D *texture);
|
|
|
|
|
|
|
|
/**
|
|
|
|
prepare a Geometry for bump lighting. Tangent-space basis vectors are
|
|
|
|
generated and attached to the geometry as vertex attribute arrays.
|
|
|
|
*/
|
|
|
|
void prepareGeometry(osg::Geometry *geo);
|
|
|
|
|
|
|
|
/** prepare a Node for bump lighting, calling prepareGeometry() for each Geometry */
|
|
|
|
void prepareNode(osg::Node *node);
|
|
|
|
|
2003-09-09 19:54:05 +08:00
|
|
|
/** prepare children for bump lighting. Actually calls prepareNode() for each child */
|
|
|
|
void prepareChildren();
|
2003-09-02 05:53:53 +08:00
|
|
|
|
|
|
|
/** set up a demo environment with predefined diffuse and normal maps, as well as texture coordinates */
|
|
|
|
void setUpDemo();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~BumpMapping() {}
|
|
|
|
BumpMapping &operator=(const BumpMapping &) { return *this; }
|
|
|
|
|
|
|
|
bool define_techniques();
|
|
|
|
|
|
|
|
private:
|
|
|
|
int lightnum_;
|
2003-11-28 06:06:11 +08:00
|
|
|
int diffuseunit_;
|
|
|
|
int normalunit_;
|
|
|
|
osg::ref_ptr<osg::Texture2D> diffuse_tex_;
|
|
|
|
osg::ref_ptr<osg::Texture2D> normal_tex_;
|
2003-09-02 05:53:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// INLINE METHODS
|
|
|
|
|
|
|
|
inline int BumpMapping::getLightNumber() const
|
|
|
|
{
|
|
|
|
return lightnum_;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void BumpMapping::setLightNumber(int n)
|
|
|
|
{
|
|
|
|
lightnum_ = n;
|
|
|
|
dirtyTechniques();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int BumpMapping::getDiffuseTextureUnit() const
|
|
|
|
{
|
2003-11-28 06:06:11 +08:00
|
|
|
return diffuseunit_;
|
2003-09-02 05:53:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void BumpMapping::setDiffuseTextureUnit(int n)
|
|
|
|
{
|
2003-11-28 06:06:11 +08:00
|
|
|
diffuseunit_ = n;
|
|
|
|
dirtyTechniques();
|
2003-09-02 05:53:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline int BumpMapping::getNormalMapTextureUnit() const
|
|
|
|
{
|
2003-11-28 06:06:11 +08:00
|
|
|
return normalunit_;
|
2003-09-02 05:53:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void BumpMapping::setNormalMapTextureUnit(int n)
|
|
|
|
{
|
2003-11-28 06:06:11 +08:00
|
|
|
normalunit_ = n;
|
|
|
|
dirtyTechniques();
|
2003-09-02 05:53:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline osg::Texture2D *BumpMapping::getOverrideDiffuseTexture()
|
|
|
|
{
|
2003-11-28 06:06:11 +08:00
|
|
|
return diffuse_tex_.get();
|
2003-09-02 05:53:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const osg::Texture2D *BumpMapping::getOverrideDiffuseTexture() const
|
|
|
|
{
|
2003-11-28 06:06:11 +08:00
|
|
|
return diffuse_tex_.get();
|
2003-09-02 05:53:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void BumpMapping::setOverrideDiffuseTexture(osg::Texture2D *texture)
|
|
|
|
{
|
2003-11-28 06:06:11 +08:00
|
|
|
diffuse_tex_ = texture;
|
|
|
|
dirtyTechniques();
|
2003-09-02 05:53:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline osg::Texture2D *BumpMapping::getOverrideNormalMapTexture()
|
|
|
|
{
|
2003-11-28 06:06:11 +08:00
|
|
|
return normal_tex_.get();
|
2003-09-02 05:53:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const osg::Texture2D *BumpMapping::getOverrideNormalMapTexture() const
|
|
|
|
{
|
2003-11-28 06:06:11 +08:00
|
|
|
return normal_tex_.get();
|
2003-09-02 05:53:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void BumpMapping::setOverrideNormalMapTexture(osg::Texture2D *texture)
|
|
|
|
{
|
2003-11-28 06:06:11 +08:00
|
|
|
normal_tex_ = texture;
|
|
|
|
dirtyTechniques();
|
2003-09-02 05:53:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|