]> git.tdb.fi Git - libs/gl.git/blob - source/effects/ambientocclusion.h
fd3b6574cbbdfec1b83b2244d1e5e744cf003532
[libs/gl.git] / source / effects / ambientocclusion.h
1 #ifndef MSP_GL_AMBIENTOCCLUSION_H_
2 #define MSP_GL_AMBIENTOCCLUSION_H_
3
4 #include "postprocessor.h"
5 #include "programdata.h"
6 #include "rendertarget.h"
7
8 namespace Msp {
9 namespace GL {
10
11 class Program;
12
13 /**
14 Implements screen-space ambient occlusion.
15
16 http://en.wikipedia.org/wiki/Screen_Space_Ambient_Occlusion
17 */
18 class AmbientOcclusion: public PostProcessor
19 {
20 public:
21         struct Template: PostProcessor::Template
22         {
23                 class Loader: public DataFile::DerivedObjectLoader<Template, PostProcessor::Template::Loader>
24                 {
25                 public:
26                         Loader(Template &);
27                 };
28
29                 unsigned n_samples;
30                 float occlusion_radius;
31                 float darkness;
32                 float edge_depth_threshold;
33
34                 Template();
35
36                 virtual AmbientOcclusion *create(unsigned, unsigned) const;
37         };
38
39 private:
40         const Texture2D &rotate_lookup;
41         RenderTarget occlude_target;
42         const Program &occlude_shader;
43         const Program &combine_shader;
44         mutable ProgramData shdata;
45         const Mesh &quad;
46         const Sampler &linear_sampler;
47         const Sampler &nearest_clamp_sampler;
48         const Sampler &nearest_sampler;
49
50 public:
51         AmbientOcclusion(unsigned, unsigned, float = 1.0f);
52
53 private:
54         static const Texture2D &get_or_create_rotate_lookup();
55         static float radical_inverse(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         virtual void set_debug_name(const std::string &);
67 };
68
69 } // namespace GL
70 } // namespace Msp
71
72 #endif