X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Feffects%2Fenvironmentmap.h;h=9ef0e87d87a599fa8632a45234b8d3de6a3f0b95;hp=c54968de35d5cfc7bf11be0ee14559c34cf766fc;hb=HEAD;hpb=7aaec9a70b8d7733429bec043f8e33e02956f266 diff --git a/source/effects/environmentmap.h b/source/effects/environmentmap.h index c54968de..9ef0e87d 100644 --- a/source/effects/environmentmap.h +++ b/source/effects/environmentmap.h @@ -1,55 +1,121 @@ #ifndef MSP_GL_ENVIRONMENTMAP_H_ #define MSP_GL_ENVIRONMENTMAP_H_ +#include #include "camera.h" #include "effect.h" #include "framebuffer.h" -#include "matrix.h" #include "programdata.h" -#include "renderbuffer.h" +#include "texture2d.h" #include "texturecube.h" -#include "vector.h" namespace Msp { namespace GL { -class Renderable; +class Mesh; +class Sampler; /** -Creates a cube map texture of the surroundings of the renderable. This texture -can then be used to implement effects such as reflections or refractions. +Creates a cube map texture of the surroundings of the content renderable, for +use in image-based lighting. Also called a light probe. -If the EnvironmentMap is used in a Pipeline, it's worth noting that the cube -map will be prepared outside of any rendering pass. It's recommended to use -another Pipeline to define which passes should be used to render the -environment. +The cube map can optionally be prefiltered for varying amounts of roughness. +An irradiance map for diffuse lighting is also created. + +The EnvironmentMap won't be rendered inside its own environment. This avoids +artifacts if one is used to create reflections on a complex object. + +The shader fragment common.glsl provides interfaces to access the environment +data. */ class EnvironmentMap: public Effect { -private: +public: + struct Template: Effect::Template + { + class Loader: public DataFile::DerivedObjectLoader + { + private: + static ActionMap shared_actions; + + public: + Loader(Template &, Collection &); + private: + virtual void init_actions(); + + void fixed_position(float, float, float); + }; + + unsigned size = 512; + PixelFormat format = RGBA16F; + std::string environment_name; + unsigned roughness_levels = 5; + Vector3 fixed_position; + bool use_fixed_position = false; + float near_clip = 0.1f; + float far_clip = 100.0f; + + virtual EnvironmentMap *create(const std::map &) const; + }; + +protected: + struct Face + { + Framebuffer fbo; + Camera camera; + }; + unsigned size; Renderable &environment; TextureCube env_tex; - Renderbuffer depth_buf; - Framebuffer fbo[6]; - RefPtr sampler; - Camera camera; - mutable ProgramData shdata; - bool rendered; - unsigned update_interval; - unsigned update_delay; + Texture2D depth_buf; + Face faces[6]; + Vector3 fixed_position; + bool use_fixed_pos = false; + + TextureCube irradiance; + const Program &irradiance_shprog; + Framebuffer irradiance_fbo; + const Program &specular_shprog; + std::vector specular_fbos; + ProgramData prefilter_shdata; + const Mesh &fullscreen_mesh; + + const Sampler &sampler; + const Sampler &mip_sampler; + ProgramData shdata; + bool rendered = false; + bool in_setup_frame = false; + unsigned update_interval = 1; + unsigned update_delay = 0; public: - EnvironmentMap(unsigned size, Renderable &rend, Renderable &env); + EnvironmentMap(unsigned size, PixelFormat, Renderable &content, Renderable &env); + + /** Creates an EnvironmentMap with prefiltering for varying amounts of + roughness. Levels specifies the number of prefilter mipmap levels and must + be valid for the size. */ + EnvironmentMap(unsigned size, PixelFormat, unsigned levels, Renderable &content, Renderable &env); + + /** Sets a fixed position to render the environment map from. This can be + useful if the content renderable does not have a model matrix. */ + void set_fixed_position(const Vector3 &); void set_depth_clip(float, float); + + /** Sets the interval in frames between environment map updates. A value of + 0 means an update is only done when manually requested. */ void set_update_interval(unsigned); + + /** Request that the environment map is updated on the next frame. */ void queue_update(); virtual void setup_frame(Renderer &); virtual void finish_frame(); - virtual void render(Renderer &, const Tag & = Tag()) const; + virtual void render(Renderer &, Tag = Tag()) const; + + virtual void set_debug_name(const std::string &); }; } // namespace GL