2 #include "IVideoDriver.h"
3 #include "ISceneManager.h"
4 #include "ICameraSceneNode.h"
6 #include "client/tile.h"
7 #include "noise.h" // easeCurve
9 #include "util/numeric.h"
12 #include "camera.h" // CameraModes
15 Sky::Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id,
16 ITextureSource *tsrc):
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, tsrc->getTextureForMesh("sunrisebg.png"));
50 m_materials[2].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
51 //m_materials[2].MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
53 m_sun_texture = tsrc->isKnownSourceImage("sun.png") ?
54 tsrc->getTextureForMesh("sun.png") : NULL;
55 m_moon_texture = tsrc->isKnownSourceImage("moon.png") ?
56 tsrc->getTextureForMesh("moon.png") : NULL;
57 m_sun_tonemap = tsrc->isKnownSourceImage("sun_tonemap.png") ?
58 tsrc->getTexture("sun_tonemap.png") : NULL;
59 m_moon_tonemap = tsrc->isKnownSourceImage("moon_tonemap.png") ?
60 tsrc->getTexture("moon_tonemap.png") : NULL;
64 m_materials[3].setTexture(0, m_sun_texture);
65 m_materials[3].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
67 m_materials[3].Lighting = true;
71 m_materials[4].setTexture(0, m_moon_texture);
72 m_materials[4].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
74 m_materials[4].Lighting = true;
77 for(u32 i=0; i<SKY_STAR_COUNT; i++){
79 myrand_range(-10000,10000),
80 myrand_range(-10000,10000),
81 myrand_range(-10000,10000)
83 m_stars[i].normalize();
86 m_directional_colored_fog = g_settings->getBool("directional_colored_fog");
89 void Sky::OnRegisterSceneNode()
92 SceneManager->registerNodeForRendering(this, scene::ESNRP_SKY_BOX);
94 scene::ISceneNode::OnRegisterSceneNode();
97 const core::aabbox3d<f32>& Sky::getBoundingBox() const
102 //! renders the node.
108 video::IVideoDriver* driver = SceneManager->getVideoDriver();
109 scene::ICameraSceneNode* camera = SceneManager->getActiveCamera();
111 if (!camera || !driver)
114 ScopeProfiler sp(g_profiler, "Sky::render()", SPT_AVG);
116 // draw perspective skybox
118 core::matrix4 translate(AbsoluteTransformation);
119 translate.setTranslation(camera->getAbsolutePosition());
121 // Draw the sky box between the near and far clip plane
122 const f32 viewDistance = (camera->getNearValue() + camera->getFarValue()) * 0.5f;
124 scale.setScale(core::vector3df(viewDistance, viewDistance, viewDistance));
126 driver->setTransform(video::ETS_WORLD, translate * scale);
130 float sunsize = 0.07;
131 video::SColorf suncolor_f(1, 1, 0, 1);
133 suncolor_f.g = MYMAX(0.3, MYMIN(1.0, 0.7+m_time_brightness*(0.5)));
134 suncolor_f.b = MYMAX(0.0, m_brightness*0.95);
135 video::SColorf suncolor2_f(1, 1, 1, 1);
137 suncolor_f.g = MYMAX(0.3, MYMIN(1.0, 0.85+m_time_brightness*(0.5)));
138 suncolor_f.b = MYMAX(0.0, m_brightness);
140 float moonsize = 0.04;
141 video::SColorf mooncolor_f(0.50, 0.57, 0.65, 1);
142 video::SColorf mooncolor2_f(0.85, 0.875, 0.9, 1);
144 float nightlength = 0.415;
145 float wn = nightlength / 2;
146 float wicked_time_of_day = 0;
147 if(m_time_of_day > wn && m_time_of_day < 1.0 - wn)
148 wicked_time_of_day = (m_time_of_day - wn)/(1.0-wn*2)*0.5 + 0.25;
149 else if(m_time_of_day < 0.5)
150 wicked_time_of_day = m_time_of_day / wn * 0.25;
152 wicked_time_of_day = 1.0 - ((1.0-m_time_of_day) / wn * 0.25);
153 /*std::cerr<<"time_of_day="<<m_time_of_day<<" -> "
154 <<"wicked_time_of_day="<<wicked_time_of_day<<std::endl;*/
156 video::SColor suncolor = suncolor_f.toSColor();
157 video::SColor suncolor2 = suncolor2_f.toSColor();
158 video::SColor mooncolor = mooncolor_f.toSColor();
159 video::SColor mooncolor2 = mooncolor2_f.toSColor();
161 // Calculate offset normalized to the X dimension of a 512x1 px tonemap
162 float offset=(1.0-fabs(sin((m_time_of_day - 0.5)*irr::core::PI)))*511;
165 u8 * texels = (u8 *)m_sun_tonemap->lock();
166 video::SColor* texel = (video::SColor *)(texels + (u32)offset * 4);
167 video::SColor texel_color (255,texel->getRed(),texel->getGreen(), texel->getBlue());
168 m_sun_tonemap->unlock();
169 m_materials[3].EmissiveColor = texel_color;
172 u8 * texels = (u8 *)m_moon_tonemap->lock();
173 video::SColor* texel = (video::SColor *)(texels + (u32)offset * 4);
174 video::SColor texel_color (255,texel->getRed(),texel->getGreen(), texel->getBlue());
175 m_moon_tonemap->unlock();
176 m_materials[4].EmissiveColor = texel_color;
181 static const u16 indices[4] = {0,1,2,3};
182 video::S3DVertex vertices[4];
184 driver->setMaterial(m_materials[1]);
186 //video::SColor cloudyfogcolor(255,255,255,255);
187 video::SColor cloudyfogcolor = m_bgcolor;
188 //video::SColor cloudyfogcolor = m_bgcolor.getInterpolated(m_skycolor, 0.5);
190 // Draw far cloudy fog thing
191 for(u32 j=0; j<4; j++)
193 video::SColor c = cloudyfogcolor.getInterpolated(m_skycolor, 0.45);
194 vertices[0] = video::S3DVertex(-1, 0.08,-1, 0,0,1, c, t, t);
195 vertices[1] = video::S3DVertex( 1, 0.08,-1, 0,0,1, c, o, t);
196 vertices[2] = video::S3DVertex( 1, 0.12,-1, 0,0,1, c, o, o);
197 vertices[3] = video::S3DVertex(-1, 0.12,-1, 0,0,1, c, t, o);
198 for(u32 i=0; i<4; i++){
203 // Switch from -Z (south) to +X (east)
204 vertices[i].Pos.rotateXZBy(90);
206 // Switch from -Z (south) to -X (west)
207 vertices[i].Pos.rotateXZBy(-90);
209 // Switch from -Z (south) to -Z (north)
210 vertices[i].Pos.rotateXZBy(-180);
212 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
214 for(u32 j=0; j<4; j++)
216 video::SColor c = cloudyfogcolor;
217 vertices[0] = video::S3DVertex(-1,-1.0,-1, 0,0,1, c, t, t);
218 vertices[1] = video::S3DVertex( 1,-1.0,-1, 0,0,1, c, o, t);
219 vertices[2] = video::S3DVertex( 1, 0.08,-1, 0,0,1, c, o, o);
220 vertices[3] = video::S3DVertex(-1, 0.08,-1, 0,0,1, c, t, o);
221 for(u32 i=0; i<4; i++){
226 // Switch from -Z (south) to +X (east)
227 vertices[i].Pos.rotateXZBy(90);
229 // Switch from -Z (south) to -X (west)
230 vertices[i].Pos.rotateXZBy(-90);
232 // Switch from -Z (south) to -Z (north)
233 vertices[i].Pos.rotateXZBy(-180);
235 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
238 driver->setMaterial(m_materials[2]);
242 float mid = (wicked_time_of_day < 0.5 ? mid1 : (1.0 - mid1));
243 float a_ = 1.0 - fabs(wicked_time_of_day - mid) * 35.0;
244 float a = easeCurve(MYMAX(0, MYMIN(1, a_)));
245 //std::cerr<<"a_="<<a_<<" a="<<a<<std::endl;
246 video::SColor c(255,255,255,255);
247 float y = -(1.0 - a) * 0.2;
248 vertices[0] = video::S3DVertex(-1,-0.05+y,-1, 0,0,1, c, t, t);
249 vertices[1] = video::S3DVertex( 1,-0.05+y,-1, 0,0,1, c, o, t);
250 vertices[2] = video::S3DVertex( 1, 0.2+y,-1, 0,0,1, c, o, o);
251 vertices[3] = video::S3DVertex(-1, 0.2+y,-1, 0,0,1, c, t, o);
252 for(u32 i=0; i<4; i++){
253 if(wicked_time_of_day < 0.5)
254 // Switch from -Z (south) to +X (east)
255 vertices[i].Pos.rotateXZBy(90);
257 // Switch from -Z (south) to -X (west)
258 vertices[i].Pos.rotateXZBy(-90);
260 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
264 if(wicked_time_of_day > 0.15 && wicked_time_of_day < 0.85){
266 driver->setMaterial(m_materials[1]);
267 float d = sunsize * 1.7;
268 video::SColor c = suncolor;
269 c.setAlpha(0.05*255);
270 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
271 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
272 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
273 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
274 for(u32 i=0; i<4; i++){
275 // Switch from -Z (south) to +X (east)
276 vertices[i].Pos.rotateXZBy(90);
277 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
279 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
283 c.setAlpha(0.15*255);
284 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
285 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
286 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
287 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
288 for(u32 i=0; i<4; i++){
289 // Switch from -Z (south) to +X (east)
290 vertices[i].Pos.rotateXZBy(90);
291 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
293 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
296 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, suncolor, t, t);
297 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, suncolor, o, t);
298 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, suncolor, o, o);
299 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, suncolor, t, o);
300 for(u32 i=0; i<4; i++){
301 // Switch from -Z (south) to +X (east)
302 vertices[i].Pos.rotateXZBy(90);
303 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
305 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
308 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, suncolor2, t, t);
309 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, suncolor2, o, t);
310 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, suncolor2, o, o);
311 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, suncolor2, t, o);
312 for(u32 i=0; i<4; i++){
313 // Switch from -Z (south) to +X (east)
314 vertices[i].Pos.rotateXZBy(90);
315 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
317 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
319 driver->setMaterial(m_materials[3]);
320 float d = sunsize * 1.7;
323 c = video::SColor (0,0,0,0);
325 c = video::SColor (255,255,255,255);
326 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
327 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
328 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
329 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
330 for(u32 i=0; i<4; i++){
331 // Switch from -Z (south) to +X (east)
332 vertices[i].Pos.rotateXZBy(90);
333 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
335 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
340 if(wicked_time_of_day < 0.3 || wicked_time_of_day > 0.7)
342 if (!m_moon_texture){
343 driver->setMaterial(m_materials[1]);
344 float d = moonsize * 1.9;
345 video::SColor c = mooncolor;
346 c.setAlpha(0.05*255);
347 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
348 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
349 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
350 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
351 for(u32 i=0; i<4; i++){
352 // Switch from -Z (south) to -X (west)
353 vertices[i].Pos.rotateXZBy(-90);
354 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
356 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
360 c.setAlpha(0.15*255);
361 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
362 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
363 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
364 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
365 for(u32 i=0; i<4; i++){
366 // Switch from -Z (south) to -X (west)
367 vertices[i].Pos.rotateXZBy(-90);
368 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
370 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
373 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, mooncolor, t, t);
374 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, mooncolor, o, t);
375 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, mooncolor, o, o);
376 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, mooncolor, t, o);
377 for(u32 i=0; i<4; i++){
378 // Switch from -Z (south) to -X (west)
379 vertices[i].Pos.rotateXZBy(-90);
380 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
382 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
384 float d2 = moonsize * 0.6;
385 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, mooncolor2, t, t);
386 vertices[1] = video::S3DVertex( d2,-d,-1, 0,0,1, mooncolor2, o, t);
387 vertices[2] = video::S3DVertex( d2, d2,-1, 0,0,1, mooncolor2, o, o);
388 vertices[3] = video::S3DVertex(-d, d2,-1, 0,0,1, mooncolor2, t, o);
389 for(u32 i=0; i<4; i++){
390 // Switch from -Z (south) to -X (west)
391 vertices[i].Pos.rotateXZBy(-90);
392 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
394 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
396 driver->setMaterial(m_materials[4]);
397 float d = moonsize * 1.9;
400 c = video::SColor (0,0,0,0);
402 c = video::SColor (255,255,255,255);
403 vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
404 vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
405 vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
406 vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
407 for(u32 i=0; i<4; i++){
408 // Switch from -Z (south) to -X (west)
409 vertices[i].Pos.rotateXZBy(-90);
410 vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
412 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
417 driver->setMaterial(m_materials[1]);
419 float starbrightness = MYMAX(0, MYMIN(1,
420 (0.285 - fabs(wicked_time_of_day < 0.5 ?
421 wicked_time_of_day : (1.0 - wicked_time_of_day))) * 10));
422 float f = starbrightness;
424 video::SColor starcolor(255, f*90,f*90,f*90);
425 if(starcolor.getBlue() < m_skycolor.getBlue())
427 u16 indices[SKY_STAR_COUNT*4];
428 video::S3DVertex vertices[SKY_STAR_COUNT*4];
429 for(u32 i=0; i<SKY_STAR_COUNT; i++){
430 indices[i*4+0] = i*4+0;
431 indices[i*4+1] = i*4+1;
432 indices[i*4+2] = i*4+2;
433 indices[i*4+3] = i*4+3;
435 core::CMatrix4<f32> a;
436 a.buildRotateFromTo(v3f(0,1,0), v3f(d,1+d/2,0));
439 a.buildRotateFromTo(v3f(0,1,0), v3f(d,1,d));
442 a.buildRotateFromTo(v3f(0,1,0), v3f(0,1-d/2,d));
445 p.rotateXYBy(wicked_time_of_day * 360 - 90);
446 p1.rotateXYBy(wicked_time_of_day * 360 - 90);
447 p2.rotateXYBy(wicked_time_of_day * 360 - 90);
448 p3.rotateXYBy(wicked_time_of_day * 360 - 90);
449 vertices[i*4+0].Pos = p;
450 vertices[i*4+0].Color = starcolor;
451 vertices[i*4+1].Pos = p1;
452 vertices[i*4+1].Color = starcolor;
453 vertices[i*4+2].Pos = p2;
454 vertices[i*4+2].Color = starcolor;
455 vertices[i*4+3].Pos = p3;
456 vertices[i*4+3].Color = starcolor;
458 driver->drawVertexPrimitiveList(vertices, SKY_STAR_COUNT*4,
459 indices, SKY_STAR_COUNT, video::EVT_STANDARD,
460 scene::EPT_QUADS, video::EIT_16BIT);
463 for(u32 j=0; j<2; j++)
465 //video::SColor c = m_skycolor;
466 video::SColor c = cloudyfogcolor;
467 vertices[0] = video::S3DVertex(-1,-1.0,-1, 0,0,1, c, t, t);
468 vertices[1] = video::S3DVertex( 1,-1.0,-1, 0,0,1, c, o, t);
469 vertices[2] = video::S3DVertex( 1,-0.02,-1, 0,0,1, c, o, o);
470 vertices[3] = video::S3DVertex(-1,-0.02,-1, 0,0,1, c, t, o);
471 for(u32 i=0; i<4; i++){
472 //if(wicked_time_of_day < 0.5)
474 // Switch from -Z (south) to +X (east)
475 vertices[i].Pos.rotateXZBy(90);
477 // Switch from -Z (south) to -X (west)
478 vertices[i].Pos.rotateXZBy(-90);
480 driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
485 void Sky::update(float time_of_day, float time_brightness,
486 float direct_brightness, bool sunlight_seen,
487 CameraMode cam_mode, float yaw, float pitch)
489 // Stabilize initial brightness and color values by flooding updates
491 /*dstream<<"First update with time_of_day="<<time_of_day
492 <<" time_brightness="<<time_brightness
493 <<" direct_brightness="<<direct_brightness
494 <<" sunlight_seen="<<sunlight_seen<<std::endl;*/
495 m_first_update = false;
496 for(u32 i=0; i<100; i++){
497 update(time_of_day, time_brightness, direct_brightness,
498 sunlight_seen, cam_mode, yaw, pitch);
503 m_time_of_day = time_of_day;
504 m_time_brightness = time_brightness;
505 m_sunlight_seen = sunlight_seen;
507 bool is_dawn = (time_brightness >= 0.20 && time_brightness < 0.35);
509 //video::SColorf bgcolor_bright_normal_f(170./255,200./255,230./255, 1.0);
510 video::SColorf bgcolor_bright_normal_f(155./255,193./255,240./255, 1.0);
511 video::SColorf bgcolor_bright_indoor_f(100./255,100./255,100./255, 1.0);
512 //video::SColorf bgcolor_bright_dawn_f(0.666,200./255*0.7,230./255*0.5,1.0);
513 //video::SColorf bgcolor_bright_dawn_f(0.666,0.549,0.220,1.0);
514 //video::SColorf bgcolor_bright_dawn_f(0.666*1.2,0.549*1.0,0.220*1.0, 1.0);
515 //video::SColorf bgcolor_bright_dawn_f(0.666*1.2,0.549*1.0,0.220*1.2,1.0);
516 video::SColorf bgcolor_bright_dawn_f
517 (155./255*1.2,193./255,240./255, 1.0);
519 video::SColorf skycolor_bright_normal_f =
520 video::SColor(255, 140, 186, 250);
521 video::SColorf skycolor_bright_dawn_f =
522 video::SColor(255, 180, 186, 250);
524 video::SColorf cloudcolor_bright_normal_f =
525 video::SColor(255, 240,240,255);
526 //video::SColorf cloudcolor_bright_dawn_f(1.0, 0.591, 0.4);
527 //video::SColorf cloudcolor_bright_dawn_f(1.0, 0.65, 0.44);
528 //video::SColorf cloudcolor_bright_dawn_f(1.0, 0.7, 0.5);
529 video::SColorf cloudcolor_bright_dawn_f(1.0, 0.875, 0.75);
531 float cloud_color_change_fraction = 0.95;
533 if(fabs(time_brightness - m_brightness) < 0.2){
534 m_brightness = m_brightness * 0.95 + time_brightness * 0.05;
536 m_brightness = m_brightness * 0.80 + time_brightness * 0.20;
537 cloud_color_change_fraction = 0.0;
541 if(direct_brightness < m_brightness)
542 m_brightness = m_brightness * 0.95 + direct_brightness * 0.05;
544 m_brightness = m_brightness * 0.98 + direct_brightness * 0.02;
547 m_clouds_visible = true;
548 float color_change_fraction = 0.98;
551 m_bgcolor_bright_f = m_bgcolor_bright_f.getInterpolated(
552 bgcolor_bright_dawn_f, color_change_fraction);
553 m_skycolor_bright_f = m_skycolor_bright_f.getInterpolated(
554 skycolor_bright_dawn_f, color_change_fraction);
555 m_cloudcolor_bright_f = m_cloudcolor_bright_f.getInterpolated(
556 cloudcolor_bright_dawn_f, color_change_fraction);
558 m_bgcolor_bright_f = m_bgcolor_bright_f.getInterpolated(
559 bgcolor_bright_normal_f, color_change_fraction);
560 m_skycolor_bright_f = m_skycolor_bright_f.getInterpolated(
561 skycolor_bright_normal_f, color_change_fraction);
562 m_cloudcolor_bright_f = m_cloudcolor_bright_f.getInterpolated(
563 cloudcolor_bright_normal_f, color_change_fraction);
566 m_bgcolor_bright_f = m_bgcolor_bright_f.getInterpolated(
567 bgcolor_bright_indoor_f, color_change_fraction);
568 m_skycolor_bright_f = m_skycolor_bright_f.getInterpolated(
569 bgcolor_bright_indoor_f, color_change_fraction);
570 m_cloudcolor_bright_f = m_cloudcolor_bright_f.getInterpolated(
571 cloudcolor_bright_normal_f, color_change_fraction);
572 m_clouds_visible = false;
575 video::SColor bgcolor_bright = m_bgcolor_bright_f.toSColor();
576 m_bgcolor = video::SColor(
578 bgcolor_bright.getRed() * m_brightness,
579 bgcolor_bright.getGreen() * m_brightness,
580 bgcolor_bright.getBlue() * m_brightness);
582 video::SColor skycolor_bright = m_skycolor_bright_f.toSColor();
583 m_skycolor = video::SColor(
585 skycolor_bright.getRed() * m_brightness,
586 skycolor_bright.getGreen() * m_brightness,
587 skycolor_bright.getBlue() * m_brightness);
589 // Horizon coloring based on sun and moon direction during sunset and sunrise
590 video::SColor pointcolor = video::SColor(255, 255, 255, m_bgcolor.getAlpha());
591 if (m_directional_colored_fog) {
592 if (m_horizon_blend() != 0)
594 // calculate hemisphere value from yaw, (inverted in third person front view)
596 if (cam_mode > CAMERA_MODE_THIRD)
598 f32 pointcolor_blend = wrapDegrees_0_360( yaw*dir_factor + 90);
599 if (pointcolor_blend > 180)
600 pointcolor_blend = 360 - pointcolor_blend;
601 pointcolor_blend /= 180;
602 // bound view angle to determine where transition starts and ends
603 pointcolor_blend = rangelim(1 - pointcolor_blend * 1.375, 0, 1 / 1.375) * 1.375;
604 // combine the colors when looking up or down, otherwise turning looks weird
605 pointcolor_blend += (0.5 - pointcolor_blend) * (1 - MYMIN((90 - std::abs(pitch)) / 90 * 1.5, 1));
606 // invert direction to match where the sun and moon are rising
607 if (m_time_of_day > 0.5)
608 pointcolor_blend = 1 - pointcolor_blend;
609 // horizon colors of sun and moon
610 f32 pointcolor_light = rangelim(m_time_brightness * 3, 0.2, 1);
612 video::SColorf pointcolor_sun_f(1, 1, 1, 1);
615 pointcolor_sun_f.r = pointcolor_light * (float)m_materials[3].EmissiveColor.getRed() / 255;
616 pointcolor_sun_f.b = pointcolor_light * (float)m_materials[3].EmissiveColor.getBlue() / 255;
617 pointcolor_sun_f.g = pointcolor_light * (float)m_materials[3].EmissiveColor.getGreen() / 255;
621 pointcolor_sun_f.r = pointcolor_light * 1;
622 pointcolor_sun_f.b = pointcolor_light * (0.25 + (rangelim(m_time_brightness, 0.25, 0.75) - 0.25) * 2 * 0.75);
623 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);
626 video::SColorf pointcolor_moon_f(0.5 * pointcolor_light, 0.6 * pointcolor_light, 0.8 * pointcolor_light, 1);
629 pointcolor_moon_f.r = pointcolor_light * (float)m_materials[4].EmissiveColor.getRed() / 255;
630 pointcolor_moon_f.b = pointcolor_light * (float)m_materials[4].EmissiveColor.getBlue() / 255;
631 pointcolor_moon_f.g = pointcolor_light * (float)m_materials[4].EmissiveColor.getGreen() / 255;
634 video::SColor pointcolor_sun = pointcolor_sun_f.toSColor();
635 video::SColor pointcolor_moon = pointcolor_moon_f.toSColor();
636 // calculate the blend color
637 pointcolor = m_mix_scolor(pointcolor_moon, pointcolor_sun, pointcolor_blend);
639 m_bgcolor = m_mix_scolor(m_bgcolor, pointcolor, m_horizon_blend() * 0.5);
640 m_skycolor = m_mix_scolor(m_skycolor, pointcolor, m_horizon_blend() * 0.25);
643 float cloud_direct_brightness = 0;
645 if (!m_directional_colored_fog) {
646 cloud_direct_brightness = time_brightness;
647 if(time_brightness >= 0.2 && time_brightness < 0.7)
648 cloud_direct_brightness *= 1.3;
651 cloud_direct_brightness = MYMIN(m_horizon_blend() * 0.15 + m_time_brightness, 1);
654 cloud_direct_brightness = direct_brightness;
656 m_cloud_brightness = m_cloud_brightness * cloud_color_change_fraction +
657 cloud_direct_brightness * (1.0 - cloud_color_change_fraction);
658 m_cloudcolor_f = video::SColorf(
659 m_cloudcolor_bright_f.r * m_cloud_brightness,
660 m_cloudcolor_bright_f.g * m_cloud_brightness,
661 m_cloudcolor_bright_f.b * m_cloud_brightness,
663 if (m_directional_colored_fog) {
664 m_cloudcolor_f = m_mix_scolorf(m_cloudcolor_f, video::SColorf(pointcolor), m_horizon_blend() * 0.25);