1 #ifndef MSP_GL_SHADOWMAP_H_
2 #define MSP_GL_SHADOWMAP_H_
6 #include "framebuffer.h"
7 #include "programdata.h"
15 class DirectionalLight;
20 Creates shadows on a renderable through a shadow map texture. In the setup
21 phase, the scene is rendered to a depth texture from the point of view of the
22 lightsource. This texture is then used in the rendering phase together with
23 texture coordinate generation to determine whether each fragment is lit.
25 class ShadowMap: public Effect
42 Renderable *shadow_caster;
55 const Lighting *lighting;
56 std::vector<ShadowedLight> lights;
57 std::vector<ShadowView> views;
60 const Sampler &sampler;
63 float depth_bias = 4.0f;
64 float darkness = 1.0f;
66 bool rendered = false;
67 std::string debug_name;
69 ShadowMap(unsigned, unsigned, Renderable &, const Lighting *);
71 ShadowMap(unsigned, Renderable &, const DirectionalLight &, Renderable &);
72 ShadowMap(unsigned, unsigned, Renderable &, const Lighting &);
74 void add_light(const DirectionalLight &, unsigned, Renderable &);
75 void add_light(const PointLight &, unsigned, Renderable &);
77 void add_light(const Light &, unsigned, ShadowType, Renderable &);
80 /** Sets the ShadowMap target point and radius. The transformation matrix is
81 computed so that a sphere with the specified parameters will be completely
82 covered by the ShadowMap. */
83 void set_target(const Vector3 &, float);
85 /** Sets the darkness of shadows. Must be in the range between 0.0 and 1.0,
86 inclusive. Only usable with shaders, and provided through the
87 shadow_darkness uniform. */
88 void set_darkness(float);
90 /** Sets a distance beyond objects from which the shadow starts. Expressed
91 in pixel-sized units. Must be positive; values less than 1.0 are not
92 recommended. Larger values produce less depth artifacts, but may prevent
93 thin objects from casting shadows on nearby sufraces. */
94 void set_depth_bias(float);
96 const Texture2D &get_depth_texture() const { return depth_buf; }
98 virtual void setup_frame(Renderer &);
99 virtual void finish_frame();
101 virtual void render(Renderer &, Tag = Tag()) const;
103 virtual void set_debug_name(const std::string &);