]> git.tdb.fi Git - libs/gl.git/blob - source/effects/sky.h
Modify sunlight color based on transmittance of the atmosphere
[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 "framebuffer.h"
6 #include "programdata.h"
7 #include "rendertarget.h"
8
9 namespace Msp {
10 namespace GL {
11
12 class Mesh;
13 class Light;
14 class Program;
15
16 /**
17 Renders a procedurally generated sky at the background.  Based on the paper
18 "A Scalable and Production Ready Sky and Atmosphere Rendering Technique" by
19 Sébastien Hillaire (https://sebh.github.io/publications/egsr2020.pdf).
20 */
21 class Sky: public Effect
22 {
23 public:
24         struct Planet
25         {
26                 Color rayleigh_scatter;
27                 Color mie_scatter;
28                 Color mie_absorb;
29                 Color ozone_absorb;
30                 float rayleigh_density_decay;
31                 float mie_density_decay;
32                 float ozone_band_center;
33                 float ozone_band_extent;
34                 float atmosphere_thickness;
35                 float planet_radius;
36                 Color ground_albedo;
37
38                 Planet();
39
40                 static Planet earth();
41         };
42
43 private:
44         Planet planet;
45         Light &sun;
46         RenderTarget transmittance_lookup;
47         const Program &transmittance_shprog;
48         bool transmittance_lookup_dirty;
49         RenderTarget distant;
50         const Program &distant_shprog;
51         const Mesh &fullscreen_mesh;
52         const Program &backdrop_shprog;
53         const Sampler &sampler;
54         const Sampler &wrap_sampler;
55         mutable ProgramData shdata;
56         float view_height;
57         bool rendered;
58
59 public:
60         Sky(Renderable &, Light &);
61
62         void set_planet(const Planet &);
63         void set_view_height(float);
64
65         Color get_transmittance(const Vector3 &);
66
67         virtual void setup_frame(Renderer &);
68         virtual void finish_frame();
69         virtual void render(Renderer &, Tag = Tag()) const;
70 };
71
72 } // namespace GL
73 } // namespace Msp
74
75 #endif