X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Feffects%2Fsky.h;fp=source%2Feffects%2Fsky.h;h=eb4f618d9607569bcdb32a9151a44ebf7442d8bd;hb=06d83c11e10208478487dea864ddd7822630c391;hp=0000000000000000000000000000000000000000;hpb=e98956208676c77e74462f17932ac530077a0540;p=libs%2Fgl.git diff --git a/source/effects/sky.h b/source/effects/sky.h new file mode 100644 index 00000000..eb4f618d --- /dev/null +++ b/source/effects/sky.h @@ -0,0 +1,73 @@ +#ifndef MSP_GL_SKY_H_ +#define MSP_GL_SKY_H_ + +#include "effect.h" +#include "framebuffer.h" +#include "programdata.h" +#include "texture2d.h" + +namespace Msp { +namespace GL { + +class Mesh; +class Light; +class Program; + +/** +Renders a procedurally generated sky at the background. Based on the paper +"A Scalable and Production Ready Sky and Atmosphere Rendering Technique" by +Sébastien Hillaire (https://sebh.github.io/publications/egsr2020.pdf). +*/ +class Sky: public Effect +{ +public: + struct Planet + { + Color rayleigh_scatter; + Color mie_scatter; + Color mie_absorb; + Color ozone_absorb; + float rayleigh_density_decay; + float mie_density_decay; + float ozone_band_center; + float ozone_band_extent; + float atmosphere_thickness; + float planet_radius; + Color ground_albedo; + + Planet(); + + static Planet earth(); + }; + +private: + const Light &sun; + Texture2D transmittance_lookup; + const Program &transmittance_shprog; + Framebuffer transmittance_fbo; + bool transmittance_lookup_dirty; + Texture2D distant; + const Program &distant_shprog; + Framebuffer distant_fbo; + const Mesh &fullscreen_mesh; + const Program &backdrop_shprog; + const Sampler &sampler; + const Sampler &wrap_sampler; + mutable ProgramData shdata; + bool rendered; + +public: + Sky(Resources &, Renderable &, const Light &); + + void set_planet(const Planet &); + void set_view_height(float); + + virtual void setup_frame(Renderer &); + virtual void finish_frame(); + virtual void render(Renderer &, Tag = Tag()) const; +}; + +} // namespace GL +} // namespace Msp + +#endif