X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Feffects%2Fshadowmap.h;h=502480122fc68354e45c85adec5b8a3d22c328de;hp=c3c7bd55a7f53430937cce8faf6f6955b220f61d;hb=083a8227715fa32c841fc2b8126e4ab8d2840ba0;hpb=a2b0d155023ca23afe7848ae5d17e0f7bc328525 diff --git a/source/effects/shadowmap.h b/source/effects/shadowmap.h index c3c7bd55..50248012 100644 --- a/source/effects/shadowmap.h +++ b/source/effects/shadowmap.h @@ -12,7 +12,9 @@ namespace Msp { namespace GL { +class DirectionalLight; class Light; +class PointLight; /** Creates shadows on a renderable through a shadow map texture. In the setup @@ -22,38 +24,107 @@ texture coordinate generation to determine whether each fragment is lit. */ class ShadowMap: public Effect { +public: + struct Template: Effect::Template + { + class Loader: public DataFile::DerivedObjectLoader + { + private: + static ActionMap shared_actions; + + public: + Loader(Template &, Collection &); + private: + virtual void init_actions(); + + void light(const std::string &); + void size_square(unsigned); + void target(float, float, float); + }; + + struct ShadowedLight + { + class Loader: public DataFile::ObjectLoader + { + private: + static ActionMap shared_actions; + + public: + Loader(ShadowedLight &); + private: + virtual void init_actions(); + }; + + const Light *light = 0; + unsigned size; + std::string shadow_caster_name; + }; + + unsigned width = 2048; + unsigned height = 2048; + const Lighting *lighting = 0; + std::vector lights; + Vector3 target; + float radius = 1.0f; + float depth_bias = 4.0f; + float darkness = 1.0f; + + virtual ShadowMap *create(const std::map &) const; + }; + private: + enum ShadowType + { + NONE, + DIRECTIONAL, + TETRAHEDRON + }; + struct ShadowedLight { const Light *light; unsigned index; Rect region; - Camera shadow_camera; + ShadowType type; + unsigned view_index; + Renderable *shadow_caster; + }; + + struct ShadowView + { + unsigned light_index; + unsigned face; + Camera camera; + Matrix face_matrix; }; unsigned width; unsigned height; const Lighting *lighting; std::vector lights; - Renderable &shadow_caster; + std::vector views; Framebuffer fbo; Texture2D depth_buf; const Sampler &sampler; Vector3 target; - float radius; - float depth_bias; - float darkness; + float radius = 1.0f; + float depth_bias = 4.0f; + float darkness = 1.0f; ProgramData shdata; - bool rendered; + bool rendered = false; std::string debug_name; - ShadowMap(unsigned, unsigned, Renderable &, const Lighting *, Renderable &); + ShadowMap(unsigned, unsigned, Renderable &, const Lighting *); public: - ShadowMap(unsigned, Renderable &, const Light &, Renderable &); - ShadowMap(unsigned, unsigned, Renderable &, const Lighting &, Renderable &); + ShadowMap(unsigned, Renderable &, const DirectionalLight &, Renderable &); + ShadowMap(unsigned, unsigned, Renderable &, const Lighting &); - void add_light(const Light &, unsigned); + void add_light(const DirectionalLight &, unsigned, Renderable &); + void add_light(const PointLight &, unsigned, Renderable &); +private: + void add_light(const Light &, unsigned, ShadowType, Renderable &); +public: /** Sets the ShadowMap target point and radius. The transformation matrix is computed so that a sphere with the specified parameters will be completely covered by the ShadowMap. */