|
8 | 8 | #include "main.h" // g_profiler
|
9 | 9 | #include "profiler.h"
|
10 | 10 | #include "util/numeric.h" // MYMIN
|
| 11 | +#include <cmath> |
11 | 12 |
|
12 | 13 | //! constructor
|
13 |
| -Sky::Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id): |
| 14 | +Sky::Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id, LocalPlayer* player): |
14 | 15 | scene::ISceneNode(parent, mgr, id),
|
15 | 16 | m_first_update(true),
|
16 | 17 | m_brightness(0.5),
|
17 | 18 | m_cloud_brightness(0.5),
|
18 | 19 | m_bgcolor_bright_f(1,1,1,1),
|
19 | 20 | m_skycolor_bright_f(1,1,1,1),
|
20 |
| - m_cloudcolor_bright_f(1,1,1,1) |
| 21 | + m_cloudcolor_bright_f(1,1,1,1), |
| 22 | + m_player(player) |
21 | 23 | {
|
22 | 24 | setAutomaticCulling(scene::EAC_OFF);
|
23 | 25 | Box.MaxEdge.set(0,0,0);
|
@@ -431,7 +433,8 @@ void Sky::update(float time_of_day, float time_brightness,
|
431 | 433 | video::SColor(255, 240,240,255);
|
432 | 434 | //video::SColorf cloudcolor_bright_dawn_f(1.0, 0.591, 0.4);
|
433 | 435 | //video::SColorf cloudcolor_bright_dawn_f(1.0, 0.65, 0.44);
|
434 |
| - video::SColorf cloudcolor_bright_dawn_f(1.0, 0.7, 0.5); |
| 436 | + //video::SColorf cloudcolor_bright_dawn_f(1.0, 0.7, 0.5); |
| 437 | + video::SColorf cloudcolor_bright_dawn_f(1.0, 0.875, 0.75); |
435 | 438 |
|
436 | 439 | float cloud_color_change_fraction = 0.95;
|
437 | 440 | if(sunlight_seen){
|
@@ -470,41 +473,73 @@ void Sky::update(float time_of_day, float time_brightness,
|
470 | 473 | } else {
|
471 | 474 | m_bgcolor_bright_f = m_bgcolor_bright_f.getInterpolated(
|
472 | 475 | bgcolor_bright_indoor_f, color_change_fraction);
|
473 |
| - m_cloudcolor_bright_f = m_cloudcolor_bright_f.getInterpolated( |
474 |
| - cloudcolor_bright_normal_f, color_change_fraction); |
475 | 476 | m_skycolor_bright_f = m_skycolor_bright_f.getInterpolated(
|
476 | 477 | bgcolor_bright_indoor_f, color_change_fraction);
|
| 478 | + m_cloudcolor_bright_f = m_cloudcolor_bright_f.getInterpolated( |
| 479 | + cloudcolor_bright_normal_f, color_change_fraction); |
477 | 480 | m_clouds_visible = false;
|
478 | 481 | }
|
| 482 | + |
| 483 | + // Horizon coloring based on sun and moon direction during sunset and sunrise |
| 484 | + video::SColor pointcolor = video::SColor(255, 255, 255, m_bgcolor.getAlpha()); |
| 485 | + if (m_horizon_blend() != 0) |
| 486 | + { |
| 487 | + // calculate hemisphere value from yaw |
| 488 | + f32 pointcolor_blend = wrapDegrees_0_360(m_player->getYaw() + 90); |
| 489 | + if (pointcolor_blend > 180) |
| 490 | + pointcolor_blend = 360 - pointcolor_blend; |
| 491 | + pointcolor_blend /= 180; |
| 492 | + // bound view angle to determine where transition starts and ends |
| 493 | + pointcolor_blend = rangelim(1 - pointcolor_blend * 1.375, 0, 1 / 1.375) * 1.375; |
| 494 | + // combine the colors when looking up or down, otherwise turning looks weird |
| 495 | + pointcolor_blend += (0.5 - pointcolor_blend) * (1 - MYMIN((90 - std::abs(m_player->getPitch())) / 90 * 1.5, 1)); |
| 496 | + // invert direction to match where the sun and moon are rising |
| 497 | + if (m_time_of_day > 0.5) |
| 498 | + pointcolor_blend = 1 - pointcolor_blend; |
| 499 | + |
| 500 | + // horizon colors of sun and moon |
| 501 | + f32 pointcolor_light = rangelim(m_time_brightness * 3, 0.2, 1); |
| 502 | + video::SColorf pointcolor_sun_f(1, 1, 1, 1); |
| 503 | + pointcolor_sun_f.r = pointcolor_light * 1; |
| 504 | + pointcolor_sun_f.b = pointcolor_light * (0.25 + (rangelim(m_time_brightness, 0.25, 0.75) - 0.25) * 2 * 0.75); |
| 505 | + 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); |
| 506 | + video::SColorf pointcolor_moon_f(0.5 * pointcolor_light, 0.6 * pointcolor_light, 0.8 * pointcolor_light, 1); |
| 507 | + video::SColor pointcolor_sun = pointcolor_sun_f.toSColor(); |
| 508 | + video::SColor pointcolor_moon = pointcolor_moon_f.toSColor(); |
| 509 | + // calculate the blend color |
| 510 | + pointcolor = m_mix_scolor(pointcolor_moon, pointcolor_sun, pointcolor_blend); |
| 511 | + } |
| 512 | + |
479 | 513 | video::SColor bgcolor_bright = m_bgcolor_bright_f.toSColor();
|
480 | 514 | m_bgcolor = video::SColor(
|
481 |
| - 255, |
482 |
| - bgcolor_bright.getRed() * m_brightness, |
483 |
| - bgcolor_bright.getGreen() * m_brightness, |
484 |
| - bgcolor_bright.getBlue() * m_brightness); |
485 |
| - |
| 515 | + 255, |
| 516 | + bgcolor_bright.getRed() * m_brightness, |
| 517 | + bgcolor_bright.getGreen() * m_brightness, |
| 518 | + bgcolor_bright.getBlue() * m_brightness); |
| 519 | + m_bgcolor = m_mix_scolor(m_bgcolor, pointcolor, m_horizon_blend() * 0.5); |
| 520 | + |
486 | 521 | video::SColor skycolor_bright = m_skycolor_bright_f.toSColor();
|
487 | 522 | m_skycolor = video::SColor(
|
488 |
| - 255, |
489 |
| - skycolor_bright.getRed() * m_brightness, |
490 |
| - skycolor_bright.getGreen() * m_brightness, |
491 |
| - skycolor_bright.getBlue() * m_brightness); |
492 |
| - |
| 523 | + 255, |
| 524 | + skycolor_bright.getRed() * m_brightness, |
| 525 | + skycolor_bright.getGreen() * m_brightness, |
| 526 | + skycolor_bright.getBlue() * m_brightness); |
| 527 | + m_skycolor = m_mix_scolor(m_skycolor, pointcolor, m_horizon_blend() * 0.25); |
| 528 | + |
493 | 529 | float cloud_direct_brightness = 0;
|
494 | 530 | if(sunlight_seen){
|
495 |
| - cloud_direct_brightness = time_brightness; |
496 |
| - if(time_brightness >= 0.2 && time_brightness < 0.7) |
497 |
| - cloud_direct_brightness *= 1.3; |
| 531 | + cloud_direct_brightness = MYMIN(m_horizon_blend() * 0.15 + m_time_brightness, 1); |
498 | 532 | } else {
|
499 | 533 | cloud_direct_brightness = direct_brightness;
|
500 | 534 | }
|
501 | 535 | m_cloud_brightness = m_cloud_brightness * cloud_color_change_fraction +
|
502 | 536 | cloud_direct_brightness * (1.0 - cloud_color_change_fraction);
|
503 | 537 | m_cloudcolor_f = video::SColorf(
|
504 |
| - m_cloudcolor_bright_f.getRed() * m_cloud_brightness, |
505 |
| - m_cloudcolor_bright_f.getGreen() * m_cloud_brightness, |
506 |
| - m_cloudcolor_bright_f.getBlue() * m_cloud_brightness, |
| 538 | + m_cloudcolor_bright_f.r * m_cloud_brightness, |
| 539 | + m_cloudcolor_bright_f.g * m_cloud_brightness, |
| 540 | + m_cloudcolor_bright_f.b * m_cloud_brightness, |
507 | 541 | 1.0);
|
| 542 | + m_cloudcolor_f = m_mix_scolorf(m_cloudcolor_f, video::SColorf(pointcolor), m_horizon_blend() * 0.75); |
508 | 543 |
|
509 | 544 | }
|
510 | 545 |
|
|
0 commit comments