1 #ifndef MSP_GL_SHADOWMAP_H_
2 #define MSP_GL_SHADOWMAP_H_
5 #include "framebuffer.h"
6 #include "programdata.h"
18 Creates shadows on a Scene through a shadow map texture. In the preparation
19 phase, the scene is rendered to a depth texture from the point of view of the
20 lightsource. This texture is then used in the rendering phase together with
21 texture coordinate generation to determine whether each fragment is lit.
23 class ShadowMap: public Effect
31 const Sampler &sampler;
35 mutable ProgramData shdata;
39 ShadowMap(Resources &, unsigned, Renderable &, const Light &);
41 /** Sets the ShadowMap target point and radius. The transformation matrix is
42 computed so that a sphere with the specified parameters will be completely
43 covered by the ShadowMap. */
44 void set_target(const Vector3 &, float);
46 /** Sets the darkness of shadows. Must be in the range between 0.0 and 1.0,
47 inclusive. Only usable with shaders, and provided through the
48 shadow_darkness uniform. */
49 void set_darkness(float);
51 /** Sets a distance beyond objects from which the shadow starts. Expressed
52 in pixel-sized units. Must be positive; values less than 1.0 are not
53 recommended. Larger values produce less depth artifacts, but may prevent
54 thin objects from casting shadows on nearby sufraces. */
55 void set_depth_bias(float);
57 const Texture2D &get_depth_texture() const { return depth_buf; }
58 const Matrix &get_shadow_matrix() const { return shadow_matrix; }
60 virtual void setup_frame(Renderer &);
61 virtual void finish_frame();
63 virtual void render(Renderer &, const Tag & = Tag()) const;