]> git.tdb.fi Git - libs/gl.git/blob - source/ambientocclusion.h
Make ambient occlusion edge detection threshold adjustable
[libs/gl.git] / source / 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 #include "texturing.h"
12
13 namespace Msp {
14 namespace GL {
15
16 /**
17 Implements screen-space ambient occlusion.
18
19 http://en.wikipedia.org/wiki/Screen_Space_Ambient_Occlusion
20 */
21 class AmbientOcclusion: public PostProcessor
22 {
23 public:
24         struct Template: PostProcessor::Template
25         {
26                 class Loader: public DataFile::DerivedObjectLoader<Template, PostProcessor::Template::Loader>
27                 {
28                 public:
29                         Loader(Template &);
30                 };
31
32                 unsigned n_samples;
33                 float occlusion_radius;
34                 float darkness;
35                 float edge_depth_threshold;
36
37                 Template();
38
39                 virtual AmbientOcclusion *create(unsigned, unsigned) const;
40         };
41
42 private:
43         Texture2D rotate_lookup;
44         RenderTarget occlude_target;
45         Texturing texturing;
46         Program occlude_shader;
47         Program combine_shader;
48         mutable ProgramData shdata;
49         const Mesh &quad;
50
51 public:
52         AmbientOcclusion(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         // Deprecated
63         void set_depth_ratio(float);
64
65         void set_darkness(float);
66
67         virtual void render(Renderer &, const Texture2D &, const Texture2D &);
68 };
69
70 } // namespace GL
71 } // namespace Msp
72
73 #endif