X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fmaterials%2Flight.h;h=189380cdb7a1e2f1b619423761b708bfadc8b2dc;hp=c7e281887651c7f3d5495f86c34960055d9429e9;hb=HEAD;hpb=dff7004fa078d55911664c0f513b5dc6c9449420 diff --git a/source/materials/light.h b/source/materials/light.h index c7e28188..189380cd 100644 --- a/source/materials/light.h +++ b/source/materials/light.h @@ -1,7 +1,8 @@ #ifndef MSP_GL_LIGHT_H_ #define MSP_GL_LIGHT_H_ -#include +#include +#include #include #include "color.h" #include "placeable.h" @@ -9,103 +10,67 @@ namespace Msp { namespace GL { -class Matrix; class ProgramData; /** -Stores properties of a single light source. Lights can be directional, point -lights or spotlights. No explicit type parameter is provided; rather the -other parameters determine what kind of light it is. If the fourth component -of position is zero, it's a directional light. Otherwise, if the spot cutoff -is not 180 degrees, it's a spotlight. Otherwise it's an omnidirectional point -light. +Base class for light sources. The DirectionalLight and PointLight classes +implement different types of lights. Lights are usually grouped with a Lighting object, which can be used in a Sequence::Step. -Lights do not cast shadows by themselves. See ShadowMap for that. +Shadows can be added to lights by using the ShadowMap effect. */ class Light: public Placeable { -public: +protected: class Loader: public DataFile::ObjectLoader { - public: + protected: Loader(Light &); + virtual void init_actions(); + private: - void attenuation(float, float, float); - void diffuse(float, float, float); - void position(float, float, float, float); - void specular(float, float, float); - void spot_direction(float, float, float); - void spot_exponent(float); - void spot_cutoff(float); + void color(float, float, float); }; -private: - Color diffuse; - Color specular; - Vector4 position; - Vector3 spot_dir; - Vector3 direction; - float spot_exp; - Geometry::Angle spot_cutoff; - float attenuation[3]; - public: - Light(); - -private: - void update_matrix(); - -public: - /** Sets the diffuse (direction-independent) color of the Light. Provided - to shaders with the name light_sources[i].diffuse. */ - void set_diffuse(const Color &c); - - /** Sets the specular (direction-dependent) color of the Light. Provided to - shaders with the name light_sources[i].specular. */ - void set_specular(const Color &c); + class GenericLoader: public DataFile::DynamicObjectLoader + { + friend class Light; - const Color &get_diffuse() const { return diffuse; } - const Color &get_specular() const { return specular; } + public: + GenericLoader(Collection &c): DynamicObjectLoader(&c) { } - /** Sets the postion and orientation of the Light from a matrix. Negative Z - axis is used as the spot direction, other axes are ignored. */ - virtual void set_matrix(const Matrix &); + protected: + virtual const TypeRegistry &get_type_registry() const { return Light::get_light_registry(); } + }; - /** Sets the position of the Light. For a directional light, set the xyz - components to a vector pointing towards the light and the w component to 0. */ - void set_position(const Vector4 &); +protected: + Color color = { 1.0f }; + unsigned generation = 0; - const Vector4 &get_position() const { return position; } + Light() = default; +public: + virtual ~Light() = default; - /** Sets the direction of a spotlight. Has no effect if spotlight cutoff is - not set. */ - void set_spot_direction(const Vector3 &); + /** Sets the color of the light. */ + void set_color(const Color &); - /** Sets the angular falloff exponent of the spotlight. Must be >= 0. */ - void set_spot_exponent(float); + const Color &get_color() const { return color; } - /** Sets the cutoff angle of a spotlight. Beyond this angle from its axis - the spotlight provides no illumination. Must be between 0 and 90 degrees, - or exactly 180 degrees to indicate a non-spotlight. */ - void set_spot_cutoff(const Geometry::Angle &); + unsigned get_generation() const { return generation; } - /** Disables spotlight, reverting to an omnidirectional point light. - Equivalent to setting the spot cutoff to 180 degrees. */ - void disable_spot_cutoff(); + /** Updates a ProgramData object with the uniform values for the light. A + light source index must be passed in. */ + void update_shader_data(ProgramData &, unsigned) const; - const Vector3 &get_spot_direction() const { return spot_dir; } - float get_spot_exponent() const { return spot_exp; } - const Geometry::Angle &get_spot_cutoff() const { return spot_cutoff; } - void set_attenuation(float, float, float); - const float *get_attenuation() const { return attenuation; } +protected: + virtual void update_shader_data(ProgramData &, const std::string &) const = 0; - /** Updates a ProgramData object with the uniforms for the Light. A view - matrix and light source index must be passed in. */ - void update_shader_data(ProgramData &, const Matrix &, unsigned) const; +private: + static GenericLoader::TypeRegistry &get_light_registry(); }; } // namespace GL