X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Feffects%2Fshadowmap.h;h=cf2dec01bc69e90afda1255dd63918fd5b8d5ebc;hb=bace0b24414abc7b3ba46df3a9fd7408d7479a5e;hp=5d8bf5095287423827e71f32b988a22811d1777e;hpb=0d765be40336decc966932e0143fe9496f3eab4b;p=libs%2Fgl.git diff --git a/source/effects/shadowmap.h b/source/effects/shadowmap.h index 5d8bf509..cf2dec01 100644 --- a/source/effects/shadowmap.h +++ b/source/effects/shadowmap.h @@ -5,14 +5,15 @@ #include "effect.h" #include "framebuffer.h" #include "programdata.h" +#include "rect.h" #include "texture2d.h" #include "vector.h" namespace Msp { namespace GL { +class DirectionalLight; class Light; -class Resources; /** Creates shadows on a renderable through a shadow map texture. In the setup @@ -23,25 +24,53 @@ texture coordinate generation to determine whether each fragment is lit. class ShadowMap: public Effect { private: - unsigned size; - const Light &light; - Renderable &shadow_caster; + enum ShadowType + { + NONE, + DIRECTIONAL + }; + + struct ShadowedLight + { + const Light *light; + unsigned index; + Rect region; + ShadowType type; + unsigned view_index; + Renderable *shadow_caster; + }; + + struct ShadowView + { + unsigned light_index; + unsigned face; + Camera camera; + }; + + unsigned width; + unsigned height; + const Lighting *lighting; + std::vector lights; + std::vector views; Framebuffer fbo; - Camera shadow_camera; - Matrix shadow_matrix; Texture2D depth_buf; const Sampler &sampler; Vector3 target; - float radius; - float depth_bias; - mutable ProgramData shdata; - bool rendered; + float radius = 1.0f; + float depth_bias = 4.0f; + float darkness = 1.0f; + ProgramData shdata; + bool rendered = false; + std::string debug_name; + ShadowMap(unsigned, unsigned, Renderable &, const Lighting *); public: - ShadowMap(Resources &, unsigned, Renderable &, const Light &, Renderable &); - DEPRECATED ShadowMap(Resources &, unsigned, Renderable &, const Light &); + ShadowMap(unsigned, Renderable &, const DirectionalLight &, Renderable &); + ShadowMap(unsigned, unsigned, Renderable &, const Lighting &); + + void add_light(const DirectionalLight &, unsigned, Renderable &); private: - void init(unsigned); + void add_light(const Light &, unsigned, ShadowType, Renderable &); public: /** Sets the ShadowMap target point and radius. The transformation matrix is @@ -61,12 +90,13 @@ public: void set_depth_bias(float); const Texture2D &get_depth_texture() const { return depth_buf; } - const Matrix &get_shadow_matrix() const { return shadow_matrix; } virtual void setup_frame(Renderer &); virtual void finish_frame(); virtual void render(Renderer &, Tag = Tag()) const; + + virtual void set_debug_name(const std::string &); }; } // namespace GL