+/*
+Minetest
+Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
#include "sky.h"
#include "IVideoDriver.h"
#include "ISceneManager.h"
#include "profiler.h"
#include "util/numeric.h"
#include <cmath>
+#include "client/renderingengine.h"
#include "settings.h"
#include "camera.h" // CameraModes
-Sky::Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id,
- ITextureSource *tsrc):
- scene::ISceneNode(parent, mgr, id),
- m_visible(true),
- m_fallback_bg_color(255, 255, 255, 255),
- m_first_update(true),
- m_brightness(0.5),
- m_cloud_brightness(0.5),
- m_bgcolor_bright_f(1, 1, 1, 1),
- m_skycolor_bright_f(1, 1, 1, 1),
- m_cloudcolor_bright_f(1, 1, 1, 1)
+Sky::Sky(s32 id, ITextureSource *tsrc):
+ scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(),
+ RenderingEngine::get_scene_manager(), id)
{
setAutomaticCulling(scene::EAC_OFF);
m_box.MaxEdge.set(0, 0, 0);
m_materials[4].Lighting = true;
}
- for (u32 i = 0; i < SKY_STAR_COUNT; i++) {
- m_stars[i] = v3f(
+ for (v3f &star : m_stars) {
+ star = v3f(
myrand_range(-10000, 10000),
myrand_range(-10000, 10000),
myrand_range(-10000, 10000)
);
- m_stars[i].normalize();
+ star.normalize();
}
m_directional_colored_fog = g_settings->getBool("directional_colored_fog");
if (!camera || !driver)
return;
-
+
ScopeProfiler sp(g_profiler, "Sky::render()", SPT_AVG);
// Draw perspective skybox
if (m_sunlight_seen) {
float sunsize = 0.07;
video::SColorf suncolor_f(1, 1, 0, 1);
- suncolor_f.r = 1;
- suncolor_f.g = MYMAX(0.3, MYMIN(1.0, 0.7 + m_time_brightness * 0.5));
- suncolor_f.b = MYMAX(0.0, m_brightness * 0.95);
+ //suncolor_f.r = 1;
+ //suncolor_f.g = MYMAX(0.3, MYMIN(1.0, 0.7 + m_time_brightness * 0.5));
+ //suncolor_f.b = MYMAX(0.0, m_brightness * 0.95);
video::SColorf suncolor2_f(1, 1, 1, 1);
+ // The values below were probably meant to be suncolor2_f instead of a
+ // reassignment of suncolor_f. However, the resulting colour was chosen
+ // and is our long-running classic colour. So preserve, but comment-out
+ // the unnecessary first assignments above.
suncolor_f.r = 1;
suncolor_f.g = MYMAX(0.3, MYMIN(1.0, 0.85 + m_time_brightness * 0.5));
suncolor_f.b = MYMAX(0.0, m_brightness);
float moonsize = 0.04;
video::SColorf mooncolor_f(0.50, 0.57, 0.65, 1);
video::SColorf mooncolor2_f(0.85, 0.875, 0.9, 1);
-
+
float nightlength = 0.415;
float wn = nightlength / 2;
float wicked_time_of_day = 0;
const f32 o = 0.0f;
static const u16 indices[4] = {0, 1, 2, 3};
video::S3DVertex vertices[4];
-
+
driver->setMaterial(m_materials[1]);
-
+
video::SColor cloudyfogcolor = m_bgcolor;
-
+
// Draw far cloudy fog thing blended with skycolor
for (u32 j = 0; j < 4; j++) {
video::SColor c = cloudyfogcolor.getInterpolated(m_skycolor, 0.45);
vertices[1] = video::S3DVertex( 1, 0.08, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( 1, 0.12, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-1, 0.12, -1, 0, 0, 1, c, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
if (j == 0)
// Don't switch
{}
else if (j == 1)
// Switch from -Z (south) to +X (east)
- vertices[i].Pos.rotateXZBy(90);
+ vertex.Pos.rotateXZBy(90);
else if (j == 2)
// Switch from -Z (south) to -X (west)
- vertices[i].Pos.rotateXZBy(-90);
+ vertex.Pos.rotateXZBy(-90);
else
// Switch from -Z (south) to +Z (north)
- vertices[i].Pos.rotateXZBy(-180);
+ vertex.Pos.rotateXZBy(-180);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
vertices[1] = video::S3DVertex( 1, -1.0, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( 1, 0.08, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-1, 0.08, -1, 0, 0, 1, c, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
if (j == 0)
// Don't switch
{}
else if (j == 1)
// Switch from -Z (south) to +X (east)
- vertices[i].Pos.rotateXZBy(90);
+ vertex.Pos.rotateXZBy(90);
else if (j == 2)
// Switch from -Z (south) to -X (west)
- vertices[i].Pos.rotateXZBy(-90);
+ vertex.Pos.rotateXZBy(-90);
else
// Switch from -Z (south) to +Z (north)
- vertices[i].Pos.rotateXZBy(-180);
+ vertex.Pos.rotateXZBy(-180);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
+ // Draw bottom far cloudy fog thing
+ video::SColor c = cloudyfogcolor;
+ vertices[0] = video::S3DVertex(-1, -1.0, -1, 0, 1, 0, c, t, t);
+ vertices[1] = video::S3DVertex( 1, -1.0, -1, 0, 1, 0, c, o, t);
+ vertices[2] = video::S3DVertex( 1, -1.0, 1, 0, 1, 0, c, o, o);
+ vertices[3] = video::S3DVertex(-1, -1.0, 1, 0, 1, 0, c, t, o);
+ driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+
+ // If sun, moon and stars are (temporarily) disabled, abort here
+ if (!m_bodies_visible)
+ return;
+
driver->setMaterial(m_materials[2]);
// Draw sunrise/sunset horizon glow texture (textures/base/pack/sunrisebg.png)
{
float mid1 = 0.25;
float mid = wicked_time_of_day < 0.5 ? mid1 : (1.0 - mid1);
- float a_ = 1.0 - fabs(wicked_time_of_day - mid) * 35.0;
+ float a_ = 1.0f - std::fabs(wicked_time_of_day - mid) * 35.0f;
float a = easeCurve(MYMAX(0, MYMIN(1, a_)));
//std::cerr<<"a_="<<a_<<" a="<<a<<std::endl;
video::SColor c(255, 255, 255, 255);
vertices[1] = video::S3DVertex( 1, -0.05 + y, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( 1, 0.2 + y, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-1, 0.2 + y, -1, 0, 0, 1, c, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
if (wicked_time_of_day < 0.5)
// Switch from -Z (south) to +X (east)
- vertices[i].Pos.rotateXZBy(90);
+ vertex.Pos.rotateXZBy(90);
else
// Switch from -Z (south) to -X (west)
- vertices[i].Pos.rotateXZBy(-90);
+ vertex.Pos.rotateXZBy(-90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( d, d, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-d, d, -1, 0, 0, 1, c, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to +X (east)
- vertices[i].Pos.rotateXZBy(90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( d, d, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-d, d, -1, 0, 0, 1, c, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to +X (east)
- vertices[i].Pos.rotateXZBy(90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, suncolor, o, t);
vertices[2] = video::S3DVertex( d, d, -1, 0, 0, 1, suncolor, o, o);
vertices[3] = video::S3DVertex(-d, d, -1, 0, 0, 1, suncolor, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to +X (east)
- vertices[i].Pos.rotateXZBy(90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, suncolor2, o, t);
vertices[2] = video::S3DVertex( d, d, -1, 0, 0, 1, suncolor2, o, o);
vertices[3] = video::S3DVertex(-d, d, -1, 0, 0, 1, suncolor2, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to +X (east)
- vertices[i].Pos.rotateXZBy(90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
} else {
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( d, d, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-d, d, -1, 0, 0, 1, c, t, o);
- for(u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to +X (east)
- vertices[i].Pos.rotateXZBy(90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( d, d, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-d, d, -1, 0, 0, 1, c, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to -X (west)
- vertices[i].Pos.rotateXZBy(-90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(-90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
-
+
d = moonsize * 1.3;
c = mooncolor;
c.setAlpha(0.15 * 255);
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( d, d, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-d, d, -1, 0, 0, 1, c, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to -X (west)
- vertices[i].Pos.rotateXZBy(-90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(-90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, mooncolor, o, t);
vertices[2] = video::S3DVertex( d, d, -1, 0, 0, 1, mooncolor, o, o);
vertices[3] = video::S3DVertex(-d, d, -1, 0, 0, 1, mooncolor, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to -X (west)
- vertices[i].Pos.rotateXZBy(-90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(-90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
vertices[1] = video::S3DVertex( d2,-d, -1, 0, 0, 1, mooncolor2, o, t);
vertices[2] = video::S3DVertex( d2, d2, -1, 0, 0, 1, mooncolor2, o, o);
vertices[3] = video::S3DVertex(-d, d2, -1, 0, 0, 1, mooncolor2, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to -X (west)
- vertices[i].Pos.rotateXZBy(-90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(-90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
} else {
vertices[1] = video::S3DVertex( d, -d, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( d, d, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-d, d, -1, 0, 0, 1, c, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
// Switch from -Z (south) to -X (west)
- vertices[i].Pos.rotateXZBy(-90);
- vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
+ vertex.Pos.rotateXZBy(-90);
+ vertex.Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
}
// Draw stars
- driver->setMaterial(m_materials[1]);
do {
+ driver->setMaterial(m_materials[1]);
float starbrightness = MYMAX(0, MYMIN(1,
(0.285 - fabs(wicked_time_of_day < 0.5 ?
wicked_time_of_day : (1.0 - wicked_time_of_day))) * 10));
driver->drawVertexPrimitiveList(vertices, SKY_STAR_COUNT * 4,
indices, SKY_STAR_COUNT, video::EVT_STANDARD,
scene::EPT_QUADS, video::EIT_16BIT);
- } while(0);
-
+ } while(false);
+
// Draw far cloudy fog thing below east and west horizons
for (u32 j = 0; j < 2; j++) {
video::SColor c = cloudyfogcolor;
vertices[1] = video::S3DVertex( 1, -1.0, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( 1, -0.02, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-1, -0.02, -1, 0, 0, 1, c, t, o);
- for (u32 i = 0; i < 4; i++) {
+ for (video::S3DVertex &vertex : vertices) {
//if (wicked_time_of_day < 0.5)
if (j == 0)
// Switch from -Z (south) to +X (east)
- vertices[i].Pos.rotateXZBy(90);
+ vertex.Pos.rotateXZBy(90);
else
// Switch from -Z (south) to -X (west)
- vertices[i].Pos.rotateXZBy(-90);
+ vertex.Pos.rotateXZBy(-90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
m_time_of_day = time_of_day;
m_time_brightness = time_brightness;
m_sunlight_seen = sunlight_seen;
-
+ m_bodies_visible = true;
+
bool is_dawn = (time_brightness >= 0.20 && time_brightness < 0.35);
/*
video::SColorf skycolor_bright_normal_f = video::SColor(255, 140, 186, 250);
video::SColorf skycolor_bright_dawn_f = video::SColor(255, 180, 186, 250);
video::SColorf skycolor_bright_night_f = video::SColor(255, 0, 107, 255);
-
- video::SColorf cloudcolor_bright_normal_f = video::SColor(255, 240, 240, 255);
- video::SColorf cloudcolor_bright_dawn_f = video::SColor(255, 255, 223, 191);
+
+ // pure white: becomes "diffuse light component" for clouds
+ video::SColorf cloudcolor_bright_normal_f = video::SColor(255, 255, 255, 255);
+ // dawn-factoring version of pure white (note: R is above 1.0)
+ video::SColorf cloudcolor_bright_dawn_f(255.0f/240.0f, 223.0f/240.0f, 191.0f/255.0f);
float cloud_color_change_fraction = 0.95;
if (sunlight_seen) {
- if (fabs(time_brightness - m_brightness) < 0.2) {
+ if (std::fabs(time_brightness - m_brightness) < 0.2f) {
m_brightness = m_brightness * 0.95 + time_brightness * 0.05;
} else {
m_brightness = m_brightness * 0.80 + time_brightness * 0.20;
else
m_brightness = m_brightness * 0.98 + direct_brightness * 0.02;
}
-
+
m_clouds_visible = true;
float color_change_fraction = 0.98;
if (sunlight_seen) {
);
// Horizon coloring based on sun and moon direction during sunset and sunrise
- video::SColor pointcolor = video::SColor(255, 255, 255, m_bgcolor.getAlpha());
+ video::SColor pointcolor = video::SColor(m_bgcolor.getAlpha(), 255, 255, 255);
if (m_directional_colored_fog) {
if (m_horizon_blend() != 0) {
// Calculate hemisphere value from yaw, (inverted in third person front view)