]> git.tdb.fi Git - libs/gl.git/blob - source/effects/sky.h
Support effects and subordinate sequences inside sequence templates
[libs/gl.git] / source / effects / sky.h
1 #ifndef MSP_GL_SKY_H_
2 #define MSP_GL_SKY_H_
3
4 #include "effect.h"
5 #include "programdata.h"
6 #include "rendertarget.h"
7
8 namespace Msp {
9 namespace GL {
10
11 class DirectionalLight;
12 class Mesh;
13 class Program;
14
15 /**
16 Renders a procedurally generated sky at the background.  Based on the paper
17 "A Scalable and Production Ready Sky and Atmosphere Rendering Technique" by
18 Sébastien Hillaire (https://sebh.github.io/publications/egsr2020.pdf).
19 */
20 class Sky: public Effect
21 {
22 public:
23         struct Planet
24         {
25                 Color rayleigh_scatter;
26                 Color mie_scatter;
27                 Color mie_absorb;
28                 Color ozone_absorb;
29                 float rayleigh_density_decay;
30                 float mie_density_decay;
31                 float ozone_band_center;
32                 float ozone_band_extent;
33                 float atmosphere_thickness;
34                 float planet_radius;
35                 Color ground_albedo;
36
37                 Planet();
38
39                 static Planet earth();
40         };
41
42         struct Template: Effect::Template
43         {
44                 class Loader: public DataFile::DerivedObjectLoader<Template, Effect::Template::Loader>
45                 {
46                 private:
47                         static ActionMap shared_actions;
48
49                 public:
50                         Loader(Template &, Collection &);
51                 private:
52                         virtual void init_actions();
53                 };
54
55                 DirectionalLight *sun = 0;
56
57                 virtual Sky *create(const std::map<std::string, Renderable *> &) const;
58         };
59
60 private:
61         Planet planet;
62         DirectionalLight &sun;
63         RenderTarget transmittance_lookup;
64         const Program &transmittance_shprog;
65         bool transmittance_lookup_dirty;
66         RenderTarget distant;
67         const Program &distant_shprog;
68         const Mesh &fullscreen_mesh;
69         const Program &backdrop_shprog;
70         const Sampler &sampler;
71         const Sampler &wrap_sampler;
72         mutable ProgramData shdata;
73         float view_height;
74         bool rendered;
75
76 public:
77         Sky(Renderable &, DirectionalLight &);
78
79         void set_planet(const Planet &);
80         void set_view_height(float);
81
82         Color get_transmittance(const Vector3 &);
83
84         virtual void setup_frame(Renderer &);
85         virtual void finish_frame();
86         virtual void render(Renderer &, Tag = Tag()) const;
87
88         virtual void set_debug_name(const std::string &);
89 };
90
91 } // namespace GL
92 } // namespace Msp
93
94 #endif