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