]> git.tdb.fi Git - libs/gl.git/blob - source/effects/sky.h
Access builtin resources through a global instance
[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         const Light &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         bool rendered;
56
57 public:
58         Sky(Renderable &, const Light &);
59
60         void set_planet(const Planet &);
61         void set_view_height(float);
62
63         virtual void setup_frame(Renderer &);
64         virtual void finish_frame();
65         virtual void render(Renderer &, Tag = Tag()) const;
66 };
67
68 } // namespace GL
69 } // namespace Msp
70
71 #endif