]> git.tdb.fi Git - libs/gl.git/blob - source/shadowmap.h
Drop Id tags and copyright notices from files
[libs/gl.git] / source / shadowmap.h
1 #ifndef SHADOWMAP_H_
2 #define SHADOWMAP_H_
3
4 #include "effect.h"
5 #include "framebuffer.h"
6 #include "texture2d.h"
7 #include "vector.h"
8
9 namespace Msp {
10 namespace GL {
11
12 class Light;
13 class Scene;
14
15 /**
16 Creates shadows on a Scene through a shadow map texture.  In the preparation
17 phase, the scene is rendered to a depth texture from the point of view of the
18 lightsource.  This texture is then used in the rendering phase together with
19 texture coordinate generation to determine whether each fragment is lit.
20 */
21 class ShadowMap: public Effect
22 {
23 private:
24         unsigned size;
25         const Scene &scene;
26         const Light &light;
27         Framebuffer fbo;
28         unsigned unit;
29         Texture2D depth_buf;
30         Vector3 target;
31         float radius;
32
33 public:
34         ShadowMap(unsigned, const Scene &, const Light &);
35
36         /** Sets the ShadowMap target point and radius.  The transformation matrix is
37         computed so that a sphere with the specified parameters will be completely
38         covered by the ShadowMap. */
39         void set_target(const Vector3 &, float);
40
41         /** Sets the texture unit to bind the shadow map to during the rendering
42         phase.  The default is texture unit 3. */
43         void set_texture_unit(unsigned);
44
45         virtual void prepare();
46         virtual void cleanup();
47 };
48
49 } // namespace GL
50 } // namespace Msp
51
52 #endif