X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fmaterials%2Flight.h;h=189380cdb7a1e2f1b619423761b708bfadc8b2dc;hp=a6ffd16efd3701d456cb3b0d3578b0ee558d6f6b;hb=HEAD;hpb=5bb193f930fb8738d099d630c4d625d82c1215b5 diff --git a/source/materials/light.h b/source/materials/light.h index a6ffd16e..189380cd 100644 --- a/source/materials/light.h +++ b/source/materials/light.h @@ -1,11 +1,11 @@ #ifndef MSP_GL_LIGHT_H_ #define MSP_GL_LIGHT_H_ +#include +#include #include -#include #include "color.h" #include "placeable.h" -#include "vector.h" namespace Msp { namespace GL { @@ -13,106 +13,64 @@ namespace GL { 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 color(float, float, float); - void position(float, float, float, float); - void spot_direction(float, float, float); - void spot_exponent(float); - void spot_cutoff(float); }; -private: - Color color; - Color transmittance; - Vector4 position; - Vector3 spot_dir; - Vector3 direction; - float spot_exp; - Geometry::Angle spot_cutoff; - float attenuation[3]; - unsigned generation; - public: - Light(); - -private: - void update_matrix(); - -public: - /** Sets the color of the Light. Provided - to shaders as light_sources[i].color. */ - void set_color(const Color &); - - /** Sets a multiplier on how much light actually reaches the target. Used - when modeling an atmosphere. */ - void set_transmittance(const Color &); - - const Color &get_color() const { return color; } - const Color &get_transmittance() const { return transmittance; } - - DEPRECATED void set_diffuse(const Color &c) { set_color(c); } - DEPRECATED void set_specular(const Color &) { } - DEPRECATED const Color &get_diffuse() const { return color; } - DEPRECATED const Color &get_specular() const { return color; } - - /** 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 &); - - /** 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 &); + class GenericLoader: public DataFile::DynamicObjectLoader + { + friend class Light; - const Vector4 &get_position() const { return position; } + public: + GenericLoader(Collection &c): DynamicObjectLoader(&c) { } - /** Sets the direction of a spotlight. Has no effect if spotlight cutoff is - not set. */ - void set_spot_direction(const Vector3 &); + protected: + virtual const TypeRegistry &get_type_registry() const { return Light::get_light_registry(); } + }; - /** Sets the angular falloff exponent of the spotlight. Must be >= 0. */ - void set_spot_exponent(float); +protected: + Color color = { 1.0f }; + unsigned generation = 0; - /** 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 &); + Light() = default; +public: + virtual ~Light() = default; - /** Disables spotlight, reverting to an omnidirectional point light. - Equivalent to setting the spot cutoff to 180 degrees. */ - void disable_spot_cutoff(); + /** Sets the color of the light. */ + void set_color(const Color &); - 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; } + const Color &get_color() const { return color; } unsigned get_generation() const { return generation; } - /** Updates a ProgramData object with the uniforms for the Light. A light - source index must be passed in. Primarily used by Lighting. */ + /** 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; + +protected: + virtual void update_shader_data(ProgramData &, const std::string &) const = 0; + +private: + static GenericLoader::TypeRegistry &get_light_registry(); }; } // namespace GL