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 content renderable, for
20 use in image-based lighting. Also called a light probe.
22 The cube map can optionally be prefiltered for varying amounts of roughness.
23 An irradiance map for diffuse lighting is also created.
25 The EnvironmentMap won't be rendered inside its own environment. This avoids
26 artifacts if one is used to create reflections on a complex object.
28 The shader fragment common.glsl provides interfaces to access the environment
31 class EnvironmentMap: public Effect
34 struct Template: Effect::Template
36 class Loader: public DataFile::DerivedObjectLoader<Template, Effect::Template::Loader>
39 static ActionMap shared_actions;
42 Loader(Template &, Collection &);
44 virtual void init_actions();
46 void fixed_position(float, float, float);
50 PixelFormat format = RGBA16F;
51 std::string environment_name;
52 unsigned roughness_levels = 5;
53 Vector3 fixed_position;
54 bool use_fixed_position = false;
55 float near_clip = 0.1f;
56 float far_clip = 100.0f;
58 virtual EnvironmentMap *create(const std::map<std::string, Renderable *> &) const;
69 Renderable &environment;
73 Vector3 fixed_position;
74 bool use_fixed_pos = false;
76 TextureCube irradiance;
77 const Program &irradiance_shprog;
78 Framebuffer irradiance_fbo;
79 const Program &specular_shprog;
80 std::vector<Framebuffer> specular_fbos;
81 ProgramData prefilter_shdata;
82 const Mesh &fullscreen_mesh;
84 const Sampler &sampler;
85 const Sampler &mip_sampler;
87 bool rendered = false;
88 bool in_setup_frame = false;
89 unsigned update_interval = 1;
90 unsigned update_delay = 0;
93 EnvironmentMap(unsigned size, PixelFormat, Renderable &content, Renderable &env);
95 /** Creates an EnvironmentMap with prefiltering for varying amounts of
96 roughness. Levels specifies the number of prefilter mipmap levels and must
97 be valid for the size. */
98 EnvironmentMap(unsigned size, PixelFormat, unsigned levels, Renderable &content, Renderable &env);
100 /** Sets a fixed position to render the environment map from. This can be
101 useful if the content renderable does not have a model matrix. */
102 void set_fixed_position(const Vector3 &);
104 void set_depth_clip(float, float);
106 /** Sets the interval in frames between environment map updates. A value of
107 0 means an update is only done when manually requested. */
108 void set_update_interval(unsigned);
110 /** Request that the environment map is updated on the next frame. */
113 virtual void setup_frame(Renderer &);
114 virtual void finish_frame();
116 virtual void render(Renderer &, Tag = Tag()) const;
118 virtual void set_debug_name(const std::string &);