]> git.mxchange.org Git - simgear.git/blob - simgear/scene/tgdb/pt_lights.hxx
Use Effect to implement point lights
[simgear.git] / simgear / scene / tgdb / pt_lights.hxx
1 // pt_lights.hxx -- build a 'directional' light on the fly
2 //
3 // Written by Curtis Olson, started March 2002.
4 //
5 // Copyright (C) 2002  Curtis L. Olson  - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23
24 #ifndef _SG_PT_LIGHTS_HXX
25 #define _SG_PT_LIGHTS_HXX
26
27
28 #ifndef __cplusplus
29 # error This library requires C++
30 #endif
31
32 #include <simgear/compiler.h>
33
34 #include <string>
35 #include <vector>               // STL
36
37 #include <osg/Drawable>
38 #include <osg/Node>
39 #include <osg/Point>
40
41 #include <simgear/math/sg_types.hxx>
42 #include <simgear/scene/material/matlib.hxx>
43 #include <simgear/scene/util/SGSceneFeatures.hxx>
44
45 #include "SGLightBin.hxx"
46 #include "SGDirectionalLightBin.hxx"
47
48 namespace simgear
49 {
50 class Effect;
51 }
52
53 // Specify the way we want to draw directional point lights (assuming the
54 // appropriate extensions are available.)
55
56 inline void SGConfigureDirectionalLights( bool use_point_sprites,
57                                    bool enhanced_lighting,
58                                    bool distance_attenuation ) {
59   static SGSceneFeatures* sceneFeatures = SGSceneFeatures::instance();
60   sceneFeatures->setEnablePointSpriteLights(use_point_sprites);
61   sceneFeatures->setEnableDistanceAttenuationLights(distance_attenuation);
62 }
63
64 class SGLightFactory {
65 public:
66
67   static osg::Drawable*
68   getLightDrawable(const SGLightBin::Light& light);
69
70   static osg::Drawable*
71   getLightDrawable(const SGDirectionalLightBin::Light& light);
72
73   /**
74    * Return a drawable for a very simple point light that isn't
75    * distance scaled.
76    */
77   static osg::Drawable*
78   getLights(const SGLightBin& lights, unsigned inc = 1, float alphaOff = 0);
79
80   static osg::Drawable*
81   getLights(const SGDirectionalLightBin& lights);
82
83   static osg::Drawable*
84   getVasi(const SGVec3f& up, const SGDirectionalLightBin& lights,
85           const SGVec4f& red, const SGVec4f& white);
86
87   static osg::Node*
88   getSequenced(const SGDirectionalLightBin& lights);
89
90   static osg::Node*
91   getOdal(const SGLightBin& lights);
92 };
93
94 simgear::Effect* getLightEffect(float size, const osg::Vec3& attenuation,
95                                 float minSize, float maxSize, bool directional);
96 #endif // _SG_PT_LIGHTS_HXX