]> git.lizzy.rs Git - dragonfireclient.git/blob - src/sky.h
Fix formspec field labels
[dragonfireclient.git] / src / sky.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "irrlichttypes_extrabloated.h"
21 #include <ISceneNode.h>
22 #include "localplayer.h"
23
24 #ifndef SKY_HEADER
25 #define SKY_HEADER
26
27 #define SKY_MATERIAL_COUNT 3
28 #define SKY_STAR_COUNT 200
29
30 // Skybox, rendered with zbuffer turned off, before all other nodes.
31 class Sky : public scene::ISceneNode
32 {
33 public:
34         //! constructor
35         Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id, LocalPlayer* player);
36
37         virtual void OnRegisterSceneNode();
38
39         //! renders the node.
40         virtual void render();
41
42         virtual const core::aabbox3d<f32>& getBoundingBox() const;
43
44         // Used by Irrlicht for optimizing rendering
45         virtual video::SMaterial& getMaterial(u32 i)
46         { return m_materials[i]; }
47
48         // Used by Irrlicht for optimizing rendering
49         virtual u32 getMaterialCount() const
50         { return SKY_MATERIAL_COUNT; }
51
52         void update(float m_time_of_day, float time_brightness,
53                         float direct_brightness, bool sunlight_seen);
54         
55         float getBrightness(){ return m_brightness; }
56         video::SColor getBgColor(){ return m_bgcolor; }
57         video::SColor getSkyColor(){ return m_skycolor; }
58         
59         bool getCloudsVisible(){ return m_clouds_visible; }
60         video::SColorf getCloudColor(){ return m_cloudcolor_f; }
61
62 private:
63         core::aabbox3d<f32> Box;
64         video::SMaterial m_materials[SKY_MATERIAL_COUNT];
65
66         // How much sun & moon transition should affect horizon color
67         float m_horizon_blend()
68         {
69                 if (!m_sunlight_seen)
70                         return 0;
71                 float x; m_time_of_day >= 0.5 ? x = (1 - m_time_of_day) * 2 : x = m_time_of_day * 2;
72                 if (x <= 0.3)
73                         return 0;
74                 if (x <= 0.4) // when the sun and moon are aligned
75                         return (x - 0.3) * 10;
76                 if (x <= 0.5)
77                         return (0.5 - x) * 10;
78                 return 0;
79         }
80
81         // Mix two colors by a given amount
82         video::SColor m_mix_scolor(video::SColor col1, video::SColor col2, f32 factor)
83         {
84                 video::SColor result = video::SColor(
85                         col1.getAlpha() * (1 - factor) + col2.getAlpha() * factor,
86                         col1.getRed() * (1 - factor) + col2.getRed() * factor,
87                         col1.getGreen() * (1 - factor) + col2.getGreen() * factor,
88                         col1.getBlue() * (1 - factor) + col2.getBlue() * factor);
89                 return result;
90         }
91         video::SColorf m_mix_scolorf(video::SColorf col1, video::SColorf col2, f32 factor)
92         {
93                 video::SColorf result = video::SColorf(
94                         col1.r * (1 - factor) + col2.r * factor,
95                         col1.g * (1 - factor) + col2.g * factor,
96                         col1.b * (1 - factor) + col2.b * factor,
97                         col1.a * (1 - factor) + col2.a * factor);
98                 return result;
99         }
100
101         bool m_first_update;
102         float m_time_of_day;
103         float m_time_brightness;
104         bool m_sunlight_seen;
105         float m_brightness;
106         float m_cloud_brightness;
107         bool m_clouds_visible;
108         bool m_directional_colored_fog;
109         video::SColorf m_bgcolor_bright_f;
110         video::SColorf m_skycolor_bright_f;
111         video::SColorf m_cloudcolor_bright_f;
112         video::SColor m_bgcolor;
113         video::SColor m_skycolor;
114         video::SColorf m_cloudcolor_f;
115         v3f m_stars[SKY_STAR_COUNT];
116         u16 m_star_indices[SKY_STAR_COUNT*4];
117         video::S3DVertex m_star_vertices[SKY_STAR_COUNT*4];
118         LocalPlayer* m_player;
119 };
120
121 #endif
122