]> git.tdb.fi Git - libs/gl.git/blob - source/ambientocclusion.h
Remove the deprecated ProgramBuilder class
[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         RefPtr<Mesh> quad;
50         RefPtr<Sampler> linear_sampler;
51         RefPtr<Sampler> nearest_sampler;
52
53 public:
54         AmbientOcclusion(unsigned, unsigned, float = 1.0f);
55
56 private:
57         static float random(unsigned &);
58
59 public:
60         void set_n_samples(unsigned);
61         void set_occlusion_radius(float);
62         void set_edge_depth_threshold(float);
63
64         void set_darkness(float);
65
66         virtual void render(Renderer &, const Texture2D &, const Texture2D &);
67 };
68
69 } // namespace GL
70 } // namespace Msp
71
72 #endif