1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
13#ifndef OSGUTIL_HALFWAYMAPGENERATOR_
14#define OSGUTIL_HALFWAYMAPGENERATOR_
16#include <osgUtil/Export>
18#include <osgUtil/CubeMapGenerator>
23 /** This cube map generator produces an Half-way vector map, useful for
24 * hardware-based specular lighting effects.
25 * It computes: C = normalize(R - L), where C is the resulting color,
26 * R is the reflection vector and L is the light direction.
28 class OSGUTIL_EXPORT HalfWayMapGenerator: public CubeMapGenerator {
30 HalfWayMapGenerator(const osg::Vec3 &light_direction, int texture_size = 64);
31 HalfWayMapGenerator(const HalfWayMapGenerator ©, const osg::CopyOp ©op);
34 virtual ~HalfWayMapGenerator() {}
35 HalfWayMapGenerator &operator=(const HalfWayMapGenerator &) { return *this; }
37 inline virtual osg::Vec4 compute_color(const osg::Vec3 &R) const;
45 inline osg::Vec4 HalfWayMapGenerator::compute_color(const osg::Vec3 &R) const
47 const osg::Vec3 V = (R / R.length()) - ldir_;
48 return vector_to_color(V / V.length());