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):
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)
27 setAutomaticCulling(scene::EAC_OFF);
28 Box.MaxEdge.set(0,0,0);
29 Box.MinEdge.set(0,0,0);
35 mat.ZBuffer = video::ECFN_NEVER;
36 mat.ZWriteEnable = false;
38 mat.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
39 mat.TextureLayer[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
40 mat.BackfaceCulling = false;
45 //m_materials[1].MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
46 m_materials[1].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
49 m_materials[2].setTexture(0, mgr->getVideoDriver()->getTexture(
50 getTexturePath("sunrisebg.png").c_str()));
51 m_materials[2].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
52 //m_materials[2].MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
54 m_sun_texture = mgr->getVideoDriver()->getTexture(
55 getTexturePath("sun.png").c_str());
56 m_moon_texture = mgr->getVideoDriver()->getTexture(
57 getTexturePath("moon.png").c_str());
58 m_sun_tonemap = mgr->getVideoDriver()->getTexture(
59 getTexturePath("sun_tonemap.png").c_str());
60 m_moon_tonemap = mgr->getVideoDriver()->getTexture(
61 getTexturePath("moon_tonemap.png").c_str());
65 m_materials[3].setTexture(0, m_sun_texture);
66 m_materials[3].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
68 m_materials[3].Lighting = true;
72 m_materials[4].setTexture(0, m_moon_texture);
73 m_materials[4].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
75 m_materials[4].Lighting = true;
78 for(u32 i=0; i<SKY_STAR_COUNT; i++){
80 myrand_range(-10000,10000),
81 myrand_range(-10000,10000),
82 myrand_range(-10000,10000)
84 m_stars[i].normalize();
87 m_directional_colored_fog = g_settings->getBool("directional_colored_fog");
90 void Sky::OnRegisterSceneNode()
93 SceneManager->registerNodeForRendering(this, scene::ESNRP_SKY_BOX);
95 scene::ISceneNode::OnRegisterSceneNode();
98 const core::aabbox3d<f32>& Sky::getBoundingBox() const
103 //! renders the node.
109 video::IVideoDriver* driver = SceneManager->getVideoDriver();
110 scene::ICameraSceneNode* camera = SceneManager->getActiveCamera();
112 if (!camera || !driver)
115 ScopeProfiler sp(g_profiler, "Sky::render()", SPT_AVG);
117 // draw perspective skybox
119 core::matrix4 translate(AbsoluteTransformation);
120 translate.setTranslation(camera->getAbsolutePosition());
122 // Draw the sky box between the near and far clip plane
123 const f32 viewDistance = (camera->getNearValue() + camera->getFarValue()) * 0.5f;
125 scale.setScale(core::vector3df(viewDistance, viewDistance, viewDistance));
127 driver->setTransform(video::ETS_WORLD, translate * scale);
131 float sunsize = 0.07;
132 video::SColorf suncolor_f(1, 1, 0, 1);
134 suncolor_f.g = MYMAX(0.3, MYMIN(1.0, 0.7+m_time_brightness*(0.5)));
135 suncolor_f.b = MYMAX(0.0, m_brightness*0.95);
136 video::SColorf suncolor2_f(1, 1, 1, 1);
138 suncolor_f.g = MYMAX(0.3, MYMIN(1.0, 0.85+m_time_brightness*(0.5)));
139 suncolor_f.b = MYMAX(0.0, m_brightness);
141 float moonsize = 0.04;
142 video::SColorf mooncolor_f(0.50, 0.57, 0.65, 1);
143 video::SColorf mooncolor2_f(0.85, 0.875, 0.9, 1);
145 float nightlength = 0.415;
146 float wn = nightlength / 2;
147 float wicked_time_of_day = 0;
148 if(m_time_of_day > wn && m_time_of_day < 1.0 - wn)
149 wicked_time_of_day = (m_time_of_day - wn)/(1.0-wn*2)*0.5 + 0.25;
150 else if(m_time_of_day < 0.5)
151 wicked_time_of_day = m_time_of_day / wn * 0.25;
153 wicked_time_of_day = 1.0 - ((1.0-m_time_of_day) / wn * 0.25);
154 /*std::cerr<<"time_of_day="<<m_time_of_day<<" -> "
155 <<"wicked_time_of_day="<<wicked_time_of_day<<std::endl;*/
157 video::SColor suncolor = suncolor_f.toSColor();
158 video::SColor suncolor2 = suncolor2_f.toSColor();
159 video::SColor mooncolor = mooncolor_f.toSColor();
160 video::SColor mooncolor2 = mooncolor2_f.toSColor();
162 // Calculate offset normalized to the X dimension of a 512x1 px tonemap
163 float offset=(1.0-fabs(sin((m_time_of_day - 0.5)*irr::core::PI)))*511;
166 u8 * texels = (u8 *)m_sun_tonemap->lock();
167 video::SColor* texel = (video::SColor *)(texels + (u32)offset * 4);
168 video::SColor texel_color (255,texel->getRed(),texel->getGreen(), texel->getBlue());
169 m_sun_tonemap->unlock();
170 m_materials[3].EmissiveColor = texel_color;
173 u8 * texels = (u8 *)m_moon_tonemap->lock();
174 video::SColor* texel = (video::SColor *)(texels + (u32)offset * 4);
175 video::SColor texel_color (255,texel->getRed(),texel->getGreen(), texel->getBlue());
176 m_moon_tonemap->unlock();
177 m_materials[4].EmissiveColor = texel_color;
182 static const u16 indices[4] = {0,1,2,3};
183 video::S3DVertex vertices[4];
185 driver->setMaterial(m_materials[1]);
187 //video::SColor cloudyfogcolor(255,255,255,255);
188 video::SColor cloudyfogcolor = m_bgcolor;
189 //video::SColor cloudyfogcolor = m_bgcolor.getInterpolated(m_skycolor, 0.5);
191 // Draw far cloudy fog thing
192 for(u32 j=0; j<4; j++)
194 video::SColor c = cloudyfogcolor.getInterpolated(m_skycolor, 0.45);
195 vertices[0] = video::S3DVertex(-1, 0.08,-1, 0,0,1, c, t, t);
196 vertices[1] = video::S3DVertex( 1, 0.08,-1, 0,0,1, c, o, t);
197 vertices[2] = video::S3DVertex( 1, 0.12,-1, 0,0,1, c, o, o);
198 vertices[3] = video::S3DVertex(-1, 0.12,-1, 0,0,1, c, t, o);
199 for(u32 i=0; i<4; i++){
204 // Switch from -Z (south) to +X (east)
205 vertices[i].Pos.rotateXZBy(90);
207 // Switch from -Z (south) to -X (west)
208 vertices[i].Pos.rotateXZBy(-90);
210 // Switch from -Z (south) to -Z (north)
211 vertices[i].Pos.rotateXZBy(-180);
213 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
215 for(u32 j=0; j<4; j++)
217 video::SColor c = cloudyfogcolor;
218 vertices[0] = video::S3DVertex(-1,-1.0,-1, 0,0,1, c, t, t);
219 vertices[1] = video::S3DVertex( 1,-1.0,-1, 0,0,1, c, o, t);
220 vertices[2] = video::S3DVertex( 1, 0.08,-1, 0,0,1, c, o, o);
221 vertices[3] = video::S3DVertex(-1, 0.08,-1, 0,0,1, c, t, o);
222 for(u32 i=0; i<4; i++){
227 // Switch from -Z (south) to +X (east)
228 vertices[i].Pos.rotateXZBy(90);
230 // Switch from -Z (south) to -X (west)
231 vertices[i].Pos.rotateXZBy(-90);
233 // Switch from -Z (south) to -Z (north)
234 vertices[i].Pos.rotateXZBy(-180);
236 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
239 driver->setMaterial(m_materials[2]);
243 float mid = (wicked_time_of_day < 0.5 ? mid1 : (1.0 - mid1));
244 float a_ = 1.0 - fabs(wicked_time_of_day - mid) * 35.0;
245 float a = easeCurve(MYMAX(0, MYMIN(1, a_)));
246 //std::cerr<<"a_="<<a_<<" a="<<a<<std::endl;
247 video::SColor c(255,255,255,255);
248 float y = -(1.0 - a) * 0.2;
249 vertices[0] = video::S3DVertex(-1,-0.05+y,-1, 0,0,1, c, t, t);
250 vertices[1] = video::S3DVertex( 1,-0.05+y,-1, 0,0,1, c, o, t);
251 vertices[2] = video::S3DVertex( 1, 0.2+y,-1, 0,0,1, c, o, o);
252 vertices[3] = video::S3DVertex(-1, 0.2+y,-1, 0,0,1, c, t, o);
253 for(u32 i=0; i<4; i++){
254 if(wicked_time_of_day < 0.5)
255 // Switch from -Z (south) to +X (east)
256 vertices[i].Pos.rotateXZBy(90);
258 // Switch from -Z (south) to -X (west)
259 vertices[i].Pos.rotateXZBy(-90);
261 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
265 if(wicked_time_of_day > 0.15 && wicked_time_of_day < 0.85){
267 driver->setMaterial(m_materials[1]);
268 float d = sunsize * 1.7;
269 video::SColor c = suncolor;
270 c.setAlpha(0.05*255);
271 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
272 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
273 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
274 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
275 for(u32 i=0; i<4; i++){
276 // Switch from -Z (south) to +X (east)
277 vertices[i].Pos.rotateXZBy(90);
278 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
280 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
284 c.setAlpha(0.15*255);
285 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
286 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
287 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
288 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
289 for(u32 i=0; i<4; i++){
290 // Switch from -Z (south) to +X (east)
291 vertices[i].Pos.rotateXZBy(90);
292 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
294 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
297 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, suncolor, t, t);
298 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, suncolor, o, t);
299 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, suncolor, o, o);
300 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, suncolor, t, o);
301 for(u32 i=0; i<4; i++){
302 // Switch from -Z (south) to +X (east)
303 vertices[i].Pos.rotateXZBy(90);
304 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
306 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
309 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, suncolor2, t, t);
310 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, suncolor2, o, t);
311 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, suncolor2, o, o);
312 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, suncolor2, t, o);
313 for(u32 i=0; i<4; i++){
314 // Switch from -Z (south) to +X (east)
315 vertices[i].Pos.rotateXZBy(90);
316 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
318 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
320 driver->setMaterial(m_materials[3]);
321 float d = sunsize * 1.7;
324 c = video::SColor (0,0,0,0);
326 c = video::SColor (255,255,255,255);
327 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
328 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
329 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
330 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
331 for(u32 i=0; i<4; i++){
332 // Switch from -Z (south) to +X (east)
333 vertices[i].Pos.rotateXZBy(90);
334 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
336 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
341 if(wicked_time_of_day < 0.3 || wicked_time_of_day > 0.7)
343 if (!m_moon_texture){
344 driver->setMaterial(m_materials[1]);
345 float d = moonsize * 1.9;
346 video::SColor c = mooncolor;
347 c.setAlpha(0.05*255);
348 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
349 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
350 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
351 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
352 for(u32 i=0; i<4; i++){
353 // Switch from -Z (south) to -X (west)
354 vertices[i].Pos.rotateXZBy(-90);
355 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
357 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
361 c.setAlpha(0.15*255);
362 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
363 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
364 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
365 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
366 for(u32 i=0; i<4; i++){
367 // Switch from -Z (south) to -X (west)
368 vertices[i].Pos.rotateXZBy(-90);
369 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
371 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
374 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, mooncolor, t, t);
375 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, mooncolor, o, t);
376 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, mooncolor, o, o);
377 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, mooncolor, t, o);
378 for(u32 i=0; i<4; i++){
379 // Switch from -Z (south) to -X (west)
380 vertices[i].Pos.rotateXZBy(-90);
381 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
383 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
385 float d2 = moonsize * 0.6;
386 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, mooncolor2, t, t);
387 vertices[1] = video::S3DVertex( d2,-d,-1, 0,0,1, mooncolor2, o, t);
388 vertices[2] = video::S3DVertex( d2, d2,-1, 0,0,1, mooncolor2, o, o);
389 vertices[3] = video::S3DVertex(-d, d2,-1, 0,0,1, mooncolor2, t, o);
390 for(u32 i=0; i<4; i++){
391 // Switch from -Z (south) to -X (west)
392 vertices[i].Pos.rotateXZBy(-90);
393 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
395 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
397 driver->setMaterial(m_materials[4]);
398 float d = moonsize * 1.9;
401 c = video::SColor (0,0,0,0);
403 c = video::SColor (255,255,255,255);
404 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
405 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
406 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
407 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
408 for(u32 i=0; i<4; i++){
409 // Switch from -Z (south) to -X (west)
410 vertices[i].Pos.rotateXZBy(-90);
411 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
413 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
418 driver->setMaterial(m_materials[1]);
420 float starbrightness = MYMAX(0, MYMIN(1,
421 (0.285 - fabs(wicked_time_of_day < 0.5 ?
422 wicked_time_of_day : (1.0 - wicked_time_of_day))) * 10));
423 float f = starbrightness;
425 video::SColor starcolor(255, f*90,f*90,f*90);
426 if(starcolor.getBlue() < m_skycolor.getBlue())
428 u16 indices[SKY_STAR_COUNT*4];
429 video::S3DVertex vertices[SKY_STAR_COUNT*4];
430 for(u32 i=0; i<SKY_STAR_COUNT; i++){
431 indices[i*4+0] = i*4+0;
432 indices[i*4+1] = i*4+1;
433 indices[i*4+2] = i*4+2;
434 indices[i*4+3] = i*4+3;
436 core::CMatrix4<f32> a;
437 a.buildRotateFromTo(v3f(0,1,0), v3f(d,1+d/2,0));
440 a.buildRotateFromTo(v3f(0,1,0), v3f(d,1,d));
443 a.buildRotateFromTo(v3f(0,1,0), v3f(0,1-d/2,d));
446 p.rotateXYBy(wicked_time_of_day * 360 - 90);
447 p1.rotateXYBy(wicked_time_of_day * 360 - 90);
448 p2.rotateXYBy(wicked_time_of_day * 360 - 90);
449 p3.rotateXYBy(wicked_time_of_day * 360 - 90);
450 vertices[i*4+0].Pos = p;
451 vertices[i*4+0].Color = starcolor;
452 vertices[i*4+1].Pos = p1;
453 vertices[i*4+1].Color = starcolor;
454 vertices[i*4+2].Pos = p2;
455 vertices[i*4+2].Color = starcolor;
456 vertices[i*4+3].Pos = p3;
457 vertices[i*4+3].Color = starcolor;
459 driver->drawVertexPrimitiveList(vertices, SKY_STAR_COUNT*4,
460 indices, SKY_STAR_COUNT, video::EVT_STANDARD,
461 scene::EPT_QUADS, video::EIT_16BIT);
464 for(u32 j=0; j<2; j++)
466 //video::SColor c = m_skycolor;
467 video::SColor c = cloudyfogcolor;
468 vertices[0] = video::S3DVertex(-1,-1.0,-1, 0,0,1, c, t, t);
469 vertices[1] = video::S3DVertex( 1,-1.0,-1, 0,0,1, c, o, t);
470 vertices[2] = video::S3DVertex( 1,-0.02,-1, 0,0,1, c, o, o);
471 vertices[3] = video::S3DVertex(-1,-0.02,-1, 0,0,1, c, t, o);
472 for(u32 i=0; i<4; i++){
473 //if(wicked_time_of_day < 0.5)
475 // Switch from -Z (south) to +X (east)
476 vertices[i].Pos.rotateXZBy(90);
478 // Switch from -Z (south) to -X (west)
479 vertices[i].Pos.rotateXZBy(-90);
481 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
486 void Sky::update(float time_of_day, float time_brightness,
487 float direct_brightness, bool sunlight_seen,
488 CameraMode cam_mode, float yaw, float pitch)
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,
499 sunlight_seen, cam_mode, yaw, pitch);
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 video::SColor bgcolor_bright = m_bgcolor_bright_f.toSColor();
577 m_bgcolor = video::SColor(
579 bgcolor_bright.getRed() * m_brightness,
580 bgcolor_bright.getGreen() * m_brightness,
581 bgcolor_bright.getBlue() * m_brightness);
583 video::SColor skycolor_bright = m_skycolor_bright_f.toSColor();
584 m_skycolor = video::SColor(
586 skycolor_bright.getRed() * m_brightness,
587 skycolor_bright.getGreen() * m_brightness,
588 skycolor_bright.getBlue() * m_brightness);
590 // Horizon coloring based on sun and moon direction during sunset and sunrise
591 video::SColor pointcolor = video::SColor(255, 255, 255, m_bgcolor.getAlpha());
592 if (m_directional_colored_fog) {
593 if (m_horizon_blend() != 0)
595 // calculate hemisphere value from yaw, (inverted in third person front view)
597 if (cam_mode > CAMERA_MODE_THIRD)
599 f32 pointcolor_blend = wrapDegrees_0_360( yaw*dir_factor + 90);
600 if (pointcolor_blend > 180)
601 pointcolor_blend = 360 - pointcolor_blend;
602 pointcolor_blend /= 180;
603 // bound view angle to determine where transition starts and ends
604 pointcolor_blend = rangelim(1 - pointcolor_blend * 1.375, 0, 1 / 1.375) * 1.375;
605 // combine the colors when looking up or down, otherwise turning looks weird
606 pointcolor_blend += (0.5 - pointcolor_blend) * (1 - MYMIN((90 - std::abs(pitch)) / 90 * 1.5, 1));
607 // invert direction to match where the sun and moon are rising
608 if (m_time_of_day > 0.5)
609 pointcolor_blend = 1 - pointcolor_blend;
610 // horizon colors of sun and moon
611 f32 pointcolor_light = rangelim(m_time_brightness * 3, 0.2, 1);
613 video::SColorf pointcolor_sun_f(1, 1, 1, 1);
616 pointcolor_sun_f.r = pointcolor_light * (float)m_materials[3].EmissiveColor.getRed() / 255;
617 pointcolor_sun_f.b = pointcolor_light * (float)m_materials[3].EmissiveColor.getBlue() / 255;
618 pointcolor_sun_f.g = pointcolor_light * (float)m_materials[3].EmissiveColor.getGreen() / 255;
622 pointcolor_sun_f.r = pointcolor_light * 1;
623 pointcolor_sun_f.b = pointcolor_light * (0.25 + (rangelim(m_time_brightness, 0.25, 0.75) - 0.25) * 2 * 0.75);
624 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);
627 video::SColorf pointcolor_moon_f(0.5 * pointcolor_light, 0.6 * pointcolor_light, 0.8 * pointcolor_light, 1);
630 pointcolor_moon_f.r = pointcolor_light * (float)m_materials[4].EmissiveColor.getRed() / 255;
631 pointcolor_moon_f.b = pointcolor_light * (float)m_materials[4].EmissiveColor.getBlue() / 255;
632 pointcolor_moon_f.g = pointcolor_light * (float)m_materials[4].EmissiveColor.getGreen() / 255;
635 video::SColor pointcolor_sun = pointcolor_sun_f.toSColor();
636 video::SColor pointcolor_moon = pointcolor_moon_f.toSColor();
637 // calculate the blend color
638 pointcolor = m_mix_scolor(pointcolor_moon, pointcolor_sun, pointcolor_blend);
640 m_bgcolor = m_mix_scolor(m_bgcolor, pointcolor, m_horizon_blend() * 0.5);
641 m_skycolor = m_mix_scolor(m_skycolor, pointcolor, m_horizon_blend() * 0.25);
644 float cloud_direct_brightness = 0;
646 if (!m_directional_colored_fog) {
647 cloud_direct_brightness = time_brightness;
648 if(time_brightness >= 0.2 && time_brightness < 0.7)
649 cloud_direct_brightness *= 1.3;
652 cloud_direct_brightness = MYMIN(m_horizon_blend() * 0.15 + m_time_brightness, 1);
655 cloud_direct_brightness = direct_brightness;
657 m_cloud_brightness = m_cloud_brightness * cloud_color_change_fraction +
658 cloud_direct_brightness * (1.0 - cloud_color_change_fraction);
659 m_cloudcolor_f = video::SColorf(
660 m_cloudcolor_bright_f.r * m_cloud_brightness,
661 m_cloudcolor_bright_f.g * m_cloud_brightness,
662 m_cloudcolor_bright_f.b * m_cloud_brightness,
664 if (m_directional_colored_fog) {
665 m_cloudcolor_f = m_mix_scolorf(m_cloudcolor_f, video::SColorf(pointcolor), m_horizon_blend() * 0.25);