1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Universal skybox type checks, simplify sky type application, formatting fixes

This commit is contained in:
MirceaKitsune 2025-06-01 00:28:48 +03:00
parent 79f46800f3
commit cc363a77d7
8 changed files with 55 additions and 68 deletions

View file

@ -8811,7 +8811,9 @@ child will follow movement and rotation of that bone.
* `"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_back"`: Uses 6 textures, `sky_color` used as fog, stars / sun / moon in foreground.
Note: Requires Luanti client version 5.13 or greater.
* `"skybox_front"`: Uses 6 textures, `sky_color` used as fog, stars / sun / moon in background. * `"skybox_front"`: Uses 6 textures, `sky_color` used as fog, stars / sun / moon in background.
Note: Requires Luanti client version 5.13 or greater.
* `"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

View file

@ -2851,67 +2851,51 @@ 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); // Handle invalid sky type.
if (!event->set_sky->isSkybox() && !event->set_sky->isTransparent() && event->set_sky->type != "plain")
infostream << "Unknown sky type: " << (event->set_sky->type) << std::endl;
// Show the mesh sky if transparent.
sky->setVisible(event->set_sky->isTransparent());
sky->setType(event->set_sky->type); 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);
// Clear the old textures out in case we switch rendering type. // Show the mesh sky and use skybox colours if transparent.
sky->clearSkyboxTextures(); if (event->set_sky->isTransparent())
// Handle according to type
if (event->set_sky->type == "regular") {
// Shows the mesh skybox
sky->setVisible(true);
// Update mesh based skybox colours if applicable.
sky->setSkyColors(event->set_sky->sky_color); sky->setSkyColors(event->set_sky->sky_color);
sky->setHorizonTint( else
event->set_sky->fog_sun_tint,
event->set_sky->fog_moon_tint,
event->set_sky->fog_tint_type
);
} else if ((event->set_sky->type == "skybox" || event->set_sky->type == "skybox_back" ||
event->set_sky->type == "skybox_front") && event->set_sky->textures.size() == 6) {
const bool transparent = event->set_sky->type == "skybox_back" || event->set_sky->type == "skybox_front";
// Show the mesh and sky colors only if transparency is used.
if(transparent) {
sky->setVisible(true);
sky->setSkyColors(event->set_sky->sky_color);
} else {
sky->setVisible(false);
sky->setFallbackBgColor(event->set_sky->bgcolor);
}
// Set sunrise and sunset fog tinting:
sky->setHorizonTint(
event->set_sky->fog_sun_tint,
event->set_sky->fog_moon_tint,
event->set_sky->fog_tint_type
);
// Add textures to skybox.
for (int i = 0; i < 6; i++)
sky->addTextureToSkybox(event->set_sky->textures[i], i, texture_src, transparent);
} else {
// Handle everything else as plain color.
if (event->set_sky->type != "plain")
infostream << "Unknown sky type: "
<< (event->set_sky->type) << std::endl;
sky->setVisible(false);
sky->setFallbackBgColor(event->set_sky->bgcolor); sky->setFallbackBgColor(event->set_sky->bgcolor);
// Disable directional sun/moon tinting on plain or invalid skyboxes.
// Use horizon tint for regular or skybox skies.
if (event->set_sky->isSkybox() || event->set_sky->isTransparent())
sky->setHorizonTint(
event->set_sky->fog_sun_tint,
event->set_sky->fog_moon_tint,
event->set_sky->fog_tint_type
);
else
sky->setHorizonTint( sky->setHorizonTint(
event->set_sky->bgcolor, event->set_sky->bgcolor,
event->set_sky->bgcolor, event->set_sky->bgcolor,
"custom" "custom"
); );
// Clear the old textures out in case we switch rendering type.
sky->clearSkyboxTextures();
// Add textures to skybox.
if(event->set_sky->isSkybox()) {
for (int i = 0; i < 6; i++)
sky->addTextureToSkybox(event->set_sky->textures[i], i, texture_src, event->set_sky->isTransparent());
} }
// Orbit Tilt: // Orbit Tilt:
sky->setBodyOrbitTilt(event->set_sky->body_orbit_tilt); sky->setBodyOrbitTilt(event->set_sky->body_orbit_tilt);
// fog // Fog, do not override a potentially smaller client setting.
// do not override a potentially smaller client setting.
sky->setFogDistance(event->set_sky->fog_distance); sky->setFogDistance(event->set_sky->fog_distance);
// if the fog distance is reset, switch back to the client's viewing_range // If the fog distance is reset, switch back to the client's viewing_range
if (event->set_sky->fog_distance < 0) if (event->set_sky->fog_distance < 0)
draw_control->wanted_range = g_settings->getS16("viewing_range"); draw_control->wanted_range = g_settings->getS16("viewing_range");

View file

@ -197,7 +197,6 @@ void Sky::render()
const f32 t = 1.0f; const f32 t = 1.0f;
const f32 o = 0.0f; const f32 o = 0.0f;
const bool has_tex = m_sky_params.textures.size() == 6;
static const u16 indices[6] = {0, 1, 2, 0, 2, 3}; static const u16 indices[6] = {0, 1, 2, 0, 2, 3};
video::S3DVertex vertices[4]; video::S3DVertex vertices[4];
@ -211,12 +210,12 @@ 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_type == "skybox" || m_type == "skybox_back")) if (m_sky_params.type == "skybox" || m_sky_params.type == "skybox_back")
renderTextures(driver); renderTextures(driver);
// Draw far cloudy fog thing blended with skycolor // Draw far cloudy fog thing blended with skycolor
// Disabled when using a textured skybox to prevent clipping // Disabled when using a textured skybox to prevent clipping
if (m_visible && !has_tex) { if (m_visible && !m_sky_params.isSkybox()) {
driver->setMaterial(m_materials[1]); driver->setMaterial(m_materials[1]);
for (u32 j = 0; j < 4; j++) { for (u32 j = 0; j < 4; j++) {
vertices[0] = video::S3DVertex(-1, -0.02, -1, 0, 0, 1, m_bgcolor, t, t); vertices[0] = video::S3DVertex(-1, -0.02, -1, 0, 0, 1, m_bgcolor, t, t);
@ -281,7 +280,7 @@ void Sky::render()
// Draw far cloudy fog thing below all horizons in front of sun, moon and stars. // Draw far cloudy fog thing below all horizons in front of sun, moon and stars.
// Disabled when using a textured skybox to prevent clipping // Disabled when using a textured skybox to prevent clipping
if (m_visible && !has_tex) { if (m_visible && !m_sky_params.isSkybox()) {
driver->setMaterial(m_materials[1]); driver->setMaterial(m_materials[1]);
for (u32 j = 0; j < 4; j++) { for (u32 j = 0; j < 4; j++) {
@ -317,7 +316,7 @@ void Sky::render()
} }
// Draw the six sided skybox, transparent foreground. // Draw the six sided skybox, transparent foreground.
if(has_tex && m_type == "skybox_front") if (m_sky_params.type == "skybox_front")
renderTextures(driver); renderTextures(driver);
} }
} }

View file

@ -33,7 +33,6 @@ public:
virtual void OnRegisterSceneNode(); virtual void OnRegisterSceneNode();
//! renders the node. //! renders the node.
virtual void renderTextures(video::IVideoDriver *driver);
virtual void render(); virtual void render();
virtual const aabb3f &getBoundingBox() const { return m_box; } virtual const aabb3f &getBoundingBox() const { return m_box; }
@ -83,7 +82,7 @@ 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; } void setType(std::string type) { m_sky_params.type = type; }
// Set only from set_sky API // Set only from set_sky API
void setCloudsEnabled(bool clouds_enabled) { m_clouds_enabled = clouds_enabled; } void setCloudsEnabled(bool clouds_enabled) { m_clouds_enabled = clouds_enabled; }
@ -126,6 +125,8 @@ public:
private: private:
aabb3f m_box{{0.0f, 0.0f, 0.0f}}; aabb3f m_box{{0.0f, 0.0f, 0.0f}};
video::SMaterial m_materials[SKY_MATERIAL_COUNT]; video::SMaterial m_materials[SKY_MATERIAL_COUNT];
virtual void renderTextures(video::IVideoDriver *driver);
// How much sun & moon transition should affect horizon color // How much sun & moon transition should affect horizon color
float m_horizon_blend() float m_horizon_blend()
{ {
@ -164,7 +165,6 @@ 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

View file

@ -1303,8 +1303,7 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt)
StarParams stars = SkyboxDefaults::getStarDefaults(); StarParams stars = SkyboxDefaults::getStarDefaults();
// Fix for "regular", "skybox_back", "skybox_front" skies as color isn't kept: // Fix for "regular", "skybox_back", "skybox_front" skies as color isn't kept:
if (skybox.type == "regular" || if (skybox.isTransparent()) {
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);
@ -1344,8 +1343,7 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt)
*pkt >> skybox.bgcolor >> skybox.type >> 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.isSkybox()) {
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;
@ -1354,8 +1352,7 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt)
skybox.textures.emplace_back(texture); skybox.textures.emplace_back(texture);
} }
} }
if (skybox.type == "regular" || if (skybox.isTransparent()) {
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;

View file

@ -2065,8 +2065,7 @@ int ObjectRef::l_set_sky(lua_State *L)
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.isSkybox()) {
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
@ -2160,8 +2159,7 @@ int ObjectRef::l_set_sky(lua_State *L)
// Preserve old behavior of the sun, moon and stars // Preserve old behavior of the sun, moon and stars
// when using the old set_sky call. // when using the old set_sky call.
if (sky_params.type == "regular" || if (sky_params.isTransparent()) {
sky_params.type == "skybox_back" || sky_params.type == "skybox_front") {
sun_params.visible = true; sun_params.visible = true;
sun_params.sunrise_visible = true; sun_params.sunrise_visible = true;
moon_params.visible = true; moon_params.visible = true;
@ -2183,7 +2181,7 @@ int ObjectRef::l_set_sky(lua_State *L)
lua_pop(L, 1); lua_pop(L, 1);
} }
} }
if (sky_params.type == "skybox" && sky_params.textures.size() != 6) if (sky_params.isSkybox() && sky_params.textures.size() != 6)
throw LuaError("Skybox expects 6 textures."); throw LuaError("Skybox expects 6 textures.");
sky_params.clouds = true; sky_params.clouds = true;
@ -2202,8 +2200,7 @@ int ObjectRef::l_set_sky(lua_State *L)
static void push_sky_color(lua_State *L, const SkyboxParams &params) static void push_sky_color(lua_State *L, const SkyboxParams &params)
{ {
lua_newtable(L); lua_newtable(L);
if (params.type == "regular" || if (params.isTransparent()) {
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);

View file

@ -1865,14 +1865,12 @@ void Server::SendSetSky(session_t peer_id, const SkyboxParams &params)
<< 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.isSkybox()) {
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" || if (params.isTransparent()) {
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;

View file

@ -38,6 +38,16 @@ struct SkyboxParams
s16 fog_distance { -1 }; s16 fog_distance { -1 };
float fog_start { -1.0f }; float fog_start { -1.0f };
video::SColor fog_color { 0 }; // override, only used if alpha > 0 video::SColor fog_color { 0 }; // override, only used if alpha > 0
// Check if this is a textured skybox and whether transparency is used
bool isSkybox() const
{
return type == "skybox" || type == "skybox_back" || type == "skybox_front";
}
bool isTransparent() const
{
return type == "regular" || type == "skybox_back" || type == "skybox_front";
}
}; };
struct SunParams struct SunParams