]> git.tdb.fi Git - libs/gl.git/blob - source/effects/ambientocclusion.h
Rename Effect::enabled_passes to enabled_methods
[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 = 16;
30                 float occlusion_radius = 0.5f;
31                 float darkness = 1.0f;
32                 float edge_depth_threshold = 0.1f;
33
34                 virtual AmbientOcclusion *create(unsigned, unsigned) const;
35         };
36
37 private:
38         const Texture2D &rotate_lookup;
39         RenderTarget occlude_target;
40         const Program &occlude_shader;
41         const Program &combine_shader;
42         mutable ProgramData shdata;
43         const Mesh &quad;
44         const Sampler &linear_sampler;
45         const Sampler &nearest_clamp_sampler;
46         const Sampler &nearest_sampler;
47
48 public:
49         AmbientOcclusion(unsigned, unsigned, float = 1.0f);
50
51 private:
52         static const Texture2D &get_or_create_rotate_lookup();
53         static float radical_inverse(unsigned);
54
55 public:
56         void set_n_samples(unsigned);
57         void set_occlusion_radius(float);
58         void set_edge_depth_threshold(float);
59
60         void set_darkness(float);
61
62         virtual void render(Renderer &, const Texture2D &, const Texture2D &);
63
64         virtual void set_debug_name(const std::string &);
65 };
66
67 } // namespace GL
68 } // namespace Msp
69
70 #endif