]> git.tdb.fi Git - libs/gl.git/blob - source/materials/lighting.h
Rearrange soucre files into subdirectories
[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 "gl.h"
8 #include "programdata.h"
9
10 namespace Msp {
11 namespace GL {
12
13 class Light;
14
15 /**
16 Encapsulates global lighting parameters and any number of individual light
17 sources.
18 */
19 class Lighting
20 {
21 public:
22         class Loader: public DataFile::ObjectLoader<Lighting>
23         {
24         public:
25                 Loader(Lighting &);
26
27         private:
28                 void ambient(float, float, float);
29                 void fog_color(float, float, float);
30                 void fog_density(float);
31                 void fog_half_distance(float);
32                 void horizon_angle(float);
33                 void light(unsigned);
34                 void sky_color(float, float, float);
35                 void zenith_direction(float, float, float);
36         };
37
38 private:
39         Color ambient;
40         Color sky_color;
41         Vector3 zenith_direction;
42         Geometry::Angle<float> horizon_angle;
43         Color fog_color;
44         float fog_density;
45         std::vector<const Light *> lights;
46         std::vector<Light *> owned_data;
47
48 public:
49         Lighting();
50         ~Lighting();
51
52         /** Sets the ambient lighting color.  Affects all surfaces in the scene. */
53         void set_ambient(const Color &);
54
55         const Color &get_ambient() const { return ambient; }
56
57         /** Sets the color of the sky at zenith.  Has no effect without shaders. */
58         void set_sky_color(const Color &);
59
60         /** Sets the direction of the zenith.  Defaults to positive Z axis.  Has no
61         effect without shaders. */
62         void set_zenith_direction(const Vector3 &);
63
64         /** Sets the angle where skylight cuts off, counted from the true horizon.
65         Has no effect without shaders. */
66         void set_horizon_angle(const Geometry::Angle<float> &);
67
68         /** Sets the fog color, which is blended into distant surfaces. */
69         void set_fog_color(const Color &);
70
71         /** Sets the density of the fog.  Zero means no fog. */
72         void set_fog_density(float);
73
74         /** Sets the density of the fog so that the blending factor at the given
75         distance is 50%. */
76         void set_fog_half_distance(float);
77
78         /** Attaches a light source. */
79         void attach(unsigned, const Light &);
80
81         /** Detaches a light source. */
82         void detach(unsigned);
83
84         /** Returns an attached light.  If no light is attached at that index, null
85         is returned. */
86         const Light *get_attached_light(unsigned) const;
87
88         /** Updates a ProgramData object with the uniforms for the Lighting,
89         including all attached light sources.  A view matrix must be passed in. */
90         void update_shader_data(ProgramData &, const Matrix &) const;
91 };
92
93 } // namespace GL
94 } // namespace Msp
95
96 #endif