X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmaterials%2Flighting.h;fp=source%2Fmaterials%2Flighting.h;h=ca214fc829601c9c26fa05e73e9e6d37f08d46be;hb=7aaec9a70b8d7733429bec043f8e33e02956f266;hp=0000000000000000000000000000000000000000;hpb=bec07999d95b76f4b47cffcc564d0cd0afc0435e;p=libs%2Fgl.git diff --git a/source/materials/lighting.h b/source/materials/lighting.h new file mode 100644 index 00000000..ca214fc8 --- /dev/null +++ b/source/materials/lighting.h @@ -0,0 +1,96 @@ +#ifndef MSP_GL_LIGHTING_H_ +#define MSP_GL_LIGHTING_H_ + +#include +#include +#include "color.h" +#include "gl.h" +#include "programdata.h" + +namespace Msp { +namespace GL { + +class Light; + +/** +Encapsulates global lighting parameters and any number of individual light +sources. +*/ +class Lighting +{ +public: + class Loader: public DataFile::ObjectLoader + { + public: + Loader(Lighting &); + + private: + void ambient(float, float, float); + void fog_color(float, float, float); + void fog_density(float); + void fog_half_distance(float); + void horizon_angle(float); + void light(unsigned); + void sky_color(float, float, float); + void zenith_direction(float, float, float); + }; + +private: + Color ambient; + Color sky_color; + Vector3 zenith_direction; + Geometry::Angle horizon_angle; + Color fog_color; + float fog_density; + std::vector lights; + std::vector owned_data; + +public: + Lighting(); + ~Lighting(); + + /** Sets the ambient lighting color. Affects all surfaces in the scene. */ + void set_ambient(const Color &); + + const Color &get_ambient() const { return ambient; } + + /** Sets the color of the sky at zenith. Has no effect without shaders. */ + void set_sky_color(const Color &); + + /** Sets the direction of the zenith. Defaults to positive Z axis. Has no + effect without shaders. */ + void set_zenith_direction(const Vector3 &); + + /** Sets the angle where skylight cuts off, counted from the true horizon. + Has no effect without shaders. */ + void set_horizon_angle(const Geometry::Angle &); + + /** Sets the fog color, which is blended into distant surfaces. */ + void set_fog_color(const Color &); + + /** Sets the density of the fog. Zero means no fog. */ + void set_fog_density(float); + + /** Sets the density of the fog so that the blending factor at the given + distance is 50%. */ + void set_fog_half_distance(float); + + /** Attaches a light source. */ + void attach(unsigned, const Light &); + + /** Detaches a light source. */ + void detach(unsigned); + + /** Returns an attached light. If no light is attached at that index, null + is returned. */ + const Light *get_attached_light(unsigned) const; + + /** Updates a ProgramData object with the uniforms for the Lighting, + including all attached light sources. A view matrix must be passed in. */ + void update_shader_data(ProgramData &, const Matrix &) const; +}; + +} // namespace GL +} // namespace Msp + +#endif