2 #include "IVideoDriver.h"
3 #include "ISceneManager.h"
4 #include "ICameraSceneNode.h"
6 #include "tile.h" // getTexturePath
7 #include "noise.h" // easeCurve
8 #include "main.h" // g_profiler
10 #include "util/numeric.h" // MYMIN
13 #include "camera.h" // CameraModes
16 Sky::Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id, LocalPlayer* player):
17 scene::ISceneNode(parent, mgr, id),
19 m_fallback_bg_color(255,255,255,255),
22 m_cloud_brightness(0.5),
23 m_bgcolor_bright_f(1,1,1,1),
24 m_skycolor_bright_f(1,1,1,1),
25 m_cloudcolor_bright_f(1,1,1,1),
28 setAutomaticCulling(scene::EAC_OFF);
29 Box.MaxEdge.set(0,0,0);
30 Box.MinEdge.set(0,0,0);
36 mat.ZBuffer = video::ECFN_NEVER;
37 mat.ZWriteEnable = false;
39 mat.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
40 mat.TextureLayer[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
41 mat.BackfaceCulling = false;
46 //m_materials[1].MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
47 m_materials[1].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
50 m_materials[2].setTexture(0, mgr->getVideoDriver()->getTexture(
51 getTexturePath("sunrisebg.png").c_str()));
52 m_materials[2].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
53 //m_materials[2].MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
55 m_sun_texture = mgr->getVideoDriver()->getTexture(
56 getTexturePath("sun.png").c_str());
57 m_moon_texture = mgr->getVideoDriver()->getTexture(
58 getTexturePath("moon.png").c_str());
59 m_sun_tonemap = mgr->getVideoDriver()->getTexture(
60 getTexturePath("sun_tonemap.png").c_str());
61 m_moon_tonemap = mgr->getVideoDriver()->getTexture(
62 getTexturePath("moon_tonemap.png").c_str());
66 m_materials[3].setTexture(0, m_sun_texture);
67 m_materials[3].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
69 m_materials[3].Lighting = true;
73 m_materials[4].setTexture(0, m_moon_texture);
74 m_materials[4].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
76 m_materials[4].Lighting = true;
79 for(u32 i=0; i<SKY_STAR_COUNT; i++){
81 myrand_range(-10000,10000),
82 myrand_range(-10000,10000),
83 myrand_range(-10000,10000)
85 m_stars[i].normalize();
88 m_directional_colored_fog = g_settings->getBool("directional_colored_fog");
91 void Sky::OnRegisterSceneNode()
94 SceneManager->registerNodeForRendering(this, scene::ESNRP_SKY_BOX);
96 scene::ISceneNode::OnRegisterSceneNode();
99 const core::aabbox3d<f32>& Sky::getBoundingBox() const
104 //! renders the node.
110 video::IVideoDriver* driver = SceneManager->getVideoDriver();
111 scene::ICameraSceneNode* camera = SceneManager->getActiveCamera();
113 if (!camera || !driver)
116 ScopeProfiler sp(g_profiler, "Sky::render()", SPT_AVG);
118 // draw perspective skybox
120 core::matrix4 translate(AbsoluteTransformation);
121 translate.setTranslation(camera->getAbsolutePosition());
123 // Draw the sky box between the near and far clip plane
124 const f32 viewDistance = (camera->getNearValue() + camera->getFarValue()) * 0.5f;
126 scale.setScale(core::vector3df(viewDistance, viewDistance, viewDistance));
128 driver->setTransform(video::ETS_WORLD, translate * scale);
132 float sunsize = 0.07;
133 video::SColorf suncolor_f(1, 1, 0, 1);
135 suncolor_f.g = MYMAX(0.3, MYMIN(1.0, 0.7+m_time_brightness*(0.5)));
136 suncolor_f.b = MYMAX(0.0, m_brightness*0.95);
137 video::SColorf suncolor2_f(1, 1, 1, 1);
139 suncolor_f.g = MYMAX(0.3, MYMIN(1.0, 0.85+m_time_brightness*(0.5)));
140 suncolor_f.b = MYMAX(0.0, m_brightness);
142 float moonsize = 0.04;
143 video::SColorf mooncolor_f(0.50, 0.57, 0.65, 1);
144 video::SColorf mooncolor2_f(0.85, 0.875, 0.9, 1);
146 float nightlength = 0.415;
147 float wn = nightlength / 2;
148 float wicked_time_of_day = 0;
149 if(m_time_of_day > wn && m_time_of_day < 1.0 - wn)
150 wicked_time_of_day = (m_time_of_day - wn)/(1.0-wn*2)*0.5 + 0.25;
151 else if(m_time_of_day < 0.5)
152 wicked_time_of_day = m_time_of_day / wn * 0.25;
154 wicked_time_of_day = 1.0 - ((1.0-m_time_of_day) / wn * 0.25);
155 /*std::cerr<<"time_of_day="<<m_time_of_day<<" -> "
156 <<"wicked_time_of_day="<<wicked_time_of_day<<std::endl;*/
158 video::SColor suncolor = suncolor_f.toSColor();
159 video::SColor suncolor2 = suncolor2_f.toSColor();
160 video::SColor mooncolor = mooncolor_f.toSColor();
161 video::SColor mooncolor2 = mooncolor2_f.toSColor();
163 // Calculate offset normalized to the X dimension of a 512x1 px tonemap
164 float offset=(1.0-fabs(sin((m_time_of_day - 0.5)*irr::core::PI)))*511;
167 u8 * texels = (u8 *)m_sun_tonemap->lock();
168 video::SColor* texel = (video::SColor *)(texels + (u32)offset * 4);
169 video::SColor texel_color (255,texel->getRed(),texel->getGreen(), texel->getBlue());
170 m_sun_tonemap->unlock();
171 m_materials[3].EmissiveColor = texel_color;
174 u8 * texels = (u8 *)m_moon_tonemap->lock();
175 video::SColor* texel = (video::SColor *)(texels + (u32)offset * 4);
176 video::SColor texel_color (255,texel->getRed(),texel->getGreen(), texel->getBlue());
177 m_moon_tonemap->unlock();
178 m_materials[4].EmissiveColor = texel_color;
183 static const u16 indices[4] = {0,1,2,3};
184 video::S3DVertex vertices[4];
186 driver->setMaterial(m_materials[1]);
188 //video::SColor cloudyfogcolor(255,255,255,255);
189 video::SColor cloudyfogcolor = m_bgcolor;
190 //video::SColor cloudyfogcolor = m_bgcolor.getInterpolated(m_skycolor, 0.5);
192 // Draw far cloudy fog thing
193 for(u32 j=0; j<4; j++)
195 video::SColor c = cloudyfogcolor.getInterpolated(m_skycolor, 0.45);
196 vertices[0] = video::S3DVertex(-1, 0.08,-1, 0,0,1, c, t, t);
197 vertices[1] = video::S3DVertex( 1, 0.08,-1, 0,0,1, c, o, t);
198 vertices[2] = video::S3DVertex( 1, 0.12,-1, 0,0,1, c, o, o);
199 vertices[3] = video::S3DVertex(-1, 0.12,-1, 0,0,1, c, t, o);
200 for(u32 i=0; i<4; i++){
205 // Switch from -Z (south) to +X (east)
206 vertices[i].Pos.rotateXZBy(90);
208 // Switch from -Z (south) to -X (west)
209 vertices[i].Pos.rotateXZBy(-90);
211 // Switch from -Z (south) to -Z (north)
212 vertices[i].Pos.rotateXZBy(-180);
214 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
216 for(u32 j=0; j<4; j++)
218 video::SColor c = cloudyfogcolor;
219 vertices[0] = video::S3DVertex(-1,-1.0,-1, 0,0,1, c, t, t);
220 vertices[1] = video::S3DVertex( 1,-1.0,-1, 0,0,1, c, o, t);
221 vertices[2] = video::S3DVertex( 1, 0.08,-1, 0,0,1, c, o, o);
222 vertices[3] = video::S3DVertex(-1, 0.08,-1, 0,0,1, c, t, o);
223 for(u32 i=0; i<4; i++){
228 // Switch from -Z (south) to +X (east)
229 vertices[i].Pos.rotateXZBy(90);
231 // Switch from -Z (south) to -X (west)
232 vertices[i].Pos.rotateXZBy(-90);
234 // Switch from -Z (south) to -Z (north)
235 vertices[i].Pos.rotateXZBy(-180);
237 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
240 driver->setMaterial(m_materials[2]);
244 float mid = (wicked_time_of_day < 0.5 ? mid1 : (1.0 - mid1));
245 float a_ = 1.0 - fabs(wicked_time_of_day - mid) * 35.0;
246 float a = easeCurve(MYMAX(0, MYMIN(1, a_)));
247 //std::cerr<<"a_="<<a_<<" a="<<a<<std::endl;
248 video::SColor c(255,255,255,255);
249 float y = -(1.0 - a) * 0.2;
250 vertices[0] = video::S3DVertex(-1,-0.05+y,-1, 0,0,1, c, t, t);
251 vertices[1] = video::S3DVertex( 1,-0.05+y,-1, 0,0,1, c, o, t);
252 vertices[2] = video::S3DVertex( 1, 0.2+y,-1, 0,0,1, c, o, o);
253 vertices[3] = video::S3DVertex(-1, 0.2+y,-1, 0,0,1, c, t, o);
254 for(u32 i=0; i<4; i++){
255 if(wicked_time_of_day < 0.5)
256 // Switch from -Z (south) to +X (east)
257 vertices[i].Pos.rotateXZBy(90);
259 // Switch from -Z (south) to -X (west)
260 vertices[i].Pos.rotateXZBy(-90);
262 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
266 if(wicked_time_of_day > 0.15 && wicked_time_of_day < 0.85){
268 driver->setMaterial(m_materials[1]);
269 float d = sunsize * 1.7;
270 video::SColor c = suncolor;
271 c.setAlpha(0.05*255);
272 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
273 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
274 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
275 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
276 for(u32 i=0; i<4; i++){
277 // Switch from -Z (south) to +X (east)
278 vertices[i].Pos.rotateXZBy(90);
279 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
281 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
285 c.setAlpha(0.15*255);
286 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
287 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
288 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
289 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
290 for(u32 i=0; i<4; i++){
291 // Switch from -Z (south) to +X (east)
292 vertices[i].Pos.rotateXZBy(90);
293 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
295 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
298 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, suncolor, t, t);
299 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, suncolor, o, t);
300 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, suncolor, o, o);
301 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, suncolor, t, o);
302 for(u32 i=0; i<4; i++){
303 // Switch from -Z (south) to +X (east)
304 vertices[i].Pos.rotateXZBy(90);
305 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
307 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
310 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, suncolor2, t, t);
311 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, suncolor2, o, t);
312 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, suncolor2, o, o);
313 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, suncolor2, t, o);
314 for(u32 i=0; i<4; i++){
315 // Switch from -Z (south) to +X (east)
316 vertices[i].Pos.rotateXZBy(90);
317 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
319 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
321 driver->setMaterial(m_materials[3]);
322 float d = sunsize * 1.7;
325 c = video::SColor (0,0,0,0);
327 c = video::SColor (255,255,255,255);
328 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
329 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
330 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
331 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
332 for(u32 i=0; i<4; i++){
333 // Switch from -Z (south) to +X (east)
334 vertices[i].Pos.rotateXZBy(90);
335 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
337 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
342 if(wicked_time_of_day < 0.3 || wicked_time_of_day > 0.7)
344 if (!m_moon_texture){
345 driver->setMaterial(m_materials[1]);
346 float d = moonsize * 1.9;
347 video::SColor c = mooncolor;
348 c.setAlpha(0.05*255);
349 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
350 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
351 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
352 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
353 for(u32 i=0; i<4; i++){
354 // Switch from -Z (south) to -X (west)
355 vertices[i].Pos.rotateXZBy(-90);
356 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
358 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
362 c.setAlpha(0.15*255);
363 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
364 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
365 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
366 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
367 for(u32 i=0; i<4; i++){
368 // Switch from -Z (south) to -X (west)
369 vertices[i].Pos.rotateXZBy(-90);
370 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
372 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
375 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, mooncolor, t, t);
376 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, mooncolor, o, t);
377 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, mooncolor, o, o);
378 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, mooncolor, t, o);
379 for(u32 i=0; i<4; i++){
380 // Switch from -Z (south) to -X (west)
381 vertices[i].Pos.rotateXZBy(-90);
382 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
384 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
386 float d2 = moonsize * 0.6;
387 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, mooncolor2, t, t);
388 vertices[1] = video::S3DVertex( d2,-d,-1, 0,0,1, mooncolor2, o, t);
389 vertices[2] = video::S3DVertex( d2, d2,-1, 0,0,1, mooncolor2, o, o);
390 vertices[3] = video::S3DVertex(-d, d2,-1, 0,0,1, mooncolor2, t, o);
391 for(u32 i=0; i<4; i++){
392 // Switch from -Z (south) to -X (west)
393 vertices[i].Pos.rotateXZBy(-90);
394 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
396 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
398 driver->setMaterial(m_materials[4]);
399 float d = moonsize * 1.9;
402 c = video::SColor (0,0,0,0);
404 c = video::SColor (255,255,255,255);
405 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
406 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
407 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
408 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
409 for(u32 i=0; i<4; i++){
410 // Switch from -Z (south) to -X (west)
411 vertices[i].Pos.rotateXZBy(-90);
412 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
414 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
419 driver->setMaterial(m_materials[1]);
421 float starbrightness = MYMAX(0, MYMIN(1,
422 (0.285 - fabs(wicked_time_of_day < 0.5 ?
423 wicked_time_of_day : (1.0 - wicked_time_of_day))) * 10));
424 float f = starbrightness;
426 video::SColor starcolor(255, f*90,f*90,f*90);
427 if(starcolor.getBlue() < m_skycolor.getBlue())
429 u16 indices[SKY_STAR_COUNT*4];
430 video::S3DVertex vertices[SKY_STAR_COUNT*4];
431 for(u32 i=0; i<SKY_STAR_COUNT; i++){
432 indices[i*4+0] = i*4+0;
433 indices[i*4+1] = i*4+1;
434 indices[i*4+2] = i*4+2;
435 indices[i*4+3] = i*4+3;
437 core::CMatrix4<f32> a;
438 a.buildRotateFromTo(v3f(0,1,0), v3f(d,1+d/2,0));
441 a.buildRotateFromTo(v3f(0,1,0), v3f(d,1,d));
444 a.buildRotateFromTo(v3f(0,1,0), v3f(0,1-d/2,d));
447 p.rotateXYBy(wicked_time_of_day * 360 - 90);
448 p1.rotateXYBy(wicked_time_of_day * 360 - 90);
449 p2.rotateXYBy(wicked_time_of_day * 360 - 90);
450 p3.rotateXYBy(wicked_time_of_day * 360 - 90);
451 vertices[i*4+0].Pos = p;
452 vertices[i*4+0].Color = starcolor;
453 vertices[i*4+1].Pos = p1;
454 vertices[i*4+1].Color = starcolor;
455 vertices[i*4+2].Pos = p2;
456 vertices[i*4+2].Color = starcolor;
457 vertices[i*4+3].Pos = p3;
458 vertices[i*4+3].Color = starcolor;
460 driver->drawVertexPrimitiveList(vertices, SKY_STAR_COUNT*4,
461 indices, SKY_STAR_COUNT, video::EVT_STANDARD,
462 scene::EPT_QUADS, video::EIT_16BIT);
465 for(u32 j=0; j<2; j++)
467 //video::SColor c = m_skycolor;
468 video::SColor c = cloudyfogcolor;
469 vertices[0] = video::S3DVertex(-1,-1.0,-1, 0,0,1, c, t, t);
470 vertices[1] = video::S3DVertex( 1,-1.0,-1, 0,0,1, c, o, t);
471 vertices[2] = video::S3DVertex( 1,-0.02,-1, 0,0,1, c, o, o);
472 vertices[3] = video::S3DVertex(-1,-0.02,-1, 0,0,1, c, t, o);
473 for(u32 i=0; i<4; i++){
474 //if(wicked_time_of_day < 0.5)
476 // Switch from -Z (south) to +X (east)
477 vertices[i].Pos.rotateXZBy(90);
479 // Switch from -Z (south) to -X (west)
480 vertices[i].Pos.rotateXZBy(-90);
482 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
487 void Sky::update(float time_of_day, float time_brightness,
488 float direct_brightness, bool sunlight_seen)
490 // Stabilize initial brightness and color values by flooding updates
492 /*dstream<<"First update with time_of_day="<<time_of_day
493 <<" time_brightness="<<time_brightness
494 <<" direct_brightness="<<direct_brightness
495 <<" sunlight_seen="<<sunlight_seen<<std::endl;*/
496 m_first_update = false;
497 for(u32 i=0; i<100; i++){
498 update(time_of_day, time_brightness, direct_brightness,
504 m_time_of_day = time_of_day;
505 m_time_brightness = time_brightness;
506 m_sunlight_seen = sunlight_seen;
508 bool is_dawn = (time_brightness >= 0.20 && time_brightness < 0.35);
510 //video::SColorf bgcolor_bright_normal_f(170./255,200./255,230./255, 1.0);
511 video::SColorf bgcolor_bright_normal_f(155./255,193./255,240./255, 1.0);
512 video::SColorf bgcolor_bright_indoor_f(100./255,100./255,100./255, 1.0);
513 //video::SColorf bgcolor_bright_dawn_f(0.666,200./255*0.7,230./255*0.5,1.0);
514 //video::SColorf bgcolor_bright_dawn_f(0.666,0.549,0.220,1.0);
515 //video::SColorf bgcolor_bright_dawn_f(0.666*1.2,0.549*1.0,0.220*1.0, 1.0);
516 //video::SColorf bgcolor_bright_dawn_f(0.666*1.2,0.549*1.0,0.220*1.2,1.0);
517 video::SColorf bgcolor_bright_dawn_f
518 (155./255*1.2,193./255,240./255, 1.0);
520 video::SColorf skycolor_bright_normal_f =
521 video::SColor(255, 140, 186, 250);
522 video::SColorf skycolor_bright_dawn_f =
523 video::SColor(255, 180, 186, 250);
525 video::SColorf cloudcolor_bright_normal_f =
526 video::SColor(255, 240,240,255);
527 //video::SColorf cloudcolor_bright_dawn_f(1.0, 0.591, 0.4);
528 //video::SColorf cloudcolor_bright_dawn_f(1.0, 0.65, 0.44);
529 //video::SColorf cloudcolor_bright_dawn_f(1.0, 0.7, 0.5);
530 video::SColorf cloudcolor_bright_dawn_f(1.0, 0.875, 0.75);
532 float cloud_color_change_fraction = 0.95;
534 if(fabs(time_brightness - m_brightness) < 0.2){
535 m_brightness = m_brightness * 0.95 + time_brightness * 0.05;
537 m_brightness = m_brightness * 0.80 + time_brightness * 0.20;
538 cloud_color_change_fraction = 0.0;
542 if(direct_brightness < m_brightness)
543 m_brightness = m_brightness * 0.95 + direct_brightness * 0.05;
545 m_brightness = m_brightness * 0.98 + direct_brightness * 0.02;
548 m_clouds_visible = true;
549 float color_change_fraction = 0.98;
552 m_bgcolor_bright_f = m_bgcolor_bright_f.getInterpolated(
553 bgcolor_bright_dawn_f, color_change_fraction);
554 m_skycolor_bright_f = m_skycolor_bright_f.getInterpolated(
555 skycolor_bright_dawn_f, color_change_fraction);
556 m_cloudcolor_bright_f = m_cloudcolor_bright_f.getInterpolated(
557 cloudcolor_bright_dawn_f, color_change_fraction);
559 m_bgcolor_bright_f = m_bgcolor_bright_f.getInterpolated(
560 bgcolor_bright_normal_f, color_change_fraction);
561 m_skycolor_bright_f = m_skycolor_bright_f.getInterpolated(
562 skycolor_bright_normal_f, color_change_fraction);
563 m_cloudcolor_bright_f = m_cloudcolor_bright_f.getInterpolated(
564 cloudcolor_bright_normal_f, color_change_fraction);
567 m_bgcolor_bright_f = m_bgcolor_bright_f.getInterpolated(
568 bgcolor_bright_indoor_f, color_change_fraction);
569 m_skycolor_bright_f = m_skycolor_bright_f.getInterpolated(
570 bgcolor_bright_indoor_f, color_change_fraction);
571 m_cloudcolor_bright_f = m_cloudcolor_bright_f.getInterpolated(
572 cloudcolor_bright_normal_f, color_change_fraction);
573 m_clouds_visible = false;
576 // Horizon coloring based on sun and moon direction during sunset and sunrise
577 video::SColor pointcolor = video::SColor(255, 255, 255, m_bgcolor.getAlpha());
578 if (m_directional_colored_fog) {
579 if (m_horizon_blend() != 0)
581 // calculate hemisphere value from yaw, (inverted in third person front view)
583 if (m_player->camera_mode > CAMERA_MODE_THIRD)
585 f32 pointcolor_blend = wrapDegrees_0_360(m_player->getYaw()*dir_factor + 90);
586 if (pointcolor_blend > 180)
587 pointcolor_blend = 360 - pointcolor_blend;
588 pointcolor_blend /= 180;
589 // bound view angle to determine where transition starts and ends
590 pointcolor_blend = rangelim(1 - pointcolor_blend * 1.375, 0, 1 / 1.375) * 1.375;
591 // combine the colors when looking up or down, otherwise turning looks weird
592 pointcolor_blend += (0.5 - pointcolor_blend) * (1 - MYMIN((90 - std::abs(m_player->getPitch())) / 90 * 1.5, 1));
593 // invert direction to match where the sun and moon are rising
594 if (m_time_of_day > 0.5)
595 pointcolor_blend = 1 - pointcolor_blend;
597 // horizon colors of sun and moon
598 f32 pointcolor_light = rangelim(m_time_brightness * 3, 0.2, 1);
599 video::SColorf pointcolor_sun_f(1, 1, 1, 1);
600 pointcolor_sun_f.r = pointcolor_light * 1;
601 pointcolor_sun_f.b = pointcolor_light * (0.25 + (rangelim(m_time_brightness, 0.25, 0.75) - 0.25) * 2 * 0.75);
602 pointcolor_sun_f.g = pointcolor_light * (pointcolor_sun_f.b * 0.375 + (rangelim(m_time_brightness, 0.05, 0.15) - 0.05) * 10 * 0.625);
603 video::SColorf pointcolor_moon_f(0.5 * pointcolor_light, 0.6 * pointcolor_light, 0.8 * pointcolor_light, 1);
604 video::SColor pointcolor_sun = pointcolor_sun_f.toSColor();
605 video::SColor pointcolor_moon = pointcolor_moon_f.toSColor();
606 // calculate the blend color
607 pointcolor = m_mix_scolor(pointcolor_moon, pointcolor_sun, pointcolor_blend);
611 video::SColor bgcolor_bright = m_bgcolor_bright_f.toSColor();
612 m_bgcolor = video::SColor(
614 bgcolor_bright.getRed() * m_brightness,
615 bgcolor_bright.getGreen() * m_brightness,
616 bgcolor_bright.getBlue() * m_brightness);
617 if (m_directional_colored_fog) {
618 m_bgcolor = m_mix_scolor(m_bgcolor, pointcolor, m_horizon_blend() * 0.5);
621 video::SColor skycolor_bright = m_skycolor_bright_f.toSColor();
622 m_skycolor = video::SColor(
624 skycolor_bright.getRed() * m_brightness,
625 skycolor_bright.getGreen() * m_brightness,
626 skycolor_bright.getBlue() * m_brightness);
627 if (m_directional_colored_fog) {
628 m_skycolor = m_mix_scolor(m_skycolor, pointcolor, m_horizon_blend() * 0.25);
631 float cloud_direct_brightness = 0;
633 if (!m_directional_colored_fog) {
634 cloud_direct_brightness = time_brightness;
635 if(time_brightness >= 0.2 && time_brightness < 0.7)
636 cloud_direct_brightness *= 1.3;
639 cloud_direct_brightness = MYMIN(m_horizon_blend() * 0.15 + m_time_brightness, 1);
642 cloud_direct_brightness = direct_brightness;
644 m_cloud_brightness = m_cloud_brightness * cloud_color_change_fraction +
645 cloud_direct_brightness * (1.0 - cloud_color_change_fraction);
646 m_cloudcolor_f = video::SColorf(
647 m_cloudcolor_bright_f.r * m_cloud_brightness,
648 m_cloudcolor_bright_f.g * m_cloud_brightness,
649 m_cloudcolor_bright_f.b * m_cloud_brightness,
651 if (m_directional_colored_fog) {
652 m_cloudcolor_f = m_mix_scolorf(m_cloudcolor_f, video::SColorf(pointcolor), m_horizon_blend() * 0.25);