1 #ifndef MSP_GL_ENVIRONMENTMAP_H_
2 #define MSP_GL_ENVIRONMENTMAP_H_
7 #include "framebuffer.h"
8 #include "programdata.h"
10 #include "texturecube.h"
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.
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
27 class EnvironmentMap: public Effect
30 struct Template: Effect::Template
32 class Loader: public DataFile::DerivedObjectLoader<Template, Effect::Template::Loader>
35 static ActionMap shared_actions;
38 Loader(Template &, Collection &);
40 virtual void init_actions();
42 void fixed_position(float, float, float);
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;
54 virtual EnvironmentMap *create(const std::map<std::string, Renderable *> &) const;
65 Renderable &environment;
69 Vector3 fixed_position;
70 bool use_fixed_pos = false;
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;
80 const Sampler &sampler;
81 const Sampler &mip_sampler;
83 bool rendered = false;
84 unsigned update_interval = 1;
85 unsigned update_delay = 0;
88 EnvironmentMap(unsigned size, PixelFormat, Renderable &rend, Renderable &env);
89 EnvironmentMap(unsigned size, PixelFormat, unsigned, Renderable &rend, Renderable &env);
91 void set_fixed_position(const Vector3 &);
93 void set_depth_clip(float, float);
95 /** Sets the interval in frames between environment map updates. A value of
96 0 means an update is only done when manually requested. */
97 void set_update_interval(unsigned);
99 /** Request that the environment map is updated on the next frame. */
102 virtual void setup_frame(Renderer &);
103 virtual void finish_frame();
105 virtual void render(Renderer &, Tag = Tag()) const;
107 virtual void set_debug_name(const std::string &);