]> git.tdb.fi Git - libs/gl.git/blob - source/effects/ambientocclusion.h
Store the ambient occlusion rotate lookup texture in resources
[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(unsigned, unsigned) const;
39         };
40
41 private:
42         const 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_clamp_sampler;
50         const Sampler &nearest_sampler;
51
52 public:
53         AmbientOcclusion(unsigned, unsigned, float = 1.0f);
54
55 private:
56         static const Texture2D &get_or_create_rotate_lookup();
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