1 #ifndef MSP_GL_LIGHT_H_
2 #define MSP_GL_LIGHT_H_
15 Stores properties of a single light source. Lights can be directional, point
16 lights or spotlights. No explicit type parameter is provided; rather the
17 other parameters determine what kind of light it is. If the fourth component
18 of position is zero, it's a directional light. Otherwise, if the spot cutoff
19 is not 180 degrees, it's a spotlight. Otherwise it's an omnidirectional point
22 Lights are usually grouped with a Lighting object, which can be used in a
25 Lights do not cast shadows by themselves. See ShadowMap for that.
27 class Light: public Placeable
47 Geometry::Angle<float> spot_cutoff;
55 void update_parameter(int, int = -1) const;
59 /** Sets the diffuse (direction-independent) color of the Light. Provided
60 to shaders with the name light_sources[i].diffuse. */
61 void set_diffuse(const Color &c);
63 /** Sets the specular (direction-dependent) color of the Light. Provided to
64 shaders with the name light_sources[i].specular. */
65 void set_specular(const Color &c);
67 const Color &get_diffuse() const { return diffuse; }
68 const Color &get_specular() const { return specular; }
70 /** Sets the postion and orientation of the Light from a matrix. Negative Z
71 axis is used as the spot direction, other axes are ignored. */
72 virtual void set_matrix(const Matrix &);
74 /** Sets the position of the Light. For a directional light, set the xyz
75 components to a vector pointing towards the light and the w component to 0. */
76 void set_position(const Vector4 &);
78 const Vector4 &get_position() const { return position; }
80 /** Sets the direction of a spotlight. Has no effect if spotlight cutoff is
82 void set_spot_direction(const Vector3 &);
84 /** Sets the angular falloff exponent of the spotlight. Must be >= 0. */
85 void set_spot_exponent(float);
88 void set_spot_cutoff(float);
90 /** Sets the cutoff angle of a spotlight. Beyond this angle from its axis
91 the spotlight provides no illumination. Must be between 0 and 90 degrees,
92 or exactly 180 degrees to indicate a non-spotlight. */
93 void set_spot_cutoff(const Geometry::Angle<float> &);
95 /** Disables spotlight, reverting to an omnidirectional point light.
96 Equivalent to setting the spot cutoff to 180 degrees. */
97 void disable_spot_cutoff();
99 const Vector3 &get_spot_direction() const { return spot_dir; }
100 float get_spot_exponent() const { return spot_exp; }
101 const Geometry::Angle<float> &get_spot_cutoff() const { return spot_cutoff; }
102 void set_attenuation(float, float, float);
103 const float *get_attenuation() const { return attenuation; }
105 /** Updates a ProgramData object with the uniforms for the Light. A view
106 matrix and light source index must be passed in. */
107 void update_shader_data(ProgramData &, const Matrix &, unsigned) const;
109 void bind() const { return bind_to(0); }
110 void bind_to(unsigned) const;
112 static const Light *current(unsigned = 0);
113 static void unbind() { return unbind_from(0); }
114 static void unbind_from(unsigned);