mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Convert transparency flag to skybox types
This commit is contained in:
parent
ab3073e425
commit
de5328c851
8 changed files with 28 additions and 34 deletions
|
@ -8781,6 +8781,8 @@ child will follow movement and rotation of that bone.
|
||||||
* `type`: Available types:
|
* `type`: Available types:
|
||||||
* `"regular"`: Uses 0 textures, `base_color` ignored
|
* `"regular"`: Uses 0 textures, `base_color` ignored
|
||||||
* `"skybox"`: Uses 6 textures, `base_color` used as fog.
|
* `"skybox"`: Uses 6 textures, `base_color` used as fog.
|
||||||
|
* `"skybox_back"`: Uses 6 textures, `sky_color` used as fog, stars / sun / moon in foreground.
|
||||||
|
* `"skybox_front"`: Uses 6 textures, `sky_color` used as fog, stars / sun / moon in background.
|
||||||
* `"plain"`: Uses 0 textures, `base_color` used as both fog and sky.
|
* `"plain"`: Uses 0 textures, `base_color` used as both fog and sky.
|
||||||
(default: `"regular"`)
|
(default: `"regular"`)
|
||||||
* `textures`: A table containing up to six textures in the following
|
* `textures`: A table containing up to six textures in the following
|
||||||
|
@ -8789,13 +8791,9 @@ child will follow movement and rotation of that bone.
|
||||||
bottom texture and the bottom edge of the top texture touch the east face).
|
bottom texture and the bottom edge of the top texture touch the east face).
|
||||||
Some top and bottom textures expect to be aligned with the north face and will need to be rotated
|
Some top and bottom textures expect to be aligned with the north face and will need to be rotated
|
||||||
by -90 and 90 degrees, respectively, to fit the eastward orientation.
|
by -90 and 90 degrees, respectively, to fit the eastward orientation.
|
||||||
* `transparency`: Used by the `"skybox"` type. The type of transparency to use. (default: `"solid"`)
|
|
||||||
* `"solid"`: For textures without an alpha channel, `sky_color` is not used.
|
|
||||||
* `"transparent_back"`: Show stars / sun / moon over the alpha channel, `sky_color` is used.
|
|
||||||
* `"transparent_front"`: Show stars / sun / moon behind the alpha channel, `sky_color` is used.
|
|
||||||
* `clouds`: Boolean for whether clouds appear. (default: `true`)
|
* `clouds`: Boolean for whether clouds appear. (default: `true`)
|
||||||
* `sky_color`: A table used in `"regular"` and `"skybox"` types only. If used with the later,
|
* `sky_color`: A table used in `"regular"`, `"skybox_back"`, `"skybox_front"` types only. For a skybox
|
||||||
the `textures` should have an alpha channel. Contains the following values (alpha is ignored):
|
the `textures` should have an alpha channel. Contains the following values (alpha is ignored):
|
||||||
* `day_sky`: ColorSpec, for the top half of the sky during the day.
|
* `day_sky`: ColorSpec, for the top half of the sky during the day.
|
||||||
(default: `#61b5f5`)
|
(default: `#61b5f5`)
|
||||||
* `day_horizon`: ColorSpec, for the bottom half of the sky during the day.
|
* `day_horizon`: ColorSpec, for the bottom half of the sky during the day.
|
||||||
|
|
|
@ -2848,9 +2848,9 @@ void Game::handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *ca
|
||||||
void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam)
|
void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam)
|
||||||
{
|
{
|
||||||
sky->setVisible(false);
|
sky->setVisible(false);
|
||||||
|
sky->setType(event->set_sky->type);
|
||||||
// Whether clouds are visible in front of a custom skybox.
|
// Whether clouds are visible in front of a custom skybox.
|
||||||
sky->setCloudsEnabled(event->set_sky->clouds);
|
sky->setCloudsEnabled(event->set_sky->clouds);
|
||||||
sky->setTransparency(event->set_sky->transparency);
|
|
||||||
|
|
||||||
// Clear the old textures out in case we switch rendering type.
|
// Clear the old textures out in case we switch rendering type.
|
||||||
sky->clearSkyboxTextures();
|
sky->clearSkyboxTextures();
|
||||||
|
@ -2865,11 +2865,10 @@ void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam)
|
||||||
event->set_sky->fog_moon_tint,
|
event->set_sky->fog_moon_tint,
|
||||||
event->set_sky->fog_tint_type
|
event->set_sky->fog_tint_type
|
||||||
);
|
);
|
||||||
} else if (event->set_sky->type == "skybox" &&
|
} else if ((event->set_sky->type == "skybox" || event->set_sky->type == "skybox_back" ||
|
||||||
event->set_sky->textures.size() == 6) {
|
event->set_sky->type == "skybox_front") && event->set_sky->textures.size() == 6) {
|
||||||
const bool transparent = event->set_sky->transparency != "solid";
|
|
||||||
|
|
||||||
// Show the mesh and sky colors only if transparency is used.
|
// Show the mesh and sky colors only if transparency is used.
|
||||||
|
const bool transparent = event->set_sky->type == "skybox_back" || event->set_sky->type == "skybox_front";
|
||||||
if(transparent) {
|
if(transparent) {
|
||||||
sky->setVisible(true);
|
sky->setVisible(true);
|
||||||
sky->setSkyColors(event->set_sky->sky_color);
|
sky->setSkyColors(event->set_sky->sky_color);
|
||||||
|
|
|
@ -211,7 +211,7 @@ void Sky::render()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Draw the six sided skybox, solid or transparent background.
|
// Draw the six sided skybox, solid or transparent background.
|
||||||
if(has_tex && (m_transparency == "solid" || m_transparency == "transparent_back"))
|
if(has_tex && (m_type == "skybox" || m_type == "skybox_back"))
|
||||||
renderTextures(driver);
|
renderTextures(driver);
|
||||||
|
|
||||||
// Draw far cloudy fog thing blended with skycolor
|
// Draw far cloudy fog thing blended with skycolor
|
||||||
|
@ -317,7 +317,7 @@ void Sky::render()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the six sided skybox, transparent foreground.
|
// Draw the six sided skybox, transparent foreground.
|
||||||
if(has_tex && m_transparency == "transparent_front")
|
if(has_tex && m_type == "skybox_front")
|
||||||
renderTextures(driver);
|
renderTextures(driver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,9 +83,9 @@ public:
|
||||||
const video::SColorf &getCloudColor() const { return m_cloudcolor_f; }
|
const video::SColorf &getCloudColor() const { return m_cloudcolor_f; }
|
||||||
|
|
||||||
void setVisible(bool visible) { m_visible = visible; }
|
void setVisible(bool visible) { m_visible = visible; }
|
||||||
|
void setType(std::string type) { m_type = type; }
|
||||||
|
|
||||||
// Set only from set_sky API
|
// Set only from set_sky API
|
||||||
void setTransparency(std::string transparency) { m_transparency = transparency; }
|
|
||||||
void setCloudsEnabled(bool clouds_enabled) { m_clouds_enabled = clouds_enabled; }
|
void setCloudsEnabled(bool clouds_enabled) { m_clouds_enabled = clouds_enabled; }
|
||||||
void setFallbackBgColor(video::SColor fallback_bg_color)
|
void setFallbackBgColor(video::SColor fallback_bg_color)
|
||||||
{
|
{
|
||||||
|
@ -164,6 +164,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool m_visible = true;
|
bool m_visible = true;
|
||||||
|
std::string m_type = "regular";
|
||||||
// Used when m_visible=false
|
// Used when m_visible=false
|
||||||
video::SColor m_fallback_bg_color = video::SColor(255, 255, 255, 255);
|
video::SColor m_fallback_bg_color = video::SColor(255, 255, 255, 255);
|
||||||
bool m_first_update = true; // Set before the sky is updated for the first time
|
bool m_first_update = true; // Set before the sky is updated for the first time
|
||||||
|
@ -176,7 +177,6 @@ private:
|
||||||
bool m_clouds_enabled = true; // Initialised to true, reset only by set_sky API
|
bool m_clouds_enabled = true; // Initialised to true, reset only by set_sky API
|
||||||
bool m_directional_colored_fog;
|
bool m_directional_colored_fog;
|
||||||
bool m_in_clouds = true; // Prevent duplicating bools to remember old values
|
bool m_in_clouds = true; // Prevent duplicating bools to remember old values
|
||||||
std::string m_transparency = "solid"; // Type of transparency used
|
|
||||||
|
|
||||||
video::SColorf m_bgcolor_bright_f = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
|
video::SColorf m_bgcolor_bright_f = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
video::SColorf m_skycolor_bright_f = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
|
video::SColorf m_skycolor_bright_f = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
|
|
@ -1290,7 +1290,6 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt)
|
||||||
SkyboxParams skybox;
|
SkyboxParams skybox;
|
||||||
skybox.bgcolor = video::SColor(readARGB8(is));
|
skybox.bgcolor = video::SColor(readARGB8(is));
|
||||||
skybox.type = std::string(deSerializeString16(is));
|
skybox.type = std::string(deSerializeString16(is));
|
||||||
skybox.transparency = std::string("solid");
|
|
||||||
u16 count = readU16(is);
|
u16 count = readU16(is);
|
||||||
|
|
||||||
for (size_t i = 0; i < count; i++)
|
for (size_t i = 0; i < count; i++)
|
||||||
|
@ -1304,7 +1303,8 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt)
|
||||||
StarParams stars = SkyboxDefaults::getStarDefaults();
|
StarParams stars = SkyboxDefaults::getStarDefaults();
|
||||||
|
|
||||||
// Fix for "regular" and "skybox" skies, as color isn't kept:
|
// Fix for "regular" and "skybox" skies, as color isn't kept:
|
||||||
if (skybox.type == "regular" || skybox.type == "skybox") {
|
if (skybox.type == "regular" || skybox.type == "skybox" ||
|
||||||
|
skybox.type == "skybox_back" || skybox.type == "skybox_front") {
|
||||||
skybox.sky_color = SkyboxDefaults::getSkyColorDefaults();
|
skybox.sky_color = SkyboxDefaults::getSkyColorDefaults();
|
||||||
skybox.fog_tint_type = "default";
|
skybox.fog_tint_type = "default";
|
||||||
skybox.fog_moon_tint = video::SColor(255, 255, 255, 255);
|
skybox.fog_moon_tint = video::SColor(255, 255, 255, 255);
|
||||||
|
@ -1341,10 +1341,11 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt)
|
||||||
|
|
||||||
SkyboxParams skybox;
|
SkyboxParams skybox;
|
||||||
|
|
||||||
*pkt >> skybox.bgcolor >> skybox.type >> skybox.transparency >> skybox.clouds >>
|
*pkt >> skybox.bgcolor >> skybox.type >> skybox.clouds >>
|
||||||
skybox.fog_sun_tint >> skybox.fog_moon_tint >> skybox.fog_tint_type;
|
skybox.fog_sun_tint >> skybox.fog_moon_tint >> skybox.fog_tint_type;
|
||||||
|
|
||||||
if (skybox.type == "skybox") {
|
if (skybox.type == "skybox" ||
|
||||||
|
skybox.type == "skybox_back" || skybox.type == "skybox_front") {
|
||||||
u16 texture_count;
|
u16 texture_count;
|
||||||
std::string texture;
|
std::string texture;
|
||||||
*pkt >> texture_count;
|
*pkt >> texture_count;
|
||||||
|
@ -1353,7 +1354,8 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt)
|
||||||
skybox.textures.emplace_back(texture);
|
skybox.textures.emplace_back(texture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (skybox.type == "regular" || skybox.type == "skybox") {
|
if (skybox.type == "regular" || skybox.type == "skybox" ||
|
||||||
|
skybox.type == "skybox_back" || skybox.type == "skybox_front") {
|
||||||
auto &c = skybox.sky_color;
|
auto &c = skybox.sky_color;
|
||||||
*pkt >> c.day_sky >> c.day_horizon >> c.dawn_sky >> c.dawn_horizon
|
*pkt >> c.day_sky >> c.day_horizon >> c.dawn_sky >> c.dawn_horizon
|
||||||
>> c.night_sky >> c.night_horizon >> c.indoors;
|
>> c.night_sky >> c.night_horizon >> c.indoors;
|
||||||
|
|
|
@ -2044,14 +2044,10 @@ int ObjectRef::l_set_sky(lua_State *L)
|
||||||
sky_params.type = luaL_checkstring(L, -1);
|
sky_params.type = luaL_checkstring(L, -1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
lua_getfield(L, 2, "transparency");
|
|
||||||
if (!lua_isnil(L, -1))
|
|
||||||
sky_params.transparency = luaL_checkstring(L, -1);
|
|
||||||
lua_pop(L, 1);
|
|
||||||
|
|
||||||
lua_getfield(L, 2, "textures");
|
lua_getfield(L, 2, "textures");
|
||||||
sky_params.textures.clear();
|
sky_params.textures.clear();
|
||||||
if (lua_istable(L, -1) && sky_params.type == "skybox") {
|
if (lua_istable(L, -1) && (sky_params.type == "skybox" ||
|
||||||
|
sky_params.type == "skybox_back" || sky_params.type == "skybox_front")) {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
while (lua_next(L, -2) != 0) {
|
while (lua_next(L, -2) != 0) {
|
||||||
// Key is at index -2 and value at index -1
|
// Key is at index -2 and value at index -1
|
||||||
|
@ -2186,7 +2182,8 @@ int ObjectRef::l_set_sky(lua_State *L)
|
||||||
static void push_sky_color(lua_State *L, const SkyboxParams ¶ms)
|
static void push_sky_color(lua_State *L, const SkyboxParams ¶ms)
|
||||||
{
|
{
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
if (params.type == "regular" || params.type == "skybox") {
|
if (params.type == "regular" || params.type == "skybox" ||
|
||||||
|
params.type == "skybox_back" || params.type == "skybox_front") {
|
||||||
push_ARGB8(L, params.sky_color.day_sky);
|
push_ARGB8(L, params.sky_color.day_sky);
|
||||||
lua_setfield(L, -2, "day_sky");
|
lua_setfield(L, -2, "day_sky");
|
||||||
push_ARGB8(L, params.sky_color.day_horizon);
|
push_ARGB8(L, params.sky_color.day_horizon);
|
||||||
|
@ -2243,8 +2240,6 @@ int ObjectRef::l_get_sky(lua_State *L)
|
||||||
lua_setfield(L, -2, "base_color");
|
lua_setfield(L, -2, "base_color");
|
||||||
lua_pushlstring(L, skybox_params.type.c_str(), skybox_params.type.size());
|
lua_pushlstring(L, skybox_params.type.c_str(), skybox_params.type.size());
|
||||||
lua_setfield(L, -2, "type");
|
lua_setfield(L, -2, "type");
|
||||||
lua_pushlstring(L, skybox_params.transparency.c_str(), skybox_params.transparency.size());
|
|
||||||
lua_setfield(L, -2, "transparency");
|
|
||||||
|
|
||||||
if (skybox_params.body_orbit_tilt != SkyboxParams::INVALID_SKYBOX_TILT) {
|
if (skybox_params.body_orbit_tilt != SkyboxParams::INVALID_SKYBOX_TILT) {
|
||||||
lua_pushnumber(L, skybox_params.body_orbit_tilt);
|
lua_pushnumber(L, skybox_params.body_orbit_tilt);
|
||||||
|
|
|
@ -1859,16 +1859,18 @@ void Server::SendSetSky(session_t peer_id, const SkyboxParams ¶ms)
|
||||||
|
|
||||||
pkt << params.clouds;
|
pkt << params.clouds;
|
||||||
} else { // Handle current clients and future clients
|
} else { // Handle current clients and future clients
|
||||||
pkt << params.bgcolor << params.type << params.transparency
|
pkt << params.bgcolor << params.type
|
||||||
<< params.clouds << params.fog_sun_tint
|
<< params.clouds << params.fog_sun_tint
|
||||||
<< params.fog_moon_tint << params.fog_tint_type;
|
<< params.fog_moon_tint << params.fog_tint_type;
|
||||||
|
|
||||||
if (params.type == "skybox") {
|
if (params.type == "skybox" ||
|
||||||
|
params.type == "skybox_back" || params.type == "skybox_front") {
|
||||||
pkt << (u16) params.textures.size();
|
pkt << (u16) params.textures.size();
|
||||||
for (const std::string &texture : params.textures)
|
for (const std::string &texture : params.textures)
|
||||||
pkt << texture;
|
pkt << texture;
|
||||||
}
|
}
|
||||||
if (params.type == "regular" || params.type == "skybox") {
|
if (params.type == "regular" || params.type == "skybox" ||
|
||||||
|
params.type == "skybox_back" || params.type == "skybox_front") {
|
||||||
auto &c = params.sky_color;
|
auto &c = params.sky_color;
|
||||||
pkt << c.day_sky << c.day_horizon << c.dawn_sky << c.dawn_horizon
|
pkt << c.day_sky << c.day_horizon << c.dawn_sky << c.dawn_horizon
|
||||||
<< c.night_sky << c.night_horizon << c.indoors;
|
<< c.night_sky << c.night_horizon << c.indoors;
|
||||||
|
|
|
@ -28,7 +28,6 @@ struct SkyboxParams
|
||||||
|
|
||||||
video::SColor bgcolor;
|
video::SColor bgcolor;
|
||||||
std::string type;
|
std::string type;
|
||||||
std::string transparency;
|
|
||||||
std::vector<std::string> textures;
|
std::vector<std::string> textures;
|
||||||
bool clouds;
|
bool clouds;
|
||||||
SkyColor sky_color;
|
SkyColor sky_color;
|
||||||
|
@ -90,7 +89,6 @@ public:
|
||||||
SkyboxParams sky;
|
SkyboxParams sky;
|
||||||
sky.bgcolor = video::SColor(255, 255, 255, 255);
|
sky.bgcolor = video::SColor(255, 255, 255, 255);
|
||||||
sky.type = "regular";
|
sky.type = "regular";
|
||||||
sky.transparency = "solid";
|
|
||||||
sky.clouds = true;
|
sky.clouds = true;
|
||||||
sky.sky_color = getSkyColorDefaults();
|
sky.sky_color = getSkyColorDefaults();
|
||||||
sky.fog_sun_tint = video::SColor(255, 244, 125, 29);
|
sky.fog_sun_tint = video::SColor(255, 244, 125, 29);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue