]> git.tdb.fi Git - libs/gl.git/blob - source/effects/ambientocclusion.h
Convert Lighting to use shared actions
[libs/gl.git] / source / effects / ambientocclusion.h
1 #ifndef MSP_GL_AMBIENTOCCLUSION_H_
2 #define MSP_GL_AMBIENTOCCLUSION_H_
3
4 #include "framebuffer.h"
5 #include "mesh.h"
6 #include "postprocessor.h"
7 #include "program.h"
8 #include "programdata.h"
9 #include "rendertarget.h"
10 #include "texture2d.h"
11
12 namespace Msp {
13 namespace GL {
14
15 /**
16 Implements screen-space ambient occlusion.
17
18 http://en.wikipedia.org/wiki/Screen_Space_Ambient_Occlusion
19 */
20 class AmbientOcclusion: public PostProcessor
21 {
22 public:
23         struct Template: PostProcessor::Template
24         {
25                 class Loader: public DataFile::DerivedObjectLoader<Template, PostProcessor::Template::Loader>
26                 {
27                 public:
28                         Loader(Template &);
29                 };
30
31                 unsigned n_samples;
32                 float occlusion_radius;
33                 float darkness;
34                 float edge_depth_threshold;
35
36                 Template();
37
38                 virtual AmbientOcclusion *create(Resources &, unsigned, unsigned) const;
39         };
40
41 private:
42         Texture2D rotate_lookup;
43         RenderTarget occlude_target;
44         const Program &occlude_shader;
45         const Program &combine_shader;
46         mutable ProgramData shdata;
47         const Mesh &quad;
48         const Sampler &linear_sampler;
49         const Sampler &nearest_sampler;
50
51 public:
52         AmbientOcclusion(Resources &, unsigned, unsigned, float = 1.0f);
53
54 private:
55         static float random(unsigned &);
56
57 public:
58         void set_n_samples(unsigned);
59         void set_occlusion_radius(float);
60         void set_edge_depth_threshold(float);
61
62         void set_darkness(float);
63
64         virtual void render(Renderer &, const Texture2D &, const Texture2D &);
65 };
66
67 } // namespace GL
68 } // namespace Msp
69
70 #endif