]> git.tdb.fi Git - libs/gl.git/blob - source/materials/lighting.h
92a4bcf8d9478a93074bd318f03c1ad77e905a91
[libs/gl.git] / source / materials / lighting.h
1 #ifndef MSP_GL_LIGHTING_H_
2 #define MSP_GL_LIGHTING_H_
3
4 #include <vector>
5 #include <msp/geometry/angle.h>
6 #include "color.h"
7 #include "programdata.h"
8
9 namespace Msp {
10 namespace GL {
11
12 class Light;
13
14 /**
15 Encapsulates global lighting parameters and any number of individual light
16 sources.
17 */
18 class Lighting
19 {
20 public:
21         class Loader: public DataFile::CollectionObjectLoader<Lighting>
22         {
23         private:
24                 static ActionMap shared_actions;
25
26         public:
27                 Loader(Lighting &);
28                 Loader(Lighting &, Collection &);
29
30         private:
31                 virtual void init_actions();
32
33                 void ambient(float, float, float);
34                 void fog_color(float, float, float);
35                 void fog_density(float);
36                 void fog_half_distance(float);
37                 void horizon_angle(float);
38                 void light(const std::string &);
39                 void light_inline();
40                 void light_inline_index(unsigned);
41                 void sky_color(float, float, float);
42                 void zenith_direction(float, float, float);
43         };
44
45 private:
46         struct AttachedLight
47         {
48                 const Light *light;
49                 mutable unsigned generation;
50
51                 AttachedLight(const Light *l): light(l), generation(0) { }
52         };
53
54         Color ambient;
55         Color sky_color;
56         Vector3 zenith_direction;
57         Geometry::Angle<float> horizon_angle;
58         Color fog_color;
59         float fog_density;
60         std::vector<AttachedLight> lights;
61         mutable ProgramData shdata;
62
63 public:
64         Lighting();
65
66         /** Sets the ambient lighting color.  Affects all surfaces in the scene. */
67         void set_ambient(const Color &);
68
69         const Color &get_ambient() const { return ambient; }
70
71         /** Sets the color of the sky at zenith.  Has no effect without shaders. */
72         DEPRECATED void set_sky_color(const Color &);
73
74         /** Sets the direction of the zenith.  Defaults to positive Z axis.  Has no
75         effect without shaders. */
76         DEPRECATED void set_zenith_direction(const Vector3 &);
77
78         /** Sets the angle where skylight cuts off, counted from the true horizon.
79         Has no effect without shaders. */
80         DEPRECATED void set_horizon_angle(const Geometry::Angle<float> &);
81
82         /** Sets the fog color, which is blended into distant surfaces. */
83         void set_fog_color(const Color &);
84
85         /** Sets the density of the fog.  Zero means no fog. */
86         void set_fog_density(float);
87
88         /** Sets the density of the fog so that the blending factor at the given
89         distance is 50%. */
90         void set_fog_half_distance(float);
91
92         /** Attaches a light source.  If the light was already attached, does
93         nothing. */
94         void attach(const Light &);
95
96         /** Detaches a light source.  If the light was not attached, does nothing. */
97         void detach(const Light &);
98
99         DEPRECATED void attach(unsigned, const Light &l) { attach(l); }
100         DEPRECATED void detach(unsigned);
101
102         /** Returns an attached light.  If no light is attached at that index, null
103         is returned. */
104         DEPRECATED const Light *get_attached_light(unsigned) const;
105
106         /** Updates a ProgramData object with the uniforms for the Lighting,
107         including all attached light sources.  A view matrix must be passed in. */
108         DEPRECATED void update_shader_data(ProgramData &, const Matrix &) const;
109
110         const ProgramData &get_shader_data() const;
111
112         void set_debug_name(const std::string &);
113 };
114
115 } // namespace GL
116 } // namespace Msp
117
118 #endif