]> git.tdb.fi Git - libs/gl.git/blob - source/effects/environmentmap.h
Remove the exclusion mechanism from Renderer
[libs/gl.git] / source / effects / environmentmap.h
1 #ifndef MSP_GL_ENVIRONMENTMAP_H_
2 #define MSP_GL_ENVIRONMENTMAP_H_
3
4 #include <vector>
5 #include "camera.h"
6 #include "effect.h"
7 #include "framebuffer.h"
8 #include "programdata.h"
9 #include "texture2d.h"
10 #include "texturecube.h"
11
12 namespace Msp {
13 namespace GL {
14
15 class Mesh;
16 class Sampler;
17
18 /**
19 Creates a cube map texture of the surroundings of the renderable.  This texture
20 can then be used to implement effects such as reflections or refractions.
21
22 If the EnvironmentMap is used in a Sequence, it's worth noting that the cube
23 map will be prepared outside of any rendering pass.  It's recommended to use
24 another Sequence to define which passes should be used to render the
25 environment.
26 */
27 class EnvironmentMap: public Effect
28 {
29 public:
30         struct Template: Effect::Template
31         {
32                 class Loader: public DataFile::DerivedObjectLoader<Template, Effect::Template::Loader>
33                 {
34                 private:
35                         static ActionMap shared_actions;
36
37                 public:
38                         Loader(Template &, Collection &);
39                 private:
40                         virtual void init_actions();
41
42                         void fixed_position(float, float, float);
43                 };
44
45                 unsigned size = 512;
46                 PixelFormat format = RGB16F;
47                 std::string environment_name;
48                 unsigned roughness_levels = 5;
49                 Vector3 fixed_position;
50                 bool use_fixed_position = false;
51                 float near_clip = 0.1f;
52                 float far_clip = 100.0f;
53
54                 virtual EnvironmentMap *create(const std::map<std::string, Renderable *> &) const;
55         };
56
57 protected:
58         struct Face
59         {
60                 Framebuffer fbo;
61                 Camera camera;
62         };
63
64         unsigned size;
65         Renderable &environment;
66         TextureCube env_tex;
67         Texture2D depth_buf;
68         Face faces[6];
69         Vector3 fixed_position;
70         bool use_fixed_pos = false;
71
72         TextureCube irradiance;
73         const Program &irradiance_shprog;
74         Framebuffer irradiance_fbo;
75         const Program &specular_shprog;
76         std::vector<Framebuffer> specular_fbos;
77         ProgramData prefilter_shdata;
78         const Mesh &fullscreen_mesh;
79
80         const Sampler &sampler;
81         const Sampler &mip_sampler;
82         ProgramData shdata;
83         bool rendered = false;
84         bool in_setup_frame = false;
85         unsigned update_interval = 1;
86         unsigned update_delay = 0;
87
88 public:
89         EnvironmentMap(unsigned size, PixelFormat, Renderable &rend, Renderable &env);
90         EnvironmentMap(unsigned size, PixelFormat, unsigned, Renderable &rend, Renderable &env);
91
92         void set_fixed_position(const Vector3 &);
93
94         void set_depth_clip(float, float);
95
96         /** Sets the interval in frames between environment map updates.  A value of
97         0 means an update is only done when manually requested. */
98         void set_update_interval(unsigned);
99
100         /** Request that the environment map is updated on the next frame. */
101         void queue_update();
102
103         virtual void setup_frame(Renderer &);
104         virtual void finish_frame();
105
106         virtual void render(Renderer &, Tag = Tag()) const;
107
108         virtual void set_debug_name(const std::string &);
109 };
110
111 } // namespace GL
112 } // namespace Msp
113
114 #endif