]> git.tdb.fi Git - libs/gl.git/blob - source/effects/bloom.h
Load various built-in things through Resources
[libs/gl.git] / source / effects / bloom.h
1 #ifndef MSP_GL_BLOOM_H_
2 #define MSP_GL_BLOOM_H_
3
4 #include "framebuffer.h"
5 #include "mesh.h"
6 #include "postprocessor.h"
7 #include "texture2d.h"
8 #include "texturing.h"
9 #include "program.h"
10 #include "programdata.h"
11 #include "rendertarget.h"
12
13 namespace Msp {
14 namespace GL {
15
16 /**
17 The Bloom post-processing effect causes very bright areas of the image to bleed
18 into surrounding pixels.  Commonly used together with HDR rendering.
19
20 The technique used is to gaussian blur the image and then blend the result with
21 the original image.  With suitable parameters, this effect may also be used as
22 a blur filter.
23 */
24 class Bloom: public PostProcessor
25 {
26 public:
27         struct Template: public PostProcessor::Template
28         {
29                 class Loader: public DataFile::DerivedObjectLoader<Template, PostProcessor::Template::Loader>
30                 {
31                 public:
32                         Loader(Template &);
33                 };
34
35                 float radius;
36                 float strength;
37
38                 Template();
39
40                 virtual Bloom *create(Resources &, unsigned, unsigned) const;
41         };
42
43 private:
44         RenderTarget *target[2];
45         ProgramData common_shdata;
46         const Program &blur_shader;
47         ProgramData blur_shdata[2];
48         const Program &combine_shader;
49         const Mesh &quad;
50         const Sampler &nearest_sampler;
51         const Sampler &linear_sampler;
52         Texturing combine_texturing;
53
54 public:
55         Bloom(Resources &, unsigned, unsigned);
56         ~Bloom();
57
58         /** Sets the σ value of the gaussian blur.  Values much larger than 4.0 are
59         likely to cause artifacts. */
60         void set_radius(float);
61
62         /** Sets the blend factor between original and blurred images.  Larger
63         values mean more blurriness. */
64         void set_strength(float);
65
66         virtual void render(Renderer &, const Texture2D &, const Texture2D &);
67 };
68
69 } // namespace GL
70 } // namespace Msp
71
72 #endif