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//osgFX - Copyright (C) 2003 Marco Jez
15#ifndef OSGFX_ANISOTROPICLIGHTING_
16#define OSGFX_ANISOTROPICLIGHTING_
18#include <osgFX/Export>
19#include <osgFX/Effect>
22#include <osg/Texture2D>
28 This single-pass effect implements a sort of anisotropic
29 lighting that replaces the standard OpenGL lighting model.
30 The final color of vertices is not computed directly, it is
31 the result of a texture lookup on a user-supplied lighting
32 image map. A vertex program is used to compute the s and t
33 texture coordinates as follows: s = (N dot H) ; t = (N dot L)
34 where N is the vertex normal, L is the light-to-vertex vector,
35 H is the half-way vector. This is a good example of how you
36 can use the State::getInitialViewMatrix() method to retrieve
37 the view matrix and perform view-dependant effects without
39 This effect requires the ARB_vertex_program extension.
41 class OSGFX_EXPORT AnisotropicLighting: public Effect {
43 AnisotropicLighting();
44 AnisotropicLighting(const AnisotropicLighting& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
46 META_Effect(osgFX, AnisotropicLighting,
48 "Anisotropic Lighting",
50 "This single-pass effect implements a sort of anisotropic "
51 "lighting that replaces the standard OpenGL lighting model.\n"
52 "The final color of vertices is not computed directly, it is "
53 "the result of a texture lookup on a user-supplied lighting "
54 "image map. A vertex program is used to compute the s and t "
55 "texture coordinates as follows: s = (N dot H) ; t = (N dot L) "
56 "where N is the vertex normal, L is the light-to-vertex vector, "
57 "H is the half-way vector. This is a good example of how you "
58 "can use the State::getInitialViewMatrix() method to retrieve "
59 "the view matrix and perform view-dependant effects without "
60 "fakes of any kind.\n"
61 "This effect requires the ARB_vertex_program extension.",
66 /** get the lighting map */
67 inline osg::Image* getLightingMap();
69 /** get the const lighting map */
70 inline const osg::Image* getLightingMap() const;
72 /** set the lighting map */
73 inline void setLightingMap(osg::Image* image);
75 /** get the OpenGL light number */
76 inline int getLightNumber() const;
78 /** set the OpenGL light number that will be used in lighting computations */
79 inline void setLightNumber(int n);
82 virtual ~AnisotropicLighting() {}
83 AnisotropicLighting& operator=(const AnisotropicLighting&) { return *this; }
85 bool define_techniques();
89 osg::ref_ptr<osg::Texture2D> _texture;
94 inline osg::Image* AnisotropicLighting::getLightingMap()
96 return _texture->getImage();
99 inline const osg::Image* AnisotropicLighting::getLightingMap() const
101 return _texture->getImage();
104 inline void AnisotropicLighting::setLightingMap(osg::Image* image)
106 _texture->setImage(image);
109 inline int AnisotropicLighting::getLightNumber() const
114 inline void AnisotropicLighting::setLightNumber(int n)