42 lines
1.1 KiB
Plaintext
42 lines
1.1 KiB
Plaintext
#ifndef OSGUTIL_HALFWAYMAPGENERATOR_
|
|
#define OSGUTIL_HALFWAYMAPGENERATOR_
|
|
|
|
#include <osgUtil/Export>
|
|
|
|
#include <osgUtil/CubeMapGenerator>
|
|
|
|
namespace osgUtil
|
|
{
|
|
|
|
/** This cube map generator produces an Half-way vector map, useful for
|
|
hardware-based specular lighting effects.
|
|
It computes: C = normalize(R - L), where C is the resulting color,
|
|
R is the reflection vector and L is the light direction.
|
|
*/
|
|
class OSGUTIL_EXPORT HalfWayMapGenerator: public CubeMapGenerator {
|
|
public:
|
|
HalfWayMapGenerator(const osg::Vec3 &light_direction, int texture_size = 64);
|
|
HalfWayMapGenerator(const HalfWayMapGenerator ©, const osg::CopyOp ©op);
|
|
|
|
protected:
|
|
virtual ~HalfWayMapGenerator() {}
|
|
HalfWayMapGenerator &operator=(const HalfWayMapGenerator &) { return *this; }
|
|
|
|
inline virtual osg::Vec4 compute_color(const osg::Vec3 &R) const;
|
|
|
|
private:
|
|
osg::Vec3 ldir_;
|
|
};
|
|
|
|
// INLINE METHODS
|
|
|
|
inline osg::Vec4 HalfWayMapGenerator::compute_color(const osg::Vec3 &R) const
|
|
{
|
|
const osg::Vec3 V = (R / R.length()) - ldir_;
|
|
return vector_to_color(V / V.length());
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|