]> git.tdb.fi Git - libs/gl.git/blob - source/shadowmap.h
Add shd_eye_matrix to ShadowMap's shdata
[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 "programdata.h"
7 #include "texture2d.h"
8 #include "vector.h"
9
10 namespace Msp {
11 namespace GL {
12
13 class Light;
14 class Scene;
15
16 /**
17 Creates shadows on a Scene through a shadow map texture.  In the preparation
18 phase, the scene is rendered to a depth texture from the point of view of the
19 lightsource.  This texture is then used in the rendering phase together with
20 texture coordinate generation to determine whether each fragment is lit.
21 */
22 class ShadowMap: public Effect
23 {
24 private:
25         unsigned size;
26         const Light &light;
27         mutable Framebuffer fbo;
28         mutable Matrix light_matrix;
29         mutable Matrix view_matrix;
30         mutable Matrix shadow_matrix;
31         unsigned unit;
32         Texture2D depth_buf;
33         Vector3 target;
34         float radius;
35         float depth_bias;
36         mutable ProgramData shdata;
37         mutable bool rendered;
38
39 public:
40         ShadowMap(unsigned, const Renderable &, const Light &);
41
42         /** Sets the ShadowMap target point and radius.  The transformation matrix is
43         computed so that a sphere with the specified parameters will be completely
44         covered by the ShadowMap. */
45         void set_target(const Vector3 &, float);
46
47         /** Sets the darkness of shadows.  Must be in the range between 0.0 and 1.0,
48         inclusive.  Only usable with shaders, and provided through the
49         shadow_darkness uniform. */
50         void set_darkness(float);
51
52         /** Sets a distance beyond objects from which the shadow starts.  Expressed
53         in pixel-sized units.  Must be positive; values less than 1.0 are not
54         recommended.  Larger values produce less depth artifacts, but may prevent
55         thin objects from casting shadows on nearby sufraces. */
56         void set_depth_bias(float);
57
58         /** Sets the texture unit to bind the shadow map to during the rendering
59         phase.  Provided to shaders through the shadow and shadow_unit uniforms.
60         The default is texture unit 3. */
61         void set_texture_unit(unsigned);
62
63         virtual void setup_frame() const;
64         virtual void finish_frame() const;
65
66         virtual void render(Renderer &, const Tag &) const;
67 };
68
69 } // namespace GL
70 } // namespace Msp
71
72 #endif