]> git.tdb.fi Git - libs/gl.git/blob - source/effects/sky.h
Support multiple PipelineStates in Renderer
[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.
17
18 In addition to the background, the transmittance of the sun light is calculated
19 to produce realistic lighting at dawn and dusk.
20
21 Based on the techniques described in "A Scalable and Production Ready Sky and
22 Atmosphere Rendering Technique" by Sébastien Hillaire
23 (https://sebh.github.io/publications/egsr2020.pdf).
24 */
25 class Sky: public Effect
26 {
27 public:
28         struct Planet
29         {
30                 Color rayleigh_scatter;
31                 Color mie_scatter;
32                 Color mie_absorb;
33                 Color ozone_absorb;
34                 float rayleigh_density_decay;
35                 float mie_density_decay;
36                 float ozone_band_center;
37                 float ozone_band_extent;
38                 float atmosphere_thickness;
39                 float planet_radius;
40                 Color ground_albedo;
41
42                 Planet();
43
44                 static Planet earth();
45         };
46
47         struct Template: Effect::Template
48         {
49                 class Loader: public DataFile::DerivedObjectLoader<Template, Effect::Template::Loader>
50                 {
51                 private:
52                         static ActionMap shared_actions;
53
54                 public:
55                         Loader(Template &, Collection &);
56                 private:
57                         virtual void init_actions();
58                 };
59
60                 DirectionalLight *sun = 0;
61
62                 virtual Sky *create(const std::map<std::string, Renderable *> &) const;
63         };
64
65 private:
66         Planet planet;
67         DirectionalLight &sun;
68         RenderTarget transmittance_lookup;
69         const Program &transmittance_shprog;
70         bool transmittance_lookup_dirty;
71         RenderTarget distant;
72         const Program &distant_shprog;
73         const Mesh &fullscreen_mesh;
74         const Program &backdrop_shprog;
75         const Sampler &sampler;
76         const Sampler &wrap_sampler;
77         mutable ProgramData shdata;
78         float view_height;
79         bool rendered;
80
81 public:
82         Sky(Renderable &, DirectionalLight &);
83
84         void set_planet(const Planet &);
85         void set_view_height(float);
86
87         Color get_transmittance(const Vector3 &);
88
89         virtual void setup_frame(Renderer &);
90         virtual void finish_frame();
91         virtual void render(Renderer &, Tag = Tag()) const;
92
93         virtual void set_debug_name(const std::string &);
94 };
95
96 } // namespace GL
97 } // namespace Msp
98
99 #endif