3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
20 #include "irrlichttypes_extrabloated.h"
21 #include <ISceneNode.h>
27 #define SKY_MATERIAL_COUNT 5
28 #define SKY_STAR_COUNT 200
30 // Skybox, rendered with zbuffer turned off, before all other nodes.
31 class Sky : public scene::ISceneNode
35 Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id);
37 virtual void OnRegisterSceneNode();
40 virtual void render();
42 virtual const core::aabbox3d<f32>& getBoundingBox() const;
44 // Used by Irrlicht for optimizing rendering
45 virtual video::SMaterial& getMaterial(u32 i)
46 { return m_materials[i]; }
48 // Used by Irrlicht for optimizing rendering
49 virtual u32 getMaterialCount() const
50 { return SKY_MATERIAL_COUNT; }
52 void update(float m_time_of_day, float time_brightness,
53 float direct_brightness, bool sunlight_seen, CameraMode cam_mode,
54 float yaw, float pitch);
56 float getBrightness(){ return m_brightness; }
58 video::SColor getBgColor(){
59 return m_visible ? m_bgcolor : m_fallback_bg_color;
61 video::SColor getSkyColor(){
62 return m_visible ? m_skycolor : m_fallback_bg_color;
65 bool getCloudsVisible(){ return m_clouds_visible && m_visible; }
66 video::SColorf getCloudColor(){ return m_cloudcolor_f; }
68 void setVisible(bool visible){ m_visible = visible; }
69 void setFallbackBgColor(const video::SColor &fallback_bg_color){
70 m_fallback_bg_color = fallback_bg_color;
74 core::aabbox3d<f32> Box;
75 video::SMaterial m_materials[SKY_MATERIAL_COUNT];
77 // How much sun & moon transition should affect horizon color
78 float m_horizon_blend()
82 float x = m_time_of_day >= 0.5 ? (1 - m_time_of_day) * 2 : m_time_of_day * 2;
86 if (x <= 0.4) // when the sun and moon are aligned
87 return (x - 0.3) * 10;
89 return (0.5 - x) * 10;
93 // Mix two colors by a given amount
94 video::SColor m_mix_scolor(video::SColor col1, video::SColor col2, f32 factor)
96 video::SColor result = video::SColor(
97 col1.getAlpha() * (1 - factor) + col2.getAlpha() * factor,
98 col1.getRed() * (1 - factor) + col2.getRed() * factor,
99 col1.getGreen() * (1 - factor) + col2.getGreen() * factor,
100 col1.getBlue() * (1 - factor) + col2.getBlue() * factor);
103 video::SColorf m_mix_scolorf(video::SColorf col1, video::SColorf col2, f32 factor)
105 video::SColorf result = video::SColorf(
106 col1.r * (1 - factor) + col2.r * factor,
107 col1.g * (1 - factor) + col2.g * factor,
108 col1.b * (1 - factor) + col2.b * factor,
109 col1.a * (1 - factor) + col2.a * factor);
114 video::SColor m_fallback_bg_color; // Used when m_visible=false
117 float m_time_brightness;
118 bool m_sunlight_seen;
120 float m_cloud_brightness;
121 bool m_clouds_visible;
122 bool m_directional_colored_fog;
123 video::SColorf m_bgcolor_bright_f;
124 video::SColorf m_skycolor_bright_f;
125 video::SColorf m_cloudcolor_bright_f;
126 video::SColor m_bgcolor;
127 video::SColor m_skycolor;
128 video::SColorf m_cloudcolor_f;
129 v3f m_stars[SKY_STAR_COUNT];
130 video::S3DVertex m_star_vertices[SKY_STAR_COUNT*4];
131 video::ITexture* m_sun_texture;
132 video::ITexture* m_moon_texture;
133 video::ITexture* m_sun_tonemap;
134 video::ITexture* m_moon_tonemap;