]> git.tdb.fi Git - libs/gl.git/blob - source/effects/shadowmap.h
Comments and cosmetic cleanups
[libs/gl.git] / source / effects / shadowmap.h
1 #ifndef MSP_GL_SHADOWMAP_H_
2 #define MSP_GL_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 Resources;
15
16 /**
17 Creates shadows on a renderable through a shadow map texture.  In the setup
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         Framebuffer fbo;
28         Matrix shadow_matrix;
29         Texture2D depth_buf;
30         const Sampler &sampler;
31         Vector3 target;
32         float radius;
33         float depth_bias;
34         mutable ProgramData shdata;
35         bool rendered;
36
37 public:
38         ShadowMap(Resources &, unsigned, Renderable &, const Light &);
39
40         /** Sets the ShadowMap target point and radius.  The transformation matrix is
41         computed so that a sphere with the specified parameters will be completely
42         covered by the ShadowMap. */
43         void set_target(const Vector3 &, float);
44
45         /** Sets the darkness of shadows.  Must be in the range between 0.0 and 1.0,
46         inclusive.  Only usable with shaders, and provided through the
47         shadow_darkness uniform. */
48         void set_darkness(float);
49
50         /** Sets a distance beyond objects from which the shadow starts.  Expressed
51         in pixel-sized units.  Must be positive; values less than 1.0 are not
52         recommended.  Larger values produce less depth artifacts, but may prevent
53         thin objects from casting shadows on nearby sufraces. */
54         void set_depth_bias(float);
55
56         const Texture2D &get_depth_texture() const { return depth_buf; }
57         const Matrix &get_shadow_matrix() const { return shadow_matrix; }
58
59         virtual void setup_frame(Renderer &);
60         virtual void finish_frame();
61
62         virtual void render(Renderer &, const Tag & = Tag()) const;
63 };
64
65 } // namespace GL
66 } // namespace Msp
67
68 #endif