]> git.tdb.fi Git - libs/gl.git/blob - source/effects/sky.h
Split the Light class into subclasses by light type
[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 private:
43         Planet planet;
44         DirectionalLight &sun;
45         RenderTarget transmittance_lookup;
46         const Program &transmittance_shprog;
47         bool transmittance_lookup_dirty;
48         RenderTarget distant;
49         const Program &distant_shprog;
50         const Mesh &fullscreen_mesh;
51         const Program &backdrop_shprog;
52         const Sampler &sampler;
53         const Sampler &wrap_sampler;
54         mutable ProgramData shdata;
55         float view_height;
56         bool rendered;
57
58 public:
59         Sky(Renderable &, DirectionalLight &);
60
61         void set_planet(const Planet &);
62         void set_view_height(float);
63
64         Color get_transmittance(const Vector3 &);
65
66         virtual void setup_frame(Renderer &);
67         virtual void finish_frame();
68         virtual void render(Renderer &, Tag = Tag()) const;
69
70         virtual void set_debug_name(const std::string &);
71 };
72
73 } // namespace GL
74 } // namespace Msp
75
76 #endif