Skip to content

Commit 10f22dd

Browse files
authored
Let modders disable skybox dimming in caves (#16976)
1 parent d742cd1 commit 10f22dd

File tree

7 files changed

+34
-3
lines changed

7 files changed

+34
-3
lines changed

doc/lua_api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8995,6 +8995,11 @@ child will follow movement and rotation of that bone.
89958995
* `fog_color`: ColorSpec, override the color of the fog.
89968996
Unlike `base_color` above this will apply regardless of the skybox type.
89978997
(default: `"#00000000"`, which means no override)
8998+
* `auto_dim_skybox`: boolean, whether to dim skybox brightness if
8999+
the sky is assumed not to be visible (e.g. in caves),
9000+
based on a hardcoded and sometimes buggy heuristic.
9001+
Requires a Luanti 5.16.0+ client and server.
9002+
(default: `true`)
89989003
* `set_sky(base_color, type, {texture names}, clouds)`
89999004
* Deprecated. Use `set_sky(sky_parameters)`
90009005
* `base_color`: ColorSpec, defaults to white

src/client/game.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2429,6 +2429,8 @@ void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam)
24292429

24302430
sky->setFogColor(event->set_sky->fog_color);
24312431

2432+
sky->setAutoCaveBrightness(event->set_sky->auto_dim_skybox);
2433+
24322434
delete event->set_sky;
24332435
}
24342436

@@ -3406,8 +3408,10 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
34063408

34073409
// When in noclip mode force same sky brightness as above ground so you
34083410
// can see properly
3409-
if (draw_control->allow_noclip && m_cache_enable_free_move &&
3410-
client->checkPrivilege("fly")) {
3411+
bool noclip_fly = draw_control->allow_noclip &&
3412+
m_cache_enable_free_move &&
3413+
client->checkPrivilege("fly");
3414+
if (!sky->getAutoCaveBrightness() || noclip_fly) {
34113415
direct_brightness = time_brightness;
34123416
sunlight_seen = true;
34133417
} else {

src/client/sky.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ class Sky : public scene::ISceneNode
122122
return getBgColor();
123123
}
124124

125+
void setAutoCaveBrightness(bool auto_dim_skybox)
126+
{
127+
m_sky_params.auto_dim_skybox = auto_dim_skybox;
128+
}
129+
bool getAutoCaveBrightness() const
130+
{
131+
return m_sky_params.auto_dim_skybox;
132+
}
133+
125134
private:
126135
aabb3f m_box{{0.0f, 0.0f, 0.0f}};
127136
video::SMaterial m_materials[SKY_MATERIAL_COUNT];

src/network/clientpackethandler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,11 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt)
14251425
break;
14261426
// >= 5.9.0-dev
14271427
*pkt >> skybox.fog_color;
1428+
1429+
if (!pkt->hasRemainingBytes())
1430+
break;
1431+
// >= 5.16.0-dev
1432+
*pkt >> skybox.auto_dim_skybox;
14281433
} while (0);
14291434

14301435
ClientEvent *event = new ClientEvent();

src/script/lua_api/l_object.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2097,7 +2097,7 @@ int ObjectRef::l_set_sky(lua_State *L)
20972097
if (sky_params.textures.size() != 6 && !sky_params.textures.empty())
20982098
throw LuaError("Skybox expects 6 textures!");
20992099

2100-
sky_params.clouds = getboolfield_default(L, 2, "clouds", sky_params.clouds);
2100+
getboolfield(L, 2, "clouds", sky_params.clouds);
21012101

21022102
lua_getfield(L, 2, "sky_color");
21032103
if (lua_istable(L, -1)) {
@@ -2159,6 +2159,8 @@ int ObjectRef::l_set_sky(lua_State *L)
21592159
lua_pop(L, 1);
21602160
}
21612161
lua_pop(L, 1);
2162+
2163+
getboolfield(L, 2, "auto_dim_skybox", sky_params.auto_dim_skybox);
21622164
} else {
21632165
// Handle old set_sky calls, and log deprecated:
21642166
log_deprecated(L, "Deprecated call to set_sky, please check lua_api.md");
@@ -2289,6 +2291,9 @@ int ObjectRef::l_get_sky(lua_State *L)
22892291
lua_pushboolean(L, skybox_params.clouds);
22902292
lua_setfield(L, -2, "clouds");
22912293

2294+
lua_pushboolean(L, skybox_params.auto_dim_skybox);
2295+
lua_setfield(L, -2, "auto_dim_skybox");
2296+
22922297
push_sky_color(L, skybox_params);
22932298
lua_setfield(L, -2, "sky_color");
22942299

src/server.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,6 +1950,8 @@ void Server::SendSetSky(session_t peer_id, const SkyboxParams &params)
19501950

19511951
pkt << params.body_orbit_tilt << params.fog_distance << params.fog_start
19521952
<< params.fog_color;
1953+
1954+
pkt << params.auto_dim_skybox;
19531955
}
19541956

19551957
Send(&pkt);

src/skyparams.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct SkyboxParams
3737
s16 fog_distance { -1 };
3838
float fog_start { -1.0f };
3939
video::SColor fog_color { 0 }; // override, only used if alpha > 0
40+
bool auto_dim_skybox { true };
4041
};
4142

4243
struct SunParams

0 commit comments

Comments
 (0)