moving sun and moon, plus seasons, and moon phases

This commit is contained in:
darkrose 2015-08-26 20:22:15 +10:00
parent c721e75dbf
commit 93d3686807
28 changed files with 939 additions and 173 deletions

BIN
data/textures/moon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 200 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 200 B

BIN
data/textures/sun.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 439 B

View File

@ -237,6 +237,7 @@ endif()
set(voxelands_SRCS
${common_SRCS}
${audio_SRCS}
sky.cpp
hud.cpp
content_mapblock.cpp
content_cao.cpp

View File

@ -396,8 +396,12 @@ void Camera::updateViewingRange(f32 frametime_in)
m_range_old = new_range;
m_frametime_old = frametime;
// 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(2000*BS);
}else{
m_cameranode->setFarValue(viewing_range_max * BS * 10);
}
}
void Camera::wield(const InventoryItem* item)

View File

@ -225,12 +225,14 @@ Client::Client(
m_inventory_updated(false),
m_pointed_node(-32768,-32768,-32768),
m_pointed_content(CONTENT_IGNORE),
m_time_of_day(0),
m_form_open(false),
m_map_seed(0),
m_map_type(MGT_DEFAULT),
m_password(password),
m_access_denied(false)
m_access_denied(false),
m_time_of_day_set(false),
m_last_time_of_day_f(-1),
m_time_of_day_update_timer(0)
{
m_mesh_update_thread.m_env = &m_env;
m_packetcounter_timer = 0.0;
@ -309,6 +311,8 @@ void Client::step(float dtime)
m_ignore_damage_timer = 0.0;
}
m_time_of_day_update_timer += dtime;
//infostream<<"Client steps "<<dtime<<std::endl;
{
@ -1196,25 +1200,42 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
if(datasize < 4)
return;
u32 time = 0;
u16 time_of_day = readU16(&data[2]);
time_of_day = time_of_day % 24000;
//infostream<<"Client: time_of_day="<<time_of_day<<std::endl;
/*
time_of_day:
0 = midnight
12000 = midday
*/
{
m_env.setTimeOfDay(time_of_day);
u32 dr = m_env.getDayNightRatio();
infostream<<"Client: time_of_day="<<time_of_day
<<", dr="<<dr
<<std::endl;
float time_speed = 0;
if (datasize >= 2 + 2 + 4 + 4) {
time = readU32(&data[4]);
time_speed = readF1000(&data[8]);
}else{
// Old message; try to approximate speed of time by ourselves
float time_of_day_f = (float)time_of_day / 24000.0;
float tod_diff_f = 0;
if (time_of_day_f < 0.2 && m_last_time_of_day_f > 0.8) {
tod_diff_f = time_of_day_f - m_last_time_of_day_f + 1.0;
}else{
tod_diff_f = time_of_day_f - m_last_time_of_day_f;
}
m_last_time_of_day_f = time_of_day_f;
float time_diff = m_time_of_day_update_timer;
m_time_of_day_update_timer = 0;
if (m_time_of_day_set) {
time_speed = 3600.0*24.0 * tod_diff_f / time_diff;
infostream<<"Client: Measured time_of_day speed (old format): "
<<time_speed<<" tod_diff_f="<<tod_diff_f
<<" time_diff="<<time_diff<<std::endl;
}
}
// Update environment
m_env.setTimeOfDay(time_of_day);
m_env.setTimeOfDaySpeed(time_speed);
m_env.setTime(time);
m_time_of_day_set = true;
u32 dr = m_env.getDayNightRatio();
verbosestream<<"Client: time_of_day="<<time_of_day
<<" time_speed="<<time_speed
<<" dr="<<dr<<std::endl;
}
break;
case TOCLIENT_CHAT_MESSAGE:
@ -2199,11 +2220,6 @@ void Client::printDebugInfo(std::ostream &os)
{
}
u32 Client::getDayNightRatio()
{
return m_env.getDayNightRatio();
}
u16 Client::getHP()
{
Player *player = m_env.getLocalPlayer();
@ -2278,11 +2294,11 @@ void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool refresh_only)
data->m_env = &m_env;
if (refresh_only) {
data->m_daynight_ratio = getDayNightRatio();
data->m_daynight_ratio = m_env.getDayNightRatio();
data->m_refresh_only = true;
}else{
{
data->fill(getDayNightRatio(), b);
data->fill(m_env.getDayNightRatio(), b);
}
data->m_sounds = &b->m_sounds;

View File

@ -266,8 +266,6 @@ public:
// Prints a line or two of info
void printDebugInfo(std::ostream &os);
u32 getDayNightRatio();
u16 getHP();
u16 getAir();
u16 getHunger();
@ -394,9 +392,6 @@ private:
PacketCounter m_packetcounter;
// Received from the server. 0-23999
u32 m_time_of_day;
bool m_form_open;
Queue<std::wstring> m_chat_queue;
@ -413,7 +408,10 @@ private:
Queue<ClientEvent> m_client_event_queue;
friend class FarMesh;
// time_of_day speed approximation for old protocol
bool m_time_of_day_set;
float m_last_time_of_day_f;
float m_time_of_day_update_timer;
};
#endif // !SERVER

View File

@ -119,6 +119,7 @@ enum ToClientCommand
/*
u16 command
u16 time (0-23999)
f1000 time_speed (1509.00+)
*/
TOCLIENT_CHAT_MESSAGE = 0x30,
@ -431,11 +432,13 @@ enum ToServerCommand
*/
};
inline SharedBuffer<u8> makePacket_TOCLIENT_TIME_OF_DAY(u16 time)
inline SharedBuffer<u8> makePacket_TOCLIENT_TIME_OF_DAY(u16 time_of_day, float time_speed, u32 time)
{
SharedBuffer<u8> data(2+2);
SharedBuffer<u8> data(2+2+4+4);
writeU16(&data[0], TOCLIENT_TIME_OF_DAY);
writeU16(&data[2], time);
writeU16(&data[2], time_of_day);
writeU32(&data[4], time);
writeF1000(&data[8], time_speed);
return data;
}

View File

@ -35,11 +35,9 @@ Clouds::Clouds(
scene::ISceneNode* parent,
scene::ISceneManager* mgr,
s32 id,
float cloud_y,
u32 seed
):
scene::ISceneNode(parent, mgr, id),
m_cloud_y(cloud_y),
m_seed(seed),
m_camera_pos(0,0),
m_camera_offset(0,0,0),
@ -50,14 +48,16 @@ Clouds::Clouds(
m_material.setFlag(video::EMF_LIGHTING, false);
m_material.setFlag(video::EMF_BACK_FACE_CULLING, false);
m_material.setFlag(video::EMF_BILINEAR_FILTER, false);
m_material.setFlag(video::EMF_FOG_ENABLE, false);
m_material.setFlag(video::EMF_FOG_ENABLE, true);
m_material.setFlag(video::EMF_ANTI_ALIASING, true);
m_box = core::aabbox3d<f32>(-BS*1000000,cloud_y-BS,-BS*1000000, BS*1000000,cloud_y+BS,BS*1000000);
m_cloud_y = BS*100;
m_box = core::aabbox3d<f32>(-BS*1000000,m_cloud_y-BS,-BS*1000000, BS*1000000,m_cloud_y+BS,BS*1000000);
m_face_count = 1;
if (g_settings->getBool("enable_3d_clouds"))
m_face_count = 6;
}
Clouds::~Clouds()
@ -92,8 +92,9 @@ 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;
@ -112,15 +113,67 @@ void Clouds::render()
center_of_drawing_in_noise_i.Y * cloud_size
) + world_cloud_origin_pos_f;
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 = 1.0;
c_side_1_f.a = 1.0;
c_side_2_f.a = 1.0;
c_bottom_f.a = 1.0;
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();
video::SColor c[6] = {
video::SColor(128,m_brightness*240,m_brightness*240,m_brightness*255),
video::SColor(128,m_brightness*230,m_brightness*230,m_brightness*255),
video::SColor(128,m_brightness*220,m_brightness*220,m_brightness*245),
video::SColor(128,m_brightness*230,m_brightness*230,m_brightness*255),
video::SColor(128,m_brightness*220,m_brightness*220,m_brightness*245),
video::SColor(128,m_brightness*205,m_brightness*205,m_brightness*230)
c_top,
c_side_1,
c_side_2,
c_side_1,
c_side_2,
c_bottom
};
// 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
);
for (s16 zi=-cloud_radius_i; zi<cloud_radius_i; zi++)
for (s16 xi=-cloud_radius_i; xi<cloud_radius_i; xi++) {
v2s16 p_in_noise_i(
@ -203,6 +256,16 @@ void Clouds::render()
}
}
driver->setFog(
fog_color,
fog_type,
fog_start,
fog_end,
fog_density,
fog_pixelfog,
fog_rangefog
);
}
void Clouds::step(float dtime)
@ -210,9 +273,9 @@ 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;
}

View File

@ -36,7 +36,6 @@ public:
scene::ISceneNode* parent,
scene::ISceneManager* mgr,
s32 id,
float cloud_y,
u32 seed
);
@ -71,7 +70,7 @@ public:
void step(float dtime);
void update(v2f camera_p, float brightness);
void update(v2f camera_p, video::SColorf color);
void updateCameraOffset(v3s16 camera_offset)
{
@ -83,6 +82,7 @@ private:
core::aabbox3d<f32> m_box;
float m_cloud_y;
float m_brightness;
video::SColorf m_color;
u32 m_seed;
v2f m_camera_pos;
v3s16 m_camera_offset;

View File

@ -143,11 +143,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_simultaneous_block_sends_per_client", "4");
settings->setDefault("max_simultaneous_block_sends_server_total", "20");
settings->setDefault("max_block_send_distance", "7");
settings->setDefault("max_block_generate_distance", "5");
settings->setDefault("time_send_interval", "20");
settings->setDefault("time_send_interval", "5");
settings->setDefault("time_speed", "96");
settings->setDefault("server_unload_unused_data_timeout", "19");
settings->setDefault("server_map_save_interval", "1.238");

View File

@ -44,7 +44,11 @@
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
Environment::Environment():
m_time_of_day(9000)
m_time(0),
m_time_of_day(9000),
m_time_of_day_f(9000./24000),
m_time_of_day_speed(0),
m_time_counter(0)
{
}
@ -195,15 +199,36 @@ 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);
return time_to_daynight_ratio(m_time_of_day_f*24000.0);
}
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) {
m_time++;
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;
}
}
/*
@ -469,6 +494,7 @@ void ServerEnvironment::saveMeta(const std::string &savedir)
Settings args;
args.setU64("game_time", m_game_time);
args.setU64("time_of_day", getTimeOfDay());
args.setU64("world_time",m_time);
args.writeLines(os);
os<<"EnvArgsEnd\n";
}
@ -514,6 +540,13 @@ void ServerEnvironment::loadMeta(const std::string &savedir)
// This is not as important
m_time_of_day = 9000;
}
try{
m_time = args.getU64("world_time");
}catch(SettingNotFoundException &e){
// This is not as important
m_time = 0;
}
}
void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
@ -706,6 +739,8 @@ void ServerEnvironment::step(float dtime)
//TimeTaker timer("ServerEnv step");
stepTimeOfDay(dtime);
// Get some settings
bool footprints = g_settings->getBool("enable_footprints");
@ -3368,6 +3403,8 @@ void ClientEnvironment::step(float dtime)
{
DSTACK(__FUNCTION_NAME);
stepTimeOfDay(dtime);
// Get some settings
bool footprints = g_settings->getBool("enable_footprints");

View File

@ -132,13 +132,13 @@ public:
void printPlayers(std::ostream &o);
virtual bool propogateEnergy(u8 level, v3s16 powersrc, v3s16 signalsrc, v3s16 pos, core::map<v3s16,MapBlock*> &modified_blocks) {return false;};
//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()
@ -146,13 +146,60 @@ public:
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;
}
float getMoonPhase()
{
float d = m_time%20;
return d/20.0;
}
u32 getTime()
{
return m_time;
}
void setTime(u32 t)
{
m_time = t;
}
u32 getSeason()
{
return (m_time%240)/60;
}
u32 getYear()
{
return m_time/240;
}
protected:
// peer_ids in here should be unique, except that there may be many 0s
core::list<Player*> m_players;
// Brightness
//u32 m_daynight_ratio;
u32 m_time;
// 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;
// A list of positions and nodes that should be set *after* the entire loop runs
std::map<v3s16,MapNode> m_delayed_node_changes;
};

View File

@ -53,6 +53,7 @@
#include "main.h"
#endif
#include "hud.h"
#include "sky.h"
/*
TODO: Move content-aware stuff to separate file by adding properties
@ -555,40 +556,6 @@ void getPointedNode(Client *client, v3f player_position,
}
}
void update_skybox(video::IVideoDriver* driver,
scene::ISceneManager* smgr, scene::ISceneNode* &skybox,
float brightness)
{
if (skybox)
skybox->remove();
if (brightness >= 0.5) {
skybox = smgr->addSkyBoxSceneNode(
driver->getTexture(getTexturePath("skybox2.png").c_str()),
driver->getTexture(getTexturePath("skybox3.png").c_str()),
driver->getTexture(getTexturePath("skybox1.png").c_str()),
driver->getTexture(getTexturePath("skybox1.png").c_str()),
driver->getTexture(getTexturePath("skybox1.png").c_str()),
driver->getTexture(getTexturePath("skybox1.png").c_str()));
}else if(brightness >= 0.2) {
skybox = smgr->addSkyBoxSceneNode(
driver->getTexture(getTexturePath("skybox2_dawn.png").c_str()),
driver->getTexture(getTexturePath("skybox3_dawn.png").c_str()),
driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()),
driver->getTexture(getTexturePath("skybox1_dawn.png").c_str()));
}else{
skybox = smgr->addSkyBoxSceneNode(
driver->getTexture(getTexturePath("skybox2_night.png").c_str()),
driver->getTexture(getTexturePath("skybox3_night.png").c_str()),
driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
driver->getTexture(getTexturePath("skybox1_night.png").c_str()),
driver->getTexture(getTexturePath("skybox1_night.png").c_str()));
}
}
/*
Draws a screen with logo and text on it.
Text will be removed when the screen is drawn the next time.
@ -688,8 +655,6 @@ void the_game(
const s32 hotbar_itemcount = 8;
s32 hotbar_imagesize = 48;
// The color of the sky
video::SColor bgcolor_bright = video::SColor(255,167,167,200);
/*
Draw "Loading" screen
*/
@ -812,13 +777,6 @@ void the_game(
return;
}
/*
Create skybox
*/
float old_brightness = 1.0;
scene::ISceneNode* skybox = NULL;
update_skybox(driver, smgr, skybox, 1.0);
/*
Create the camera node
*/
@ -833,10 +791,16 @@ 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
*/
Sky *sky = NULL;
sky = new Sky(smgr->getRootSceneNode(), smgr, -1);
/*
Move into game
@ -952,6 +916,10 @@ void the_game(
u32 lasttime = device->getTimer()->getTime();
v3s16 lastpointed(0,0,0);
float recent_turn_speed = 0.0;
float time_of_day = 0;
float time_of_day_smooth = 0;
while (device->run() && kill == false) {
//std::cerr<<"frame"<<std::endl;
@ -1391,6 +1359,7 @@ void the_game(
NOTE: Do this before client.setPlayerControl() to not cause a camera lag of one frame
*/
float turn_amount = 0.0;
if ((device->isWindowActive() && noMenuActive()) || random_input) {
if (!random_input) {
// Mac OSX gets upset if this is set every frame
@ -1411,8 +1380,12 @@ void the_game(
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;
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);
}else{
@ -1424,6 +1397,8 @@ void the_game(
first_loop_after_window_activation = true;
}
recent_turn_speed = recent_turn_speed * 0.9 + turn_amount * 0.1;
/*
Player speed control
*/
@ -1893,33 +1868,66 @@ void the_game(
input->resetLeftReleased();
input->resetRightReleased();
/*
Calculate stuff for drawing
*/
float fog_range = 0.0;
if (draw_control.range_all) {
fog_range = 100000*BS;
}else{
fog_range = (draw_control.wanted_range+MAP_BLOCKSIZE)*(BS*1.5);
fog_range *= 0.9;
}
u32 daynight_ratio = client.getDayNightRatio();
u8 l = decode_light((daynight_ratio * LIGHT_SUN) / 1000);
video::SColor bgcolor = video::SColor(
255,
bgcolor_bright.getRed() * l / 255,
bgcolor_bright.getGreen() * l / 255,
bgcolor_bright.getBlue() * l / 255
);
u32 daynight_ratio = client.getEnv().getDayNightRatio();
float time_brightness = (float)decode_light((daynight_ratio * LIGHT_SUN) / 1000) / 255.0;
float direct_brightness = 0;
bool sunlight_seen = false;
if (free_move) {
direct_brightness = time_brightness;
sunlight_seen = true;
}else{
ScopeProfiler sp(g_profiler, "Detecting background light", SPT_AVG);
float old_brightness = sky->getBrightness();
direct_brightness = (float)client.getEnv().getClientMap().getBackgroundBrightness(
MYMIN(fog_range*1.2, 60*BS),
daynight_ratio,
(int)(old_brightness*255.5),
&sunlight_seen
);
direct_brightness /= 255.0;
}
float brightness = (float)l/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{
time_of_day_smooth = time_of_day_smooth * (1.0-todsm) + time_of_day * todsm;
}
/*
Update skybox
*/
if (fabs(brightness - old_brightness) > 0.01)
update_skybox(driver, smgr, skybox, brightness);
float moon_phase = client.getEnv().getMoonPhase();
sky->update(time_of_day_smooth, moon_phase, time_brightness, direct_brightness, sunlight_seen);
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), 0.05+brightness*0.95);
if (sky->getCloudsVisible()) {
clouds->setVisible(true);
clouds->step(dtime);
clouds->update(v2f(player_position.X, player_position.Z), sky->getCloudColor());
}else{
clouds->setVisible(false);
}
}
/*
@ -1928,24 +1936,16 @@ void the_game(
allparticles_step(dtime, client.getEnv());
allparticlespawners_step(dtime, client.getEnv());
// Store brightness value
old_brightness = brightness;
/*
Fog
*/
if (enable_fog && !force_fog_off) {
f32 range = draw_control.wanted_range*BS + MAP_BLOCKSIZE*BS*1.5;
range *= 0.9;
if (draw_control.range_all)
range = 100000*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
@ -2166,7 +2166,7 @@ void the_game(
{
TimeTaker timer("beginScene");
driver->beginScene(false, true, bgcolor);
driver->beginScene(true, true, skycolor);
timer.stop(true);
}
@ -2330,6 +2330,9 @@ void the_game(
NULL);
}
// Clear Z buffer
driver->clearZBuffer();
/*
End scene
*/

View File

@ -3190,7 +3190,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
*/
int time1 = time(0);
//u32 daynight_ratio = m_client->getDayNightRatio();
u32 daynight_ratio = m_client->getEnv().getDayNightRatio();
m_camera_mutex.Lock();
v3f camera_position = m_camera_position;
@ -3351,7 +3351,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
// Mesh has been expired: generate new mesh
if (block->mesh) {
JMutexAutoLock lock(block->mesh_mutex);
block->mesh->refresh(m_client->getDayNightRatio());
block->mesh->refresh(daynight_ratio);
block->setMeshExpired(false);
}else{
m_client->addUpdateMeshTask(block->getPos(),false,true);
@ -3432,7 +3432,6 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
sector_blocks_drawn++;
blocks_drawn++;
} // foreach sectorblocks
if (sector_blocks_drawn != 0)
@ -3549,6 +3548,200 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
<<", rendered "<<vertex_count<<" vertices."<<std::endl;*/
}
static bool getVisibleBrightness(
Map *map,
v3f p0,
v3f dir,
float step,
float step_multiplier,
float start_distance,
float end_distance,
u32 daylight_factor,
float sunlight_min_d,
int *result,
bool *sunlight_seen
)
{
int brightness_sum = 0;
int brightness_count = 0;
float distance = start_distance;
dir.normalize();
v3f pf = p0;
pf += dir * distance;
int noncount = 0;
bool nonlight_seen = false;
bool allow_allowing_non_sunlight_propagates = false;
bool allow_non_sunlight_propagates = false;
// Check content nearly at camera position
{
v3s16 p = floatToInt(p0 /*+ dir * 3*BS*/, BS);
MapNode n = map->getNodeNoEx(p);
ContentFeatures &nf = content_features(n.getContent());
if (nf.param_type == CPT_LIGHT && !nf.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);
ContentFeatures &nf = content_features(n.getContent());
if (
allow_allowing_non_sunlight_propagates
&& i == 0
&& nf.param_type == CPT_LIGHT
&& !nf.sunlight_propagates
) {
allow_non_sunlight_propagates = true;
}
if (
nf.param_type != CPT_LIGHT
|| (
!nf.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
&& n.getLight(LIGHTBANK_DAY) == LIGHT_SUN
)
*sunlight_seen = true;
noncount = 0;
brightness_sum += decode_light(n.getLightBlend(daylight_factor));
brightness_count++;
}
*result = 0;
if (brightness_count == 0)
return false;
*result = brightness_sum / brightness_count;
return true;
}
int ClientMap::getBackgroundBrightness(
float max_d,
u32 daylight_factor,
int oldvalue,
bool *sunlight_seen_result
)
{
static v3f z_directions[50] = {
v3f(-100, 0, 0)
};
static f32 z_offsets[sizeof(z_directions)/sizeof(*z_directions)] = {
-1000,
};
if (z_directions[0].X < -99) {
for (u32 i=0; i<sizeof(z_directions)/sizeof(*z_directions); i++) {
z_directions[i] = v3f(
0.01 * myrand_range(-80, 80),
1.0,
0.01 * myrand_range(-80, 80)
);
z_offsets[i] = 0.01 * myrand_range(0,100);
}
}
//std::cerr<<"In goes "<<PP(m_camera_direction)<<", out comes ";
int sunlight_seen_count = 0;
float sunlight_min_d = max_d*0.8;
if (sunlight_min_d > 35*BS)
sunlight_min_d = 35*BS;
core::array<int> values;
for (u32 i=0; i<sizeof(z_directions)/sizeof(*z_directions); i++) {
v3f z_dir = z_directions[i];
z_dir.normalize();
core::CMatrix4<f32> 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,
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;
for (u32 i=first_value_i; i < first_value_i+num_values_to_use; i++) {
brightness_sum += values[i];
brightness_count++;
}
int ret = 0;
if (brightness_count == 0) {
MapNode n = getNodeNoEx(floatToInt(m_camera_position, BS));
if (content_features(n).param_type == CPT_LIGHT) {
ret = decode_light(n.getLightBlend(daylight_factor));
}else{
ret = oldvalue;
}
}else{
ret = brightness_sum / brightness_count;
}
*sunlight_seen_result = (sunlight_seen_count > 0);
return ret;
}
void ClientMap::renderPostFx()
{
// Sadly ISceneManager has no "post effects" render pass, in that case we

View File

@ -548,6 +548,8 @@ public:
void renderMap(video::IVideoDriver* driver, s32 pass);
int getBackgroundBrightness(float max_d, u32 daylight_factor, int oldvalue, bool *sunlight_seen_result);
void renderPostFx();
/*

View File

@ -965,7 +965,6 @@ Server::Server(
m_banmanager(mapsavedir+DIR_DELIM+"ipban.txt"),
m_thread(this),
m_emergethread(this),
m_time_counter(0),
m_time_of_day_send_timer(0),
m_uptime(0),
m_mapsavedir(mapsavedir),
@ -1217,41 +1216,31 @@ 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;
float time_speed = g_settings->getFloat("time_speed");
m_env.setTimeOfDay((m_env.getTimeOfDay() + units) % 24000);
//infostream<<"Server: m_time_of_day = "<<m_time_of_day.get()<<std::endl;
m_env.setTimeOfDaySpeed(time_speed);
/*
Send to clients at constant intervals
*/
m_time_of_day_send_timer -= dtime;
if(m_time_of_day_send_timer < 0.0)
{
if (m_time_of_day_send_timer < 0.0) {
m_time_of_day_send_timer = g_settings->getFloat("time_send_interval");
//JMutexAutoLock envlock(m_env_mutex);
JMutexAutoLock conlock(m_con_mutex);
for(core::map<u16, RemoteClient*>::Iterator
i = m_clients.getIterator();
i.atEnd() == false; i++)
{
for (core::map<u16, RemoteClient*>::Iterator i = m_clients.getIterator(); i.atEnd() == false; i++) {
RemoteClient *client = i.getNode()->getValue();
//Player *player = m_env.getPlayer(client->peer_id);
SharedBuffer<u8> data = makePacket_TOCLIENT_TIME_OF_DAY(
m_env.getTimeOfDay());
SharedBuffer<u8> data = makePacket_TOCLIENT_TIME_OF_DAY(m_env.getTimeOfDay(),time_speed, m_env.getTime());
// Send as reliable
m_con.Send(client->peer_id, 0, data, true);
}
@ -2087,7 +2076,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
// Send time of day
{
SharedBuffer<u8> data = makePacket_TOCLIENT_TIME_OF_DAY(m_env.getTimeOfDay());
SharedBuffer<u8> data = makePacket_TOCLIENT_TIME_OF_DAY(m_env.getTimeOfDay(),g_settings->getFloat("time_speed"),m_env.getTime());
m_con.Send(peer_id, 0, data, true);
}

View File

@ -391,11 +391,6 @@ public:
core::list<PlayerInfo> getPlayerInfo();
/*u32 getDayNightRatio()
{
return time_to_daynight_ratio(m_time_of_day.get());
}*/
// Environment must be locked when called
void setTimeOfDay(u32 time)
{
@ -640,10 +635,6 @@ private:
Time related stuff
*/
// 0-23999
//MutexedVariable<u32> 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

328
src/sky.cpp Normal file
View File

@ -0,0 +1,328 @@
/************************************************************************
* Minetest-c55
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
*
* sky.cpp
* voxelands - 3d voxel world sandbox game
* Copyright (C) Lisa 'darkrose' Milne 2013-2015 <lisa@ltmnet.com>
*
* 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 3 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, see <http://www.gnu.org/licenses/>
*
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
* for Voxelands.
************************************************************************/
#include "sky.h"
#include "IVideoDriver.h"
#include "ISceneManager.h"
#include "ICameraSceneNode.h"
#include "S3DVertex.h"
#include "utility.h" // MYMIN
#include "path.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_moon_phase(0.0),
m_moon_phase_pending(0.0),
m_bgcolor_bright_f(1,1,1,1),
m_skycolor_bright_f(1,0,0,0),
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_ALPHA_CHANNEL;
m_materials[2] = mat;
m_materials[2].setTexture(0, mgr->getVideoDriver()->getTexture(getTexturePath("sun.png").c_str()));
m_materials[2].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
m_materials[3] = mat;
m_materials[3].setTexture(0, mgr->getVideoDriver()->getTexture(getTexturePath("moon.png").c_str()));
m_materials[3].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
for (u32 i=0; i<SKY_STAR_COUNT; i++) {
m_stars[i] = v3f(
myrand_range(-10000,10000),
myrand_range(-10000,10000),
myrand_range(-10000,10000)
);
m_stars[i].normalize();
}
}
void Sky::OnRegisterSceneNode()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this, scene::ESNRP_SKY_BOX);
scene::ISceneNode::OnRegisterSceneNode();
}
const core::aabbox3d<f32>& 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)
return;
float sunsize = 0.07;
float moonsize = 0.04;
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);
}
const f32 t = 1.0f;
const f32 o = 0.0f;
static const u16 indices[4] = {0,1,2,3};
video::S3DVertex vertices[4];
// Draw sun
if (wicked_time_of_day > 0.15 && wicked_time_of_day < 0.85) {
driver->setMaterial(m_materials[2]);
float d = sunsize * 1.7;
video::SColor c(255,255,255,255);
vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
for (u32 i=0; i<4; i++) {
// Switch from -Z (south) to +X (east)
vertices[i].Pos.rotateXZBy(90);
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
// Draw moon
if (wicked_time_of_day < 0.3 || wicked_time_of_day > 0.7) {
int mp = m_moon_phase*10;
if (mp != 0) {
driver->setMaterial(m_materials[3]);
float d = moonsize * 1.9;
video::SColor c(255,255,255,255);
if (mp == 5) {
vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
}else if (mp < 5) {
float dp = -d+(d*(m_moon_phase*4));
vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
vertices[1] = video::S3DVertex(dp,-d,-1, 0,0,1, c, 1.0-(m_moon_phase*2), t);
vertices[2] = video::S3DVertex(dp, d,-1, 0,0,1, c, 1.0-(m_moon_phase*2), o);
vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
}else{
float dp = d-(d*((1.0-m_moon_phase)*4));
vertices[0] = video::S3DVertex(dp,-d,-1, 0,0,1, c, (1.0-m_moon_phase)*2, t);
vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
vertices[3] = video::S3DVertex(dp, d,-1, 0,0,1, c, (1.0-m_moon_phase)*2, o);
}
for (u32 i=0; i<4; i++) {
// Switch from -Z (south) to -X (west)
vertices[i].Pos.rotateXZBy(-90);
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
}else{
m_moon_phase = m_moon_phase_pending;
}
// Stars
float starbrightness = MYMAX(
0,
MYMIN(
1,
(0.285 - fabs(
wicked_time_of_day < 0.5 ? wicked_time_of_day : (1.0 - wicked_time_of_day)
)) * 10
)
);
float f = starbrightness*120;
if (f >= m_skycolor.getBlue()) {
driver->setMaterial(m_materials[1]);
video::SColor starcolor(255, f,f,f);
u16 indices[SKY_STAR_COUNT*4];
video::S3DVertex vertices[SKY_STAR_COUNT*4];
for (u32 i=0; i<SKY_STAR_COUNT; i++) {
indices[i] = i;
v3f p = m_stars[i];
core::CMatrix4<f32> a;
p.rotateXYBy(wicked_time_of_day * 360 - 90);
vertices[i].Pos = p;
vertices[i].Color = starcolor;
}
driver->drawVertexPrimitiveList(
vertices,
SKY_STAR_COUNT,
indices,
SKY_STAR_COUNT,
video::EVT_STANDARD,
scene::EPT_POINTS,
video::EIT_16BIT
);
}
}
void Sky::update(
float time_of_day,
float moon_phase,
float time_brightness,
float direct_brightness,
bool sunlight_seen
)
{
// Stabilize initial brightness and color values by flooding updates
if (m_first_update) {
m_first_update = false;
m_moon_phase = moon_phase;
for (u32 i=0; i<100; i++) {
update(time_of_day, moon_phase, time_brightness, direct_brightness, sunlight_seen);
}
return;
}
m_time_of_day = time_of_day;
m_moon_phase_pending = moon_phase;
m_time_brightness = time_brightness;
m_sunlight_seen = sunlight_seen;
bool is_dawn = (time_brightness >= 0.20 && time_brightness < 0.50);
video::SColorf bgcolor_bright_normal_f(170./255,200./255,230./255, 1.0);
video::SColorf bgcolor_bright_indoor_f(100./255,100./255,100./255, 1.0);
video::SColorf bgcolor_bright_dawn_f(0.666*1.2,0.549*1.0,0.220*1.2,1.0);
video::SColorf skycolor_bright_normal_f = video::SColor(255, 121, 141, 232);
video::SColorf skycolor_bright_dawn_f = video::SColor(255, 46, 60, 132);
video::SColorf cloudcolor_bright_normal_f = video::SColor(255, 240,240,255);
video::SColorf cloudcolor_bright_dawn_f(1.0, 0.7, 0.5, 1.0);
if (sunlight_seen) {
if (fabs(time_brightness - m_brightness) < 0.2) {
m_brightness = m_brightness * 0.95 + time_brightness * 0.05;
}else{
m_brightness = m_brightness * 0.80 + time_brightness * 0.20;
}
}else if (direct_brightness < m_brightness) {
m_brightness = m_brightness * 0.95 + direct_brightness * 0.05;
}else{
m_brightness = m_brightness * 0.98 + direct_brightness * 0.02;
}
m_clouds_visible = true;
float color_change_fraction = 0.98;
if (sunlight_seen) {
if (is_dawn) {
m_bgcolor_bright_f = m_bgcolor_bright_f.getInterpolated(bgcolor_bright_dawn_f, color_change_fraction);
m_skycolor_bright_f = m_skycolor_bright_f.getInterpolated(skycolor_bright_dawn_f, color_change_fraction);
m_cloudcolor_bright_f = m_cloudcolor_bright_f.getInterpolated(cloudcolor_bright_dawn_f, color_change_fraction);
}else{
m_bgcolor_bright_f = m_bgcolor_bright_f.getInterpolated(bgcolor_bright_normal_f, color_change_fraction);
m_skycolor_bright_f = m_skycolor_bright_f.getInterpolated(skycolor_bright_normal_f, color_change_fraction);
m_cloudcolor_bright_f = m_cloudcolor_bright_f.getInterpolated(cloudcolor_bright_normal_f, color_change_fraction);
}
}else{
m_bgcolor_bright_f = m_bgcolor_bright_f.getInterpolated(bgcolor_bright_indoor_f, color_change_fraction);
m_cloudcolor_bright_f = m_cloudcolor_bright_f.getInterpolated(cloudcolor_bright_normal_f, color_change_fraction);
m_skycolor_bright_f = m_skycolor_bright_f.getInterpolated(bgcolor_bright_indoor_f, color_change_fraction);
m_clouds_visible = false;
}
video::SColor bgcolor_bright = m_bgcolor_bright_f.toSColor();
m_bgcolor = video::SColor(
255,
bgcolor_bright.getRed() * m_brightness,
bgcolor_bright.getGreen() * m_brightness,
bgcolor_bright.getBlue() * m_brightness
);
video::SColor skycolor_bright = m_skycolor_bright_f.toSColor();
m_skycolor = video::SColor(
255,
skycolor_bright.getRed() * m_brightness,
skycolor_bright.getGreen() * m_brightness,
skycolor_bright.getBlue() * m_brightness
);
float cloud_direct_brightness = 0;
if (sunlight_seen) {
cloud_direct_brightness = time_brightness;
if (time_brightness >= 0.2 && time_brightness < 0.7)
cloud_direct_brightness *= 1.3;
}else{
cloud_direct_brightness = direct_brightness;
}
m_cloud_brightness = m_cloud_brightness * 0.95 + cloud_direct_brightness * (1.0 - 0.95);
m_cloudcolor_f = video::SColorf(
m_cloudcolor_bright_f.getRed() * m_cloud_brightness,
m_cloudcolor_bright_f.getGreen() * m_cloud_brightness,
m_cloudcolor_bright_f.getBlue() * m_cloud_brightness,
1.0
);
}

91
src/sky.h Normal file
View File

@ -0,0 +1,91 @@
/************************************************************************
* Minetest-c55
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
*
* sky.h
* voxelands - 3d voxel world sandbox game
* Copyright (C) Lisa 'darkrose' Milne 2013-2015 <lisa@ltmnet.com>
*
* 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 3 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, see <http://www.gnu.org/licenses/>
*
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
* for Voxelands.
************************************************************************/
#include "common_irrlicht.h"
#include <ISceneNode.h>
#ifndef SKY_HEADER
#define SKY_HEADER
#define SKY_MATERIAL_COUNT 4
#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<f32>& 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 time_of_day, float moon_phase, 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<f32> 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;
float m_moon_phase;
float m_moon_phase_pending;
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