Skip to content

Commit

Permalink
set_sky improvements, set_sun, set_moon and set_stars
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordach authored and sfan5 committed Mar 5, 2020
1 parent 580e7e8 commit 946c03c
Show file tree
Hide file tree
Showing 19 changed files with 1,519 additions and 394 deletions.
85 changes: 76 additions & 9 deletions doc/lua_api.txt
Expand Up @@ -5964,15 +5964,82 @@ object you are working with still exists.
* `hud_set_hotbar_selected_image(texturename)`
* sets image for selected item of hotbar
* `hud_get_hotbar_selected_image`: returns texturename
* `set_sky(bgcolor, type, {texture names}, clouds)`
* `bgcolor`: ColorSpec, defaults to white
* `type`: Available types:
* `"regular"`: Uses 0 textures, `bgcolor` ignored
* `"skybox"`: Uses 6 textures, `bgcolor` used
* `"plain"`: Uses 0 textures, `bgcolor` used
* `clouds`: Boolean for whether clouds appear in front of `"skybox"` or
`"plain"` custom skyboxes (default: `true`)
* `get_sky()`: returns bgcolor, type, table of textures, clouds
* `set_sky(parameters)`
* `parameters` is a table with the following optional fields:
* `base_color`: ColorSpec, changes fog in "skybox" and "plain".
* `type`: Available types:
* `"regular"`: Uses 0 textures, `base_color` ignored
* `"skybox"`: Uses 6 textures, `base_color` used as fog.
* `"plain"`: Uses 0 textures, `base_color` used as both fog and sky.
* `textures`: A table containing up to six textures in the following
order: Y+ (top), Y- (bottom), X- (west), X+ (east), Z+ (north), Z- (south).
* `clouds`: Boolean for whether clouds appear. (default: `true`)
* `sky_color`: A table containing the following values, alpha is ignored:
* `day_sky`: ColorSpec, for the top half of the `"regular"`
skybox during the day. (default: `#8cbafa`)
* `day_horizon`: ColorSpec, for the bottom half of the
`"regular"` skybox during the day. (default: `#9bc1f0`)
* `dawn_sky`: ColorSpec, for the top half of the `"regular"`
skybox during dawn/sunset. (default: `#b4bafa`)
* `dawn_horizon`: ColorSpec, for the bottom half of the `"regular"`
skybox during dawn/sunset. (default: `#bac1f0`)
* `night_sky`: ColorSpec, for the top half of the `"regular"`
skybox during the night. (default: `#006aff`)
* `night_horizon`: ColorSpec, for the bottom half of the `"regular"`
skybox during the night. (default: `#4090ff`)
* `indoors`: ColorSpec, for when you're either indoors or
underground. Only applies to the `"regular"` skybox.
(default: `#646464`)
* `fog_sun_tint`: ColorSpec, changes the fog tinting for the sun
at sunrise and sunset.
* `fog_moon_tint`: ColorSpec, changes the fog tinting for the moon
at sunrise and sunset.
* `fog_tint_type`: string, changes which mode the directional fog
abides by, `"custom"` uses `sun_tint` and `moon_tint`, while
`"default"` uses the classic Minetest sun and moon tinting.
Will use tonemaps, if set to `"default"`. (default: `"default"`)
* `get_sky()`: returns base_color, type, table of textures, clouds.
* `get_sky_color()`: returns a table with the `sky_color` parameters as in
`set_sky`.
* `set_sun(parameters)`:
* `parameters` is a table with the following optional fields:
* `visible`: Boolean for whether the sun is visible.
(default: `true`)
* `texture`: A regular texture for the sun. Setting to `""`
will re-enable the mesh sun. (default: `"sun.png"`)
* `tonemap`: A 512x1 texture containing the tonemap for the sun
(default: `"sun_tonemap.png"`)
* `sunrise`: A regular texture for the sunrise texture.
(default: `"sunrisebg.png"`)
* `sunrise_visible`: Boolean for whether the sunrise texture is visible.
(default: `true`)
* `scale`: Float controlling the overall size of the sun. (default: `1`)
* `get_sun()`: returns a table with the current sun parameters as in
`set_sun`.
* `set_moon(parameters)`:
* `parameters` is a table with the following optional fields:
* `visible`: Boolean for whether the moon is visible.
(default: `true`)
* `texture`: A regular texture for the moon. Setting to `""`
will re-enable the mesh moon. (default: `"moon.png"`)
* `tonemap`: A 512x1 texture containing the tonemap for the moon
(default: `"moon_tonemap.png"`)
* `scale`: Float controlling the overall size of the moon (default: `1`)
* `get_moon()`: returns a table with the current moon parameters as in
`set_moon`.
* `set_stars(parameters)`:
* `parameters` is a table with the following optional fields:
* `visible`: Boolean for whether the stars are visible.
(default: `true`)
* `count`: Integer number to set the number of stars in
the skybox. Only applies to `"skybox"` and `"regular"` skyboxes.
(default: `1000`)
* `star_color`: ColorSpec, sets the colors of the stars,
alpha channel is used to set overall star brightness.
(default: `#ebebff69`)
* `size`: Float controlling the overall size of the stars (default: `1`)
* `get_stars()`: returns a table with the current stars parameters as in
`set_stars`.
* `set_clouds(parameters)`: set cloud parameters
* `parameters` is a table with the following optional fields:
* `density`: from `0` (no clouds) to `1` (full clouds) (default `0.4`)
Expand Down
3 changes: 3 additions & 0 deletions src/client/client.h
Expand Up @@ -218,6 +218,9 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
void handleCommand_HudSetFlags(NetworkPacket* pkt);
void handleCommand_HudSetParam(NetworkPacket* pkt);
void handleCommand_HudSetSky(NetworkPacket* pkt);
void handleCommand_HudSetSun(NetworkPacket* pkt);
void handleCommand_HudSetMoon(NetworkPacket* pkt);
void handleCommand_HudSetStars(NetworkPacket* pkt);
void handleCommand_CloudParams(NetworkPacket* pkt);
void handleCommand_OverrideDayNightRatio(NetworkPacket* pkt);
void handleCommand_LocalPlayerAnimations(NetworkPacket* pkt);
Expand Down
15 changes: 8 additions & 7 deletions src/client/clientevent.h
Expand Up @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <string>
#include "irrlichttypes_bloated.h"
#include "hud.h"
#include "skyparams.h"

enum ClientEventType : u8
{
Expand All @@ -38,6 +39,9 @@ enum ClientEventType : u8
CE_HUDRM,
CE_HUDCHANGE,
CE_SET_SKY,
CE_SET_SUN,
CE_SET_MOON,
CE_SET_STARS,
CE_OVERRIDE_DAY_NIGHT_RATIO,
CE_CLOUD_PARAMS,
CLIENTEVENT_MAX,
Expand Down Expand Up @@ -147,13 +151,7 @@ struct ClientEvent
v3f *v3fdata;
v2s32 *v2s32data;
} hudchange;
struct
{
video::SColor *bgcolor;
std::string *type;
std::vector<std::string> *params;
bool clouds;
} set_sky;
SkyboxParams *set_sky;
struct
{
bool do_override;
Expand All @@ -169,5 +167,8 @@ struct ClientEvent
f32 speed_x;
f32 speed_y;
} cloud_params;
SunParams *sun_params;
MoonParams *moon_params;
StarParams *star_params;
};
};
102 changes: 76 additions & 26 deletions src/client/game.cpp
Expand Up @@ -811,6 +811,9 @@ class Game {
void handleClientEvent_HudRemove(ClientEvent *event, CameraOrientation *cam);
void handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *cam);
void handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam);
void handleClientEvent_SetSun(ClientEvent *event, CameraOrientation *cam);
void handleClientEvent_SetMoon(ClientEvent *event, CameraOrientation *cam);
void handleClientEvent_SetStars(ClientEvent *event, CameraOrientation *cam);
void handleClientEvent_OverrideDayNigthRatio(ClientEvent *event,
CameraOrientation *cam);
void handleClientEvent_CloudParams(ClientEvent *event, CameraOrientation *cam);
Expand Down Expand Up @@ -2523,6 +2526,9 @@ const ClientEventHandler Game::clientEventHandler[CLIENTEVENT_MAX] = {
{&Game::handleClientEvent_HudRemove},
{&Game::handleClientEvent_HudChange},
{&Game::handleClientEvent_SetSky},
{&Game::handleClientEvent_SetSun},
{&Game::handleClientEvent_SetMoon},
{&Game::handleClientEvent_SetStars},
{&Game::handleClientEvent_OverrideDayNigthRatio},
{&Game::handleClientEvent_CloudParams},
};
Expand Down Expand Up @@ -2744,41 +2750,85 @@ void Game::handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *ca
void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam)
{
sky->setVisible(false);
// Whether clouds are visible in front of a custom skybox
sky->setCloudsEnabled(event->set_sky.clouds);
// Whether clouds are visible in front of a custom skybox.
sky->setCloudsEnabled(event->set_sky->clouds);

if (skybox) {
skybox->remove();
skybox = NULL;
}

// Clear the old textures out in case we switch rendering type.
sky->clearSkyboxTextures();
// Handle according to type
if (*event->set_sky.type == "regular") {
if (event->set_sky->type == "regular") {
// Shows the mesh skybox
sky->setVisible(true);
sky->setCloudsEnabled(true);
} else if (*event->set_sky.type == "skybox" &&
event->set_sky.params->size() == 6) {
sky->setFallbackBgColor(*event->set_sky.bgcolor);
skybox = RenderingEngine::get_scene_manager()->addSkyBoxSceneNode(
texture_src->getTextureForMesh((*event->set_sky.params)[0]),
texture_src->getTextureForMesh((*event->set_sky.params)[1]),
texture_src->getTextureForMesh((*event->set_sky.params)[2]),
texture_src->getTextureForMesh((*event->set_sky.params)[3]),
texture_src->getTextureForMesh((*event->set_sky.params)[4]),
texture_src->getTextureForMesh((*event->set_sky.params)[5]));
}
// Handle everything else as plain color
else {
if (*event->set_sky.type != "plain")
// Update mesh based skybox colours if applicable.
sky->setSkyColors(*event->set_sky);
sky->setHorizonTint(
event->set_sky->sun_tint,
event->set_sky->moon_tint,
event->set_sky->tint_type
);
} else if (event->set_sky->type == "skybox" &&
event->set_sky->textures.size() == 6) {
// Disable the dyanmic mesh skybox:
sky->setVisible(false);
// Set fog colors:
sky->setFallbackBgColor(event->set_sky->bgcolor);
// Set sunrise and sunset fog tinting:
sky->setHorizonTint(
event->set_sky->sun_tint,
event->set_sky->moon_tint,
event->set_sky->tint_type
);
// Add textures to skybox.
for (int i = 0; i < 6; i++)
sky->addTextureToSkybox(event->set_sky->textures[i], i, texture_src);
} else {
// Handle everything else as plain color.
if (event->set_sky->type != "plain")
infostream << "Unknown sky type: "
<< (*event->set_sky.type) << std::endl;

sky->setFallbackBgColor(*event->set_sky.bgcolor);
<< (event->set_sky->type) << std::endl;
sky->setVisible(false);
sky->setFallbackBgColor(event->set_sky->bgcolor);
// Disable directional sun/moon tinting on plain or invalid skyboxes.
sky->setHorizonTint(
event->set_sky->bgcolor,
event->set_sky->bgcolor,
"custom"
);
}
delete event->set_sky;
}

delete event->set_sky.bgcolor;
delete event->set_sky.type;
delete event->set_sky.params;
void Game::handleClientEvent_SetSun(ClientEvent *event, CameraOrientation *cam)
{
sky->setSunVisible(event->sun_params->visible);
sky->setSunTexture(event->sun_params->texture,
event->sun_params->tonemap, texture_src);
sky->setSunScale(event->sun_params->scale);
sky->setSunriseVisible(event->sun_params->sunrise_visible);
sky->setSunriseTexture(event->sun_params->sunrise, texture_src);
delete event->sun_params;
}

void Game::handleClientEvent_SetMoon(ClientEvent *event, CameraOrientation *cam)
{
sky->setMoonVisible(event->moon_params->visible);
sky->setMoonTexture(event->moon_params->texture,
event->moon_params->tonemap, texture_src);
sky->setMoonScale(event->moon_params->scale);
delete event->moon_params;
}

void Game::handleClientEvent_SetStars(ClientEvent *event, CameraOrientation *cam)
{
sky->setStarsVisible(event->star_params->visible);
sky->setStarCount(event->star_params->count, false);
sky->setStarColor(event->star_params->starcolor);
sky->setStarScale(event->star_params->scale);
delete event->star_params;
}

void Game::handleClientEvent_OverrideDayNigthRatio(ClientEvent *event,
Expand Down Expand Up @@ -3706,7 +3756,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
video::SColor clouds_dark = clouds->getColor()
.getInterpolated(video::SColor(255, 0, 0, 0), 0.9);
sky->overrideColors(clouds_dark, clouds->getColor());
sky->setBodiesVisible(false);
sky->setInClouds(true);
runData.fog_range = std::fmin(runData.fog_range * 0.5f, 32.0f * BS);
// do not draw clouds after all
clouds->setVisible(false);
Expand Down

0 comments on commit 946c03c

Please sign in to comment.