From 2e90ed07acd295387c0da6c0689d14665b6c125d Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 16 Mar 2012 16:34:30 +0200 Subject: [PATCH] Dynamic sky, fog and cloud colors; sun and moon --- share/client/textures/sunrisebg.png | Bin 0 -> 4652 bytes .../mods/default/textures/skybox1.png | Bin 236 -> 0 bytes .../mods/default/textures/skybox1_dawn.png | Bin 598 -> 0 bytes .../mods/default/textures/skybox1_night.png | Bin 2247 -> 0 bytes .../mods/default/textures/skybox2.png | Bin 231 -> 0 bytes .../mods/default/textures/skybox2_dawn.png | Bin 199 -> 0 bytes .../mods/default/textures/skybox2_night.png | Bin 2583 -> 0 bytes .../mods/default/textures/skybox3.png | Bin 190 -> 0 bytes .../mods/default/textures/skybox3_dawn.png | Bin 190 -> 0 bytes .../mods/default/textures/skybox3_night.png | Bin 190 -> 0 bytes src/CMakeLists.txt | 1 + src/camera.cpp | 8 +- src/client.cpp | 57 ++- src/client.h | 9 +- src/clientmap.cpp | 181 ++++++- src/clientmap.h | 3 + src/clientserver.h | 7 +- src/clouds.cpp | 204 ++++++-- src/clouds.h | 4 +- src/daynightratio.h | 43 ++ src/defaultsettings.cpp | 12 +- src/environment.cpp | 42 +- src/environment.h | 24 +- src/game.cpp | 210 ++++----- src/scriptapi.cpp | 1 + src/server.cpp | 16 +- src/server.h | 9 - src/sky.cpp | 446 ++++++++++++++++++ src/sky.h | 84 ++++ src/utility.h | 15 - 30 files changed, 1132 insertions(+), 244 deletions(-) create mode 100644 share/client/textures/sunrisebg.png delete mode 100644 share/server/games/mesetint/mods/default/textures/skybox1.png delete mode 100644 share/server/games/mesetint/mods/default/textures/skybox1_dawn.png delete mode 100644 share/server/games/mesetint/mods/default/textures/skybox1_night.png delete mode 100644 share/server/games/mesetint/mods/default/textures/skybox2.png delete mode 100644 share/server/games/mesetint/mods/default/textures/skybox2_dawn.png delete mode 100644 share/server/games/mesetint/mods/default/textures/skybox2_night.png delete mode 100644 share/server/games/mesetint/mods/default/textures/skybox3.png delete mode 100644 share/server/games/mesetint/mods/default/textures/skybox3_dawn.png delete mode 100644 share/server/games/mesetint/mods/default/textures/skybox3_night.png create mode 100644 src/daynightratio.h create mode 100644 src/sky.cpp create mode 100644 src/sky.h diff --git a/share/client/textures/sunrisebg.png b/share/client/textures/sunrisebg.png new file mode 100644 index 0000000000000000000000000000000000000000..d8b010ebb63e6b2e4f689e82d3cd766a92ecd6d7 GIT binary patch literal 4652 zcmV+{64UL8P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2iyY@ z6%;p$(=Q(Y0013nR9JLFZ*6U5Zgc_CX>@2HM@dakWG-a~000q# zNkl;Sn+CbxMD19_r(h&)jMKS~ncWPpq(gJfnR z%R1ex+H+B>cI{%b|0Itk%cLPU*<||Y`8_)>X?Z5bpr*&_4EEyf5VP0I=7#caV30cW`fYI zh4)Gie3ySs0DlMZ^$}ECt?v-;0PpbLfL0vT2n%xoeKvGNY^rvmR9-2Z~&0Ko*o z@1dBu{*2^cmH_Vp8GvmNK10vIl>n-2ye1ykRCgwXMtDyECS>1M6l55Vd`wty$v0)hhsuaR6~CkTwNCayR2JW-7m zf)k%_Aj*bamSDFf9G3#d@f+6=#}=+9f@^^5@xrwU+0|K4@ERFUg#V9J-xtXEBj59% z_}m82JIFi0A1AzD5t0V)H&DEU;Cmz-AUG0U1ZWo|hgc!V0o)uwU0hdX(-!x=at3np zW5S08Q2dyR?L=4s!wK1KwISm!hA#qQ1A?c65xUbCm6&_Q9Zf! z9S4Qq2e`j+FR;EScc6EGe*|y=;2)6i5(+^=g5m`Ph6G>^mN^l<35JQPsSdF4HERnz z0|E4?vIv;gpB$B02c?z)`o3KVSu@q<>8n;`s+Rafa0?+eoM^3&$WUaI0P`~y`UC@z z@x>%#|zdNx1!gKQ< zK@l6cZ&}{?3nZMNIADSxVZ!8!J27dcn5eqdIxCg2MaLGh#3_Ipv&+ikH0+;TTibr+ zR)0;i&@CwzBV+ZEsb!)|C?Pd7-I1+p3y#Q;GmJCU*qEiR`;>4S3f@q;PcSSfIKq%n z@CQQt+O4!*0l4fS?*Lzhb-ny1WPV>mF=OT>R#g^AC=en#c~NM>?5L*jI3v00))-eq z)>%VYr~=v|+L#Vo$(;6DSEe39i+$KE~ER20?`m1>EIy2#A#JZN5 z+TNzfCuYWv>;P*~`wu+}LT&TpxBv&gi6`XLwi4pWdgsT!SP#E42{DOk-u|RwfsPC>+ zzg5jM)o*Hhuj$HS5%D|=L+Z& z8b6*riY`>@_KL!cbuU4+0pt`QRsya;g~2A&2?aA>ci_G!YWu4*DD44o%cFpQD7fV( z460t)FBgv0uwIXO%Zt9LZl*=94T8!PO4USjFxq-dF;!4&3rF2O)_?y;u6ndhtxui0UK@(C7(E4Af~?Rz1A81O$A z?D7%9dJ9gy@cH!uuv^O86I5+H&jH}3x?t0VLHREcIUR~IG1)W`rJ0>n4c6pPmhhDxyGGDOT{?Awx4iGz-W?yD9n+i)KGdb`PNuLQ?AO4-{xN>Jkx9?gqK@Pt)2 z+l!~c7It;j=Q{L@A7vgV$N5n3i4(;mcB3jQ?RD~`S7x7E832FU1lX*hvz30=@7%u^}^ z(gK*q*w{kRsbW6%be->S#$5Ol#k;o~$aT8`EMZ=A4ScE^x6)HuWvw3r_|h?t0RFBq z_uYyy$Ur=vBy0uRRaBG|^Aytwb$G)vhC24?S3cXC~x|@bvud#ijbxrkzQDVAj zA~@~crqI4Is;jV(5>$GGv{!Tk8s-Sccvm+PSPcaYnk$ZQ9gMP1^{<-I-@i>mY*YRt zSam2X9Q0b(bmA~s!eq&Xv27nxW&lSf&x9bFzf*A=Z9eQoh!q8sr{I!znibBb0_MR^ zUxPDk921{^6mZ!9TyMat_rg5=fRH{KtIAz5>LZr;{P}Tvad?&O{3%=x64E9y#%&V~ zl3&ugD&QEQRYw~h?+O!AbI{D>s@tR46x6uIc37pOdJ_ozQ#YLAxs#37%nt526{5jg z7(jGv+XRP(oVo8P9yq`gPs!h9;`Vx230`5^D^@7S? z0(XQL5W*|GOw>Dq8?>>h(Lz=izKu{i>PEW1GUlkOvh*Q92s%RH2O-r2H}VKD>sj=g z5N8F8tD~%*lhq`Ktq{r_|9%-)WHTK=ad_baM)tD++TKL}QmBG0r)K|eJ|v= z2l(j$c=d*LwFfNl?HKhkn0h0Db$%!=PkRNc7sW{I@Q^|mN< z3e6Y?A~*4I4hFqh%O1HZ)yzU46++1=e(^FCgwp24u??>c*=P%<6COv3tFUlxunZSd zarpWfSUlEmX4W{QS+Kx8vM>Is!U49;j?ysI0b5hjx}8Svm`mdTR0L&H8$5k_4rSM%5K@Av633~G5bXP#Nkn4uD~_bqW*j{ z>oo^Homu4=%}V&p-Z-OJ86!7!p1kD)UJU9t z^MQAmWgj9X+(<7P^jN2E`Z~^EUJvBGk6ZYeJG5;OX(2&-yu73b0M`pGF_+Zz9?0(< z1V(^Y@U9h7gJP!#?C;ibx9qRnXwZ-wr7&@L5h{r#+`835Ye4ZhSVIy=RyI|UIISwQea;ZVoTcI!UmMgwRs&iJ3bkIc4`dNZ z^WQv9??<@(PH|<2pUpU@xLV-${1k5C)53y<=j7<~lKWMW1GeItKK>T6QsMsD$1HiG zzN`0kYXJXpKH$Fn*8nefmTc`p9DdKhVVeM7P}mf<(+cQos(DY6>5>J$^~b<&*ROMc zc!XD2^A%oj8X_eOwiDq3?dcZrL{m(Q^)r-RL!MxmVVEI!!JEjn`)C~aiIT(6id#Kd zmIjp_wWb7R#Q=K$TMK;vkh6dNwGu3Mi#?5TY3sErKFI+*YbPJHz@!tfpiQuBu=Zq> zhPz%$xaah!w-zGO;vtOq?Fa6wk6Or6m(YiH`FgS+urDIr0peC;hu#=KY$IcB(~WF% ztcOk;0LzU8)jbyYk>-*|{${RhFfP1TiaVR@(=@qgHz8+ zD?hXH#_v6jRSuKJE-CXfUi@=LsGAzA|19xuMJ}qNoq^ldE`fX7KL5D@U;hqi19-cm zxkJv%NE_B!FTk5NAimfB-m9SUz=_@drN@{TgZf4-DMNly{QqV62^Oqsw3!_*^K7zs zYhRrQ3_Q^?Hjrn)yN1M@Jq+MPx^Xf>xo}R3-)1(ZraGv31*e4HOoP#tjmxt*0>;l- zJbRGY2xH!OYJOw--fE%j)>3v`buDaXJ@eDGHps$H)?(K9%~|*cEX2Y6d&LkJgUK`t z(Re>rgFi{{4Br;uKZJT;%IVmp($jRoKFbQ;na|BZb8gw?YtYGi0eX*#LeQh}vW#Xh zB4VrBsD%oxh03E1l|~^-Gh^5pLIpOwWa;QYJFQ53tm&S~HAh0E-gB{7!D#_J#o~4s zg9$A`fqOEmxH7LTn}%~${C5{u;_PRxp!f~o7yjhldj+4?Q9Qz4n8{w;N+-5kHpqLl zo?V3zZY+;8eBr|Z252!fci841EH_;F!{s-xr*{MLT@_p&h|l+BU-o5R_GMr8WncDX iU-o5R_GMo_`Q=ZV$&*-#5Mw(40000$3)ON&UHOdNH#MhqQp5rH#aq}1juDza4t$sEJ;mK zD9TWe19fdb&7bf`=Si84hC#z YV7R5vzsY`QMk2^&Pgg&ebxsLQ0K`yA{{R30 diff --git a/share/server/games/mesetint/mods/default/textures/skybox1_dawn.png b/share/server/games/mesetint/mods/default/textures/skybox1_dawn.png deleted file mode 100644 index 9711c47819be9d823169536679c8c1dbc5e6cf56..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 598 zcmV-c0;&CpP)Px#32;bRa{vGf6951U69E94oEQKA00(qQO+^RW1RV|`7v>Do-~a#s9cffpbVF}# zZDnqB0000007G(RVRU6=Aa`kWXdp*PO;BVmWd{HN0l!H^K~zY`?UhSz)ld*bPxUpC zkRnEm7_%03!BW^2`(PuC5DHO}*N4Hijd^(qLI_6mz`Az3Kklk7=iU1c{7ozVvi&dc zOIv~fg!OQCUhf~<40Ln)*pI;S!qZd5x4h<3cFDXRvR^2+y!4JI;%j|Vptf9l?^~_} zn*wKnJ`@I)Yj2MMduw|?(X*t-p$QW6+s@eRYSTwYdQ?2WZ7Q^aUL<&q49X#yz$P$@1p)m&EE0oTxyh*J+x-sBRNIS%xap z208_dv_fJhkZOtA)`^UA`P?^G>5;CO6l9F1_db$xb}4C6Wnp0@sdPHdi6sN1oBI>r z?#I3L@WAr%)72Pp2glTg*&J4tF%1oxQ6fFzH3eXsCOe_sFsitGy&0(pt~3h@G-P8% zCRL_`1p2_&Y~Tk2BOWM_L;Q#;t diff --git a/share/server/games/mesetint/mods/default/textures/skybox1_night.png b/share/server/games/mesetint/mods/default/textures/skybox1_night.png deleted file mode 100644 index 32e43a63e88afa5f207d9e7db45860d55742b0b1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2247 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A1Qgk|*?TjPVk{1FcVbv~PUa<$!&%@F zSC~?lu%}vcK0dg4_oQqNu zOHxx5$}>wc6x=<115)%-*%=r(3_M*NLn>~)z3ZDN>@Cu8Q7=ULfY2eq$@dnj>TKdX z(jZ!up_aydRA&K;)9u3VYv&iI`TK9Yr#9={uGq=xIXGn;Cufqs52!s?4fKUSi za|45M-|3$zf(&^RYWO4=d=TQy3`{&AgscIkhmf4ZY`y1~PyGK4v^STD!GIBH4R$Tl z7#LV2Ku92gLEu3e&%a!0hAStxD>624!i5tU92yuM8XDjJSRiY1>i7hP11uO01N#JK z1(Kt`9K8OD(fMO(3qt}E8v`R7l5J3989|~Dgm4K=POHRnz7ErE@7;fML~&c&z!1#@ z_5e&9+`NX>wsQPpiJ`!7Sj)sP1LO^ueaMyxBzOZ86w#jId0%7~$+AF~cvC|}6Y77< zG2A;e-H^e-S{NMv8@i4^PFxyZ#wkT%tQSlLC7^Ya%6{L}VnC0#1+qIux)~VMfYFN) zI{Y3&;r z6dJrQFbEuQjsRr}1Gec47@fdQx$7{v)Z?-+x(s!pGH_ciM+tF0_EwtauMzs{wh{t`x7XSS7zCUfR>tmp8P9m7EXDS*oWbn8eI>86m;Jt4-uvI_ zK;_prssDdJ-YF8yVtCv3?)%!JHaAcHuyN(I``8*#ty6XT@1mW&-uOH z6V32yjtt9;SKGeU)*okC@fm1!*8Q97bMlU|YT0ZOQ?s-_#4#oB?j5z{1?N6z{oFWN z-QV%@t@XV{+*boz$!yI;G{{6<09Yu9}@b1~-7x#8Y@bKj&a zI(lCwRBXkQJ+o|B&stQ=E@)QP7EhPG_(xSI;lSrpsu^c?GcZ1%x?Y*3fni?LvMld) z-)&*sN{q&Kh4wAc&iY`!EgcNJo3r~pL0gEE9lbG2KQO+=KV*!~2Hw;TTGm_;9hcLd- eAGC5`9*DDaP0reWU$5P?Gp7jl&kZfj1M2T~LZf_#W!)6!6Xl!Z&P$E zPjVfPS>fYc$RlBp@PKWB_b>5D3@S$_Fu&O@w4V8e>sc4WOVO+@yiXpRn-PgU*mKJj}%A=%83h!W@g+}zZ>5+Ij>!MP|ku_QG` zp**uBL&4qCHy}kXl^rN<;OXKR;&D8=qz>% diff --git a/share/server/games/mesetint/mods/default/textures/skybox2_night.png b/share/server/games/mesetint/mods/default/textures/skybox2_night.png deleted file mode 100644 index beb07a9cf8add64e0d98f45ad7b6552b8bb399cf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2583 zcmeAS@N?(olHy`uVBq!ia0y~yU}^wi4kn;T^ZK|FAjMc5oeRDC7i+23>^Uee)E-PeU*!J}_2ZKWcBM>n#vVjnb1PBQvfDlB2e7WDD z-rpuNUuY7zoWaGAzzj0~-&T=zA}lIv7yw-XR#&&BsDZ_UZwhb-P>9liY?4pKdolo|D2A@FB4Hy8a%Df z+HhvF;sNvh>^ww-?XKr#?__s!LsK9k9Ua(T@Mfp1A6jaL+W`thZ0Yl5jP6YVhI!9x z4=`N#&9>*vwK2ttpGy9U8WO`}i~U3wkUP?JY=H0LcThV|o}G&b4m%m%ct6SO|V`24{Dih53W` z(<-Ze-j__0@)cuvS1fMA@Wlm}j*Rn1IT#YS?e(v6IW{mRtbX_Jhjae|#)R9y_zpj? zPGGpPZyzuL|Atf|Kr&&k05BWe%Gz)r=v!Z@H%fdAH)^H7aY!+g!QBfkn-6zh1(pdF zLEy4*$NPuUy}%;BzyMNUgYyKAfPu)BJWXO@D0w$CoC_YVka`4YOMalY84HU&$&@upd4u~MG!ID^z$5MCUeD_qKkZfj1M2T~LZfmdKI;Vst07ZE)<^TWy diff --git a/share/server/games/mesetint/mods/default/textures/skybox3_dawn.png b/share/server/games/mesetint/mods/default/textures/skybox3_dawn.png deleted file mode 100644 index 22c8cbef571a5142aa30cf11be5124f6c4282488..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 190 zcmeAS@N?(olHy`uVBq!ia0vp^3P3Eu!2~2l3^S5}6k~CayA#8@b22Z19L@rd$YKTt zZeb8+WSBKa0w~B{;_2(kew#&>Pu1%9e(#AuA=%83h!W@g+}zZ>5+Ij>!MP|ku_QG` zp**uBL&4qCHy}kXl^rOq?&;zf;&D7VWOHZ20@Z}11%?t^6RtD`a=Yom84LIr7;3v2 UUg@>Xl>(XN>FVdQ&MBb@05?Z4JOBUy diff --git a/share/server/games/mesetint/mods/default/textures/skybox3_night.png b/share/server/games/mesetint/mods/default/textures/skybox3_night.png deleted file mode 100644 index bb509789b694aca038a40912fc18f1e6f893feff..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 190 zcmeAS@N?(olHy`uVBq!ia0vp^3P3Eu!2~2l3^S5}6k~CayA#8@b22Z19L@rd$YKTt zZeb8+WSBKa0w~B{;_2(kew#&>&rsG!T5~;6NH#MhqQp5rH#aq}1juDza4t$sEJ;mK zD9TWe19@d%8G=cpOiD@<=>+foek10z-+d30Il|x!rW(j0JoQ41FaG U@h?0#?EsnO>FVdQ&MBb@0M1%3_W%F@ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e43ff411e..d3d9d64dc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -159,6 +159,7 @@ endif() # Client sources set(minetest_SRCS ${common_SRCS} + sky.cpp clientmap.cpp content_cso.cpp content_mapblock.cpp diff --git a/src/camera.cpp b/src/camera.cpp index 531661679..97571c77d 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -375,8 +375,12 @@ void Camera::updateViewingRange(f32 frametime_in) m_draw_control.wanted_range = viewing_range_max; // Just so big a value that everything rendered is visible - // Some more allowance than viewing_range_max * BS because of active objects etc. - m_cameranode->setFarValue(viewing_range_max * BS * 10); + // Some more allowance than viewing_range_max * BS because of clouds, + // active objects, etc. + if(viewing_range_max < 200*BS) + m_cameranode->setFarValue(200 * BS * 10); + else + m_cameranode->setFarValue(viewing_range_max * BS * 10); f32 wanted_fps = g_settings->getFloat("wanted_fps"); wanted_fps = MYMAX(wanted_fps, 1.0); diff --git a/src/client.cpp b/src/client.cpp index 6d992e717..2148bfe59 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -247,14 +247,16 @@ Client::Client( m_animation_time(0), m_crack_level(-1), m_crack_pos(0,0,0), - m_time_of_day(0), m_map_seed(0), m_password(password), m_access_denied(false), m_texture_receive_progress(0), m_textures_received(false), m_itemdef_received(false), - m_nodedef_received(false) + m_nodedef_received(false), + m_time_of_day_set(false), + m_last_time_of_day_f(-1), + m_time_of_day_update_timer(0) { m_packetcounter_timer = 0.0; //m_delete_unused_sectors_timer = 0.0; @@ -333,6 +335,8 @@ void Client::step(float dtime) if(m_animation_time > 60.0) m_animation_time -= 60.0; + m_time_of_day_update_timer += dtime; + //infostream<<"Client steps "< +#include #include "log.h" #include "mapsector.h" #include "main.h" // dout_client, g_settings @@ -29,6 +30,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "profiler.h" #include "settings.h" +#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" + ClientMap::ClientMap( Client *client, IGameDef *gamedef, @@ -189,7 +192,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) */ float animation_time = m_client->getAnimationTime(); int crack = m_client->getCrackLevel(); - u32 daynight_ratio = m_client->getDayNightRatio(); + u32 daynight_ratio = m_client->getEnv().getDayNightRatio(); m_camera_mutex.Lock(); v3f camera_position = m_camera_position; @@ -509,6 +512,182 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) <<", rendered "<getNodeNoEx(p); + if(ndef->get(n).param_type == CPT_LIGHT && + !ndef->get(n).sunlight_propagates) + allow_allowing_non_sunlight_propagates = true; + } + // If would start at CONTENT_IGNORE, start closer + { + v3s16 p = floatToInt(pf, BS); + MapNode n = map->getNodeNoEx(p); + if(n.getContent() == CONTENT_IGNORE){ + float newd = 2*BS; + pf = p0 + dir * 2*newd; + distance = newd; + } + } + for(int i=0; distance < end_distance; i++){ + pf += dir * step; + distance += step; + step *= step_multiplier; + + v3s16 p = floatToInt(pf, BS); + MapNode n = map->getNodeNoEx(p); + if(allow_allowing_non_sunlight_propagates && i == 0 && + ndef->get(n).param_type == CPT_LIGHT && + !ndef->get(n).sunlight_propagates){ + allow_non_sunlight_propagates = true; + } + if(ndef->get(n).param_type != CPT_LIGHT || + (!ndef->get(n).sunlight_propagates && + !allow_non_sunlight_propagates)){ + nonlight_seen = true; + noncount++; + if(noncount >= 4) + break; + continue; + } + if(distance >= sunlight_min_d && *sunlight_seen == false + && nonlight_seen == false) + if(n.getLight(LIGHTBANK_DAY, ndef) == LIGHT_SUN) + *sunlight_seen = true; + noncount = 0; + brightness_sum += decode_light(n.getLightBlend(daylight_factor, ndef)); + brightness_count++; + } + *result = 0; + if(brightness_count == 0) + return false; + *result = brightness_sum / brightness_count; + /*std::cerr<<"Sampled "< 35*BS) + sunlight_min_d = 35*BS; + core::array values; + for(u32 i=0; i a; + a.buildRotateFromTo(v3f(0,1,0), z_dir); + v3f dir = m_camera_direction; + a.rotateVect(dir); + int br = 0; + float step = BS*1.5; + if(max_d > 35*BS) + step = max_d / 35 * 1.5; + float off = step * z_offsets[i]; + bool sunlight_seen_now = false; + bool ok = getVisibleBrightness(this, m_camera_position, dir, + step, 1.0, max_d*0.6+off, max_d, ndef, daylight_factor, + sunlight_min_d, + &br, &sunlight_seen_now); + if(sunlight_seen_now) + sunlight_seen_count++; + if(!ok) + continue; + values.push_back(br); + // Don't try too much if being in the sun is clear + if(sunlight_seen_count >= 20) + break; + } + int brightness_sum = 0; + int brightness_count = 0; + values.sort(); + u32 num_values_to_use = values.size(); + if(num_values_to_use >= 10) + num_values_to_use -= num_values_to_use/2; + else if(num_values_to_use >= 7) + num_values_to_use -= num_values_to_use/3; + u32 first_value_i = (values.size() - num_values_to_use) / 2; + if(debugprint){ + for(u32 i=0; i < first_value_i; i++) + std::cerr<get(n).param_type == CPT_LIGHT){ + ret = decode_light(n.getLightBlend(daylight_factor, ndef)); + } else { + ret = oldvalue; + //ret = blend_light(255, 0, daylight_factor); + } + } else { + /*float pre = (float)brightness_sum / (float)brightness_count; + float tmp = pre; + const float d = 0.2; + pre *= 1.0 + d*2; + pre -= tmp * d; + int preint = pre; + ret = MYMAX(0, MYMIN(255, preint));*/ + ret = brightness_sum / brightness_count; + } + if(debugprint) + std::cerr<<"Result: "<getBool("enable_3d_clouds")) - num_faces_to_draw = 6; + + bool enable_3d = g_settings->getBool("enable_3d_clouds"); + int num_faces_to_draw = enable_3d ? 6 : 1; + + m_material.setFlag(video::EMF_BACK_FACE_CULLING, enable_3d); driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); driver->setMaterial(m_material); @@ -90,8 +93,10 @@ void Clouds::render() */ const s16 cloud_radius_i = 12; - const float cloud_size = BS*48; - const v2f cloud_speed(-BS*2, 0); + const float cloud_size = BS*64; + const v2f cloud_speed(0, -BS*2); + + const float cloud_full_radius = cloud_size * cloud_radius_i; // Position of cloud noise origin in world coordinates v2f world_cloud_origin_pos_f = m_time*cloud_speed; @@ -110,33 +115,103 @@ void Clouds::render() center_of_drawing_in_noise_i.Y * cloud_size ) + world_cloud_origin_pos_f; + /*video::SColor c_top(128,b*240,b*240,b*255); + video::SColor c_side_1(128,b*230,b*230,b*255); + video::SColor c_side_2(128,b*220,b*220,b*245); + video::SColor c_bottom(128,b*205,b*205,b*230);*/ + video::SColorf c_top_f(m_color); + video::SColorf c_side_1_f(m_color); + video::SColorf c_side_2_f(m_color); + video::SColorf c_bottom_f(m_color); + c_side_1_f.r *= 0.95; + c_side_1_f.g *= 0.95; + c_side_1_f.b *= 0.95; + c_side_2_f.r *= 0.90; + c_side_2_f.g *= 0.90; + c_side_2_f.b *= 0.90; + c_bottom_f.r *= 0.80; + c_bottom_f.g *= 0.80; + c_bottom_f.b *= 0.80; + c_top_f.a = 0.9; + c_side_1_f.a = 0.9; + c_side_2_f.a = 0.9; + c_bottom_f.a = 0.9; + video::SColor c_top = c_top_f.toSColor(); + video::SColor c_side_1 = c_side_1_f.toSColor(); + video::SColor c_side_2 = c_side_2_f.toSColor(); + video::SColor c_bottom = c_bottom_f.toSColor(); + + // Get fog parameters for setting them back later + video::SColor fog_color(0,0,0,0); + video::E_FOG_TYPE fog_type = video::EFT_FOG_LINEAR; + f32 fog_start = 0; + f32 fog_end = 0; + f32 fog_density = 0; + bool fog_pixelfog = false; + bool fog_rangefog = false; + driver->getFog(fog_color, fog_type, fog_start, fog_end, fog_density, + fog_pixelfog, fog_rangefog); + + // Set our own fog + driver->setFog(fog_color, fog_type, cloud_full_radius * 0.5, + cloud_full_radius*1.2, fog_density, fog_pixelfog, fog_rangefog); + + // Read noise + + bool *grid = new bool[cloud_radius_i*2*cloud_radius_i*2]; + for(s16 zi=-cloud_radius_i; zi= 0.80); +#endif +#if 1 + double noise = noise2d_perlin( + (float)p_in_noise_i.X*cloud_size/BS/200, + (float)p_in_noise_i.Y*cloud_size/BS/200, + m_seed, 3, 0.5); + grid[i] = (noise >= 0.4); +#endif + } + +#define GETINDEX(x, z, radius) (((z)+(radius))*(radius)*2 + (x)+(radius)) +#define CONTAINS(x, z, radius) \ + ((x) >= -(radius) && (x) < (radius) && (z) >= -(radius) && (z) < (radius)) + + for(s16 zi0=-cloud_radius_i; zi0= 0) + zi = cloud_radius_i - zi - 1; + if(xi >= 0) + xi = cloud_radius_i - xi - 1; + + u32 i = GETINDEX(xi, zi, cloud_radius_i); + + if(grid[i] == false) continue; - float b = m_brightness; - video::SColor c_top(128,b*240,b*240,b*255); - video::SColor c_side_1(128,b*230,b*230,b*255); - video::SColor c_side_2(128,b*220,b*220,b*245); - video::SColor c_bottom(128,b*205,b*205,b*230); + v2f p0 = v2f(xi,zi)*cloud_size + world_center_of_drawing_in_noise_f; video::S3DVertex v[4] = { @@ -146,55 +221,95 @@ void Clouds::render() video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 0) }; - f32 rx = cloud_size; + /*if(zi <= 0 && xi <= 0){ + v[0].Color.setBlue(255); + v[1].Color.setBlue(255); + v[2].Color.setBlue(255); + v[3].Color.setBlue(255); + }*/ + + f32 rx = cloud_size/2; f32 ry = 8*BS; - f32 rz = cloud_size; + f32 rz = cloud_size/2; for(int i=0; idrawVertexPrimitiveList(v, 4, indices, 2, video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT); } - } + + delete[] grid; + + // Restore fog settings + driver->setFog(fog_color, fog_type, fog_start, fog_end, fog_density, + fog_pixelfog, fog_rangefog); } void Clouds::step(float dtime) @@ -219,9 +339,11 @@ void Clouds::step(float dtime) m_time += dtime; } -void Clouds::update(v2f camera_p, float brightness) +void Clouds::update(v2f camera_p, video::SColorf color) { m_camera_pos = camera_p; - m_brightness = brightness; + m_color = color; + //m_brightness = brightness; + //dstream<<"m_brightness="< m_box; float m_cloud_y; float m_brightness; + video::SColorf m_color; u32 m_seed; v2f m_camera_pos; float m_time; diff --git a/src/daynightratio.h b/src/daynightratio.h new file mode 100644 index 000000000..1b075c4fa --- /dev/null +++ b/src/daynightratio.h @@ -0,0 +1,43 @@ +/* +Minetest-c55 +Copyright (C) 2010-2012 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 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 General Public License for more details. + +You should have received a copy of the GNU 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. +*/ + +#ifndef DAYNIGHTRATIO_HEADER +#define DAYNIGHTRATIO_HEADER + +inline u32 time_to_daynight_ratio(u32 time_of_day) +{ + s32 t = time_of_day%24000; + if(t < 4500 || t >= 19500) + return 150; + else if(t < 4750 || t >= 19250) + return 250; + else if(t < 5000 || t >= 19000) + return 350; + else if(t < 5250 || t >= 18750) + return 500; + else if(t < 5500 || t >= 18500) + return 675; + else if(t < 5750 || t >= 18250) + return 875; + else + return 1000; +} + +#endif + diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 97b00d421..a777ed736 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -71,7 +71,7 @@ void set_default_settings(Settings *settings) settings->setDefault("fps_max", "60"); // A bit more than the server will send around the player, to make fog blend well settings->setDefault("viewing_range_nodes_min", "35"); - settings->setDefault("viewing_range_nodes_max", "128"); + settings->setDefault("viewing_range_nodes_max", "160"); settings->setDefault("screenW", "800"); settings->setDefault("screenH", "600"); settings->setDefault("address", ""); @@ -121,11 +121,11 @@ void set_default_settings(Settings *settings) settings->setDefault("active_block_range", "2"); //settings->setDefault("max_simultaneous_block_sends_per_client", "1"); // This causes frametime jitter on client side, or does it? - settings->setDefault("max_simultaneous_block_sends_per_client", "2"); - settings->setDefault("max_simultaneous_block_sends_server_total", "8"); - settings->setDefault("max_block_send_distance", "7"); - settings->setDefault("max_block_generate_distance", "5"); - settings->setDefault("time_send_interval", "20"); + settings->setDefault("max_simultaneous_block_sends_per_client", "4"); + settings->setDefault("max_simultaneous_block_sends_server_total", "20"); + settings->setDefault("max_block_send_distance", "10"); + settings->setDefault("max_block_generate_distance", "6"); + settings->setDefault("time_send_interval", "5"); settings->setDefault("time_speed", "96"); settings->setDefault("server_unload_unused_data_timeout", "29"); settings->setDefault("server_map_save_interval", "5.3"); diff --git a/src/environment.cpp b/src/environment.cpp index 93649eed5..e713ab610 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -41,11 +41,15 @@ with this program; if not, write to the Free Software Foundation, Inc., #ifndef SERVER #include "clientmap.h" #endif +#include "daynightratio.h" #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" Environment::Environment(): - m_time_of_day(9000) + m_time_of_day(9000), + m_time_of_day_f(9000./24000), + m_time_of_day_speed(0), + m_time_counter(0) { } @@ -195,17 +199,35 @@ void Environment::printPlayers(std::ostream &o) } } -/*void Environment::setDayNightRatio(u32 r) -{ - getDayNightRatio() = r; -}*/ - u32 Environment::getDayNightRatio() { - //return getDayNightRatio(); return time_to_daynight_ratio(m_time_of_day); } +void Environment::stepTimeOfDay(float dtime) +{ + m_time_counter += dtime; + f32 speed = m_time_of_day_speed * 24000./(24.*3600); + u32 units = (u32)(m_time_counter*speed); + m_time_counter -= (f32)units / speed; + bool sync_f = false; + if(units > 0){ + // Sync at overflow + if(m_time_of_day + units >= 24000) + sync_f = true; + m_time_of_day = (m_time_of_day + units) % 24000; + if(sync_f) + m_time_of_day_f = (float)m_time_of_day / 24000.0; + } + if(!sync_f){ + m_time_of_day_f += m_time_of_day_speed/24/3600*dtime; + if(m_time_of_day_f > 1.0) + m_time_of_day_f -= 1.0; + if(m_time_of_day_f < 0.0) + m_time_of_day_f += 1.0; + } +} + /* ABMWithState */ @@ -893,6 +915,9 @@ void ServerEnvironment::step(float dtime) //TimeTaker timer("ServerEnv step"); + /* Step time of day */ + stepTimeOfDay(dtime); + /* Increment game time */ @@ -1861,6 +1886,9 @@ void ClientEnvironment::step(float dtime) { DSTACK(__FUNCTION_NAME); + /* Step time of day */ + stepTimeOfDay(dtime); + // Get some settings bool free_move = g_settings->getBool("free_move"); diff --git a/src/environment.h b/src/environment.h index a3a659c5b..04df9be48 100644 --- a/src/environment.h +++ b/src/environment.h @@ -74,27 +74,39 @@ public: core::list getPlayers(bool ignore_disconnected); void printPlayers(std::ostream &o); - //void setDayNightRatio(u32 r); u32 getDayNightRatio(); // 0-23999 virtual void setTimeOfDay(u32 time) { m_time_of_day = time; + m_time_of_day_f = (float)time / 24000.0; } u32 getTimeOfDay() - { - return m_time_of_day; - } + { return m_time_of_day; } + + float getTimeOfDayF() + { return m_time_of_day_f; } + + void stepTimeOfDay(float dtime); + + void setTimeOfDaySpeed(float speed) + { m_time_of_day_speed = speed; } + + float getTimeOfDaySpeed() + { return m_time_of_day_speed; } protected: // peer_ids in here should be unique, except that there may be many 0s core::list m_players; - // Brightness - //u32 m_daynight_ratio; // Time of day in milli-hours (0-23999); determines day and night u32 m_time_of_day; + // Time of day in 0...1 + float m_time_of_day_f; + float m_time_of_day_speed; + // Used to buffer dtime for adding to m_time_of_day + float m_time_counter; }; /* diff --git a/src/game.cpp b/src/game.cpp index 778615cf9..04b9f105d 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -54,6 +54,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "subgame.h" #include "quicktune_shortcutter.h" #include "clientmap.h" +#include "sky.h" /* Setting this to 1 enables a special camera mode that forces @@ -543,51 +544,6 @@ PointedThing getPointedThing(Client *client, v3f player_position, return result; } -void update_skybox(video::IVideoDriver* driver, ITextureSource *tsrc, - scene::ISceneManager* smgr, scene::ISceneNode* &skybox, - float brightness) -{ - if(skybox) - { - skybox->remove(); - } - - /*// Disable skybox if FarMesh is enabled - if(g_settings->getBool("enable_farmesh")) - return;*/ - - if(brightness >= 0.7) - { - skybox = smgr->addSkyBoxSceneNode( - tsrc->getTextureRaw("skybox2.png"), - tsrc->getTextureRaw("skybox3.png"), - tsrc->getTextureRaw("skybox1.png"), - tsrc->getTextureRaw("skybox1.png"), - tsrc->getTextureRaw("skybox1.png"), - tsrc->getTextureRaw("skybox1.png")); - } - else if(brightness >= 0.2) - { - skybox = smgr->addSkyBoxSceneNode( - tsrc->getTextureRaw("skybox2_dawn.png"), - tsrc->getTextureRaw("skybox3_dawn.png"), - tsrc->getTextureRaw("skybox1_dawn.png"), - tsrc->getTextureRaw("skybox1_dawn.png"), - tsrc->getTextureRaw("skybox1_dawn.png"), - tsrc->getTextureRaw("skybox1_dawn.png")); - } - else - { - skybox = smgr->addSkyBoxSceneNode( - tsrc->getTextureRaw("skybox2_night.png"), - tsrc->getTextureRaw("skybox3_night.png"), - tsrc->getTextureRaw("skybox1_night.png"), - tsrc->getTextureRaw("skybox1_night.png"), - tsrc->getTextureRaw("skybox1_night.png"), - tsrc->getTextureRaw("skybox1_night.png")); - } -} - /* Draws a screen with a single text on it. Text will be removed when the screen is drawn the next time. @@ -679,10 +635,6 @@ void the_game( //const s32 hotbar_imagesize = 64; s32 hotbar_imagesize = 48; - // The color of the sky - //video::SColor skycolor = video::SColor(255,140,186,250); - video::SColor bgcolor_bright = video::SColor(255,170,200,230); - /* Draw "Loading" screen */ @@ -891,13 +843,6 @@ void the_game( */ client.afterContentReceived(); - /* - Create skybox - */ - float old_brightness = 1.0; - scene::ISceneNode* skybox = NULL; - update_skybox(driver, tsrc, smgr, skybox, 1.0); - /* Create the camera node */ @@ -912,13 +857,18 @@ void the_game( Clouds */ - float cloud_height = BS*100; Clouds *clouds = NULL; if(g_settings->getBool("enable_clouds")) { - clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1, - cloud_height, time(0)); + clouds = new Clouds(smgr->getRootSceneNode(), smgr, -1, time(0)); } + + /* + Skybox thingy + */ + + Sky *sky = NULL; + sky = new Sky(smgr->getRootSceneNode(), smgr, -1); /* FarMesh @@ -1022,7 +972,7 @@ void the_game( // A test //throw con::PeerNotFoundException("lol"); - float brightness = 1.0; + float recent_turn_speed = 0.0; core::list frametime_log; @@ -1054,6 +1004,9 @@ void the_game( u32 show_profiler = 0; u32 show_profiler_max = 3; // Number of pages + float time_of_day = 0; + float time_of_day_smooth = 0; + /* Main loop */ @@ -1639,6 +1592,7 @@ void the_game( NOTE: Do this before client.setPlayerControl() to not cause a camera lag of one frame */ + float turn_amount = 0; if((device->isWindowActive() && noMenuActive()) || random_input) { if(!random_input) @@ -1668,11 +1622,14 @@ void the_game( dx -= dtime * keyspeed; if(input->isKeyDown(irr::KEY_RIGHT)) dx += dtime * keyspeed;*/ - - camera_yaw -= dx*0.2; - camera_pitch += dy*0.2; + + float d = 0.2; + camera_yaw -= dx*d; + camera_pitch += dy*d; if(camera_pitch < -89.5) camera_pitch = -89.5; if(camera_pitch > 89.5) camera_pitch = 89.5; + + turn_amount = v2f(dx, dy).getLength() * d; } input->setMousePos(displaycenter.X, displaycenter.Y); } @@ -1684,6 +1641,8 @@ void the_game( //infostream<<"window inactive"<getBrightness(); + direct_brightness = (float)client.getEnv().getClientMap() + .getBackgroundBrightness(MYMIN(fog_range*1.2, 60*BS), + daynight_ratio, (int)(old_brightness*255.5), &sunlight_seen) + / 255.0; + } + + time_of_day = client.getEnv().getTimeOfDayF(); + float maxsm = 0.05; + if(fabs(time_of_day - time_of_day_smooth) > maxsm && + fabs(time_of_day - time_of_day_smooth + 1.0) > maxsm && + fabs(time_of_day - time_of_day_smooth - 1.0) > maxsm) + time_of_day_smooth = time_of_day; + float todsm = 0.05; + if(time_of_day_smooth > 0.8 && time_of_day < 0.2) + time_of_day_smooth = time_of_day_smooth * (1.0-todsm) + + (time_of_day+1.0) * todsm; else - bgcolor = video::SColor( - 255, - bgcolor_bright.getRed() * brightness, - bgcolor_bright.getGreen() * brightness, - bgcolor_bright.getBlue() * brightness); - - /* - Update skybox - */ - if(fabs(brightness - old_brightness) > 0.01) - update_skybox(driver, tsrc, smgr, skybox, brightness); + time_of_day_smooth = time_of_day_smooth * (1.0-todsm) + + time_of_day * todsm; + + sky->update(time_of_day_smooth, time_brightness, direct_brightness, + sunlight_seen); + + float brightness = sky->getBrightness(); + video::SColor bgcolor = sky->getBgColor(); + video::SColor skycolor = sky->getSkyColor(); /* Update clouds */ - if(clouds) - { - clouds->step(dtime); - clouds->update(v2f(player_position.X, player_position.Z), - brightness); + if(clouds){ + if(sky->getCloudsVisible()){ + clouds->setVisible(true); + clouds->step(dtime); + clouds->update(v2f(player_position.X, player_position.Z), + sky->getCloudColor()); + } else{ + clouds->setVisible(false); + } } /* @@ -2208,35 +2201,17 @@ void the_game( brightness, farmesh_range); } - // Store brightness value - old_brightness = brightness; - /* Fog */ if(g_settings->getBool("enable_fog") == true && !force_fog_off) { - f32 range; - if(farmesh) - { - range = BS*farmesh_range; - } - else - { - range = draw_control.wanted_range*BS + 0.0*MAP_BLOCKSIZE*BS; - range *= 0.9; - if(draw_control.range_all) - range = 100000*BS; - /*if(range < 50*BS) - range = range * 0.5 + 25*BS;*/ - } - driver->setFog( bgcolor, video::EFT_FOG_LINEAR, - range*0.4, - range*1.0, + fog_range*0.4, + fog_range*1.0, 0.01, false, // pixel fog false // range fog @@ -2443,15 +2418,15 @@ void the_game( { TimeTaker timer("beginScene"); - driver->beginScene(false, true, bgcolor); //driver->beginScene(false, true, bgcolor); + //driver->beginScene(true, true, bgcolor); + driver->beginScene(true, true, skycolor); beginscenetime = timer.stop(true); } //timer3.stop(); - + //infostream<<"smgr->drawAll()"<drawAll(); @@ -2570,6 +2545,11 @@ void the_game( NULL); } + // Clear Z buffer + driver->clearZBuffer(); + // Draw some sky things + //draw_horizon(driver, camera.getCameraNode()); + /* End scene */ diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index e8ebecb5a..27ab2950b 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -46,6 +46,7 @@ extern "C" { #include "content_nodemeta.h" #include "utility.h" #include "tool.h" +#include "daynightratio.h" static void stackDump(lua_State *L, std::ostream &o) { diff --git a/src/server.cpp b/src/server.cpp index 2139df957..f3bf1e23f 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -854,7 +854,6 @@ Server::Server( m_craftdef(createCraftDefManager()), m_thread(this), m_emergethread(this), - m_time_counter(0), m_time_of_day_send_timer(0), m_uptime(0), m_shutdown_requested(false), @@ -1197,19 +1196,12 @@ void Server::AsyncRunStep() } /* - Update m_time_of_day and overall game time + Update time of day and overall game time */ { JMutexAutoLock envlock(m_env_mutex); - m_time_counter += dtime; - f32 speed = g_settings->getFloat("time_speed") * 24000./(24.*3600); - u32 units = (u32)(m_time_counter*speed); - m_time_counter -= (f32)units / speed; - - m_env->setTimeOfDay((m_env->getTimeOfDay() + units) % 24000); - - //infostream<<"Server: m_time_of_day = "<setTimeOfDaySpeed(g_settings->getFloat("time_speed")); /* Send to clients at constant intervals @@ -1231,7 +1223,7 @@ void Server::AsyncRunStep() //Player *player = m_env->getPlayer(client->peer_id); SharedBuffer data = makePacket_TOCLIENT_TIME_OF_DAY( - m_env->getTimeOfDay()); + m_env->getTimeOfDay(), g_settings->getFloat("time_speed")); // Send as reliable m_con.Send(client->peer_id, 0, data, true); } @@ -2216,7 +2208,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) // Send time of day { SharedBuffer data = makePacket_TOCLIENT_TIME_OF_DAY( - m_env->getTimeOfDay()); + m_env->getTimeOfDay(), g_settings->getFloat("time_speed")); m_con.Send(peer_id, 0, data, true); } diff --git a/src/server.h b/src/server.h index f149ac687..32ce8eb53 100644 --- a/src/server.h +++ b/src/server.h @@ -426,11 +426,6 @@ public: core::list getPlayerInfo(); - /*u32 getDayNightRatio() - { - return time_to_daynight_ratio(m_time_of_day.get()); - }*/ - // Environment must be locked when called void setTimeOfDay(u32 time) { @@ -714,10 +709,6 @@ private: Time related stuff */ - // 0-23999 - //MutexedVariable m_time_of_day; - // Used to buffer dtime for adding to m_time_of_day - float m_time_counter; // Timer for sending time of day over network float m_time_of_day_send_timer; // Uptime of server in seconds diff --git a/src/sky.cpp b/src/sky.cpp new file mode 100644 index 000000000..ba9b17493 --- /dev/null +++ b/src/sky.cpp @@ -0,0 +1,446 @@ +#include "sky.h" +#include "IVideoDriver.h" +#include "ISceneManager.h" +#include "ICameraSceneNode.h" +#include "S3DVertex.h" +#include "utility.h" // MYMIN +#include "tile.h" // getTexturePath +#include "noise.h" // easeCurve +#include "main.h" // g_profiler +#include "profiler.h" + +//! constructor +Sky::Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id): + scene::ISceneNode(parent, mgr, id), + 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) +{ + setAutomaticCulling(scene::EAC_OFF); + Box.MaxEdge.set(0,0,0); + Box.MinEdge.set(0,0,0); + + // create material + + video::SMaterial mat; + mat.Lighting = false; + mat.ZBuffer = video::ECFN_NEVER; + mat.ZWriteEnable = false; + mat.AntiAliasing=0; + mat.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE; + mat.TextureLayer[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE; + mat.BackfaceCulling = false; + + m_materials[0] = mat; + + m_materials[1] = mat; + //m_materials[1].MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; + m_materials[1].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; + + m_materials[2] = mat; + m_materials[2].setTexture(0, mgr->getVideoDriver()->getTexture( + getTexturePath("sunrisebg.png").c_str())); + m_materials[2].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; + //m_materials[2].MaterialType = video::EMT_TRANSPARENT_ADD_COLOR; + + for(u32 i=0; iregisterNodeForRendering(this, scene::ESNRP_SKY_BOX); + + scene::ISceneNode::OnRegisterSceneNode(); +} + +const core::aabbox3d& Sky::getBoundingBox() const +{ + return Box; +} + +//! renders the node. +void Sky::render() +{ + video::IVideoDriver* driver = SceneManager->getVideoDriver(); + scene::ICameraSceneNode* camera = SceneManager->getActiveCamera(); + + if (!camera || !driver) + return; + + ScopeProfiler sp(g_profiler, "Sky::render()", SPT_AVG); + + // draw perspective skybox + + core::matrix4 translate(AbsoluteTransformation); + translate.setTranslation(camera->getAbsolutePosition()); + + // Draw the sky box between the near and far clip plane + const f32 viewDistance = (camera->getNearValue() + camera->getFarValue()) * 0.5f; + core::matrix4 scale; + scale.setScale(core::vector3df(viewDistance, viewDistance, viewDistance)); + + driver->setTransform(video::ETS_WORLD, translate * scale); + + 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); + video::SColorf suncolor2_f(1, 1, 1, 1); + 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.41; + float wn = nightlength / 2; + float wicked_time_of_day = 0; + if(m_time_of_day > wn && m_time_of_day < 1.0 - wn) + wicked_time_of_day = (m_time_of_day - wn)/(1.0-wn*2)*0.5 + 0.25; + else if(m_time_of_day < 0.5) + wicked_time_of_day = m_time_of_day / wn * 0.25; + else + wicked_time_of_day = 1.0 - ((1.0-m_time_of_day) / wn * 0.25); + /*std::cerr<<"time_of_day="< " + <<"wicked_time_of_day="<setMaterial(m_materials[2]); + { + 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 = easeCurve(MYMAX(0, MYMIN(1, a_))); + //std::cerr<<"a_="< + +#ifndef SKY_HEADER +#define SKY_HEADER + +#define SKY_MATERIAL_COUNT 3 +#define SKY_STAR_COUNT 200 + +// Skybox, rendered with zbuffer turned off, before all other nodes. +class Sky : public scene::ISceneNode +{ +public: + //! constructor + Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id); + + virtual void OnRegisterSceneNode(); + + //! renders the node. + virtual void render(); + + virtual const core::aabbox3d& getBoundingBox() const; + + // Used by Irrlicht for optimizing rendering + virtual video::SMaterial& getMaterial(u32 i) + { return m_materials[i]; } + + // Used by Irrlicht for optimizing rendering + virtual u32 getMaterialCount() const + { return SKY_MATERIAL_COUNT; } + + void update(float m_time_of_day, float time_brightness, + float direct_brightness, bool sunlight_seen); + + float getBrightness(){ return m_brightness; } + video::SColor getBgColor(){ return m_bgcolor; } + video::SColor getSkyColor(){ return m_skycolor; } + + bool getCloudsVisible(){ return m_clouds_visible; } + video::SColorf getCloudColor(){ return m_cloudcolor_f; } + +private: + core::aabbox3d Box; + video::SMaterial m_materials[SKY_MATERIAL_COUNT]; + + bool m_first_update; + float m_time_of_day; + float m_time_brightness; + bool m_sunlight_seen; + float m_brightness; + float m_cloud_brightness; + bool m_clouds_visible; + video::SColorf m_bgcolor_bright_f; + video::SColorf m_skycolor_bright_f; + video::SColorf m_cloudcolor_bright_f; + video::SColor m_bgcolor; + video::SColor m_skycolor; + video::SColorf m_cloudcolor_f; + v3f m_stars[SKY_STAR_COUNT]; + u16 m_star_indices[SKY_STAR_COUNT*4]; + video::S3DVertex m_star_vertices[SKY_STAR_COUNT*4]; +}; + +#endif + diff --git a/src/utility.h b/src/utility.h index 15c013735..fbd76f230 100644 --- a/src/utility.h +++ b/src/utility.h @@ -1751,21 +1751,6 @@ std::string deSerializeJsonString(std::istream &is); // -inline u32 time_to_daynight_ratio(u32 time_of_day) -{ - s32 t = time_of_day%24000; - if(t < 4500 || t >= 19500) - return 150; - else if(t < 5000 || t >= 19000) - return 350; - else if(t < 5500 || t >= 18500) - return 500; - else if(t < 6000 || t >= 18000) - return 750; - else - return 1000; -} - // Random helper. Usually d=BS inline core::aabbox3d getNodeBox(v3s16 p, float d) {