Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9147,6 +9147,11 @@ child will follow movement and rotation of that bone.
* `intensity` sets the intensity of the shadows from 0 (no shadows, default) to 1 (blackness)
* `tint` tints the shadows with the provided color, with RGB values ranging from 0 to 255.
(default `{r=0, g=0, b=0}`)
* `direction` is a direction vector that can override the direction of the light,
disregarding the sun/moon position. This is useful for custom skyboxes.
The default is a zero vector and disables the override.
Note: the vector points "outwards" so that `(0, 1, 0)` is equivalent to
the sun at midday shining straight down.
* `exposure` is a table that controls automatic exposure.
The basic exposure factor equation is `e = 2^exposure_correction / clamp(luminance, 2^luminance_min, 2^luminance_max)`
* This has no effect on clients who have the "Automatic Exposure" effect disabled.
Expand Down
18 changes: 12 additions & 6 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3591,17 +3591,23 @@ void Game::updateShadows()

float in_timeofday = std::fmod(runData.time_of_day_smooth, 1.0f);

float timeoftheday = getWickedTimeOfDay(in_timeofday);
bool is_day = timeoftheday > 0.25 && timeoftheday < 0.75;
bool is_shadow_visible = is_day ? sky->getSunVisible() : sky->getMoonVisible();
const auto &lighting = client->getEnv().getLocalPlayer()->getLighting();
shadow->setShadowIntensity(is_shadow_visible ? lighting.shadow_intensity : 0.0f);
shadow->setShadowTint(lighting.shadow_tint);

timeoftheday = std::fmod(timeoftheday + 0.75f, 0.5f) + 0.25f;
const float offset_constant = 10000.0f;

v3f light = is_day ? sky->getSunDirection() : sky->getMoonDirection();
v3f light;
if (lighting.shadow_direction.getLengthSQ() > 0.0f) {
// Custom shadow direction: bypass sun/moon visibility check
shadow->setShadowIntensity(lighting.shadow_intensity);
light = lighting.shadow_direction;
} else {
float timeoftheday = getWickedTimeOfDay(in_timeofday);
bool is_day = timeoftheday > 0.25f && timeoftheday < 0.75f;
bool is_shadow_visible = is_day ? sky->getSunVisible() : sky->getMoonVisible();
shadow->setShadowIntensity(is_shadow_visible ? lighting.shadow_intensity : 0.0f);
light = is_day ? sky->getSunDirection() : sky->getMoonDirection();
}

v3f sun_pos = light * offset_constant;
shadow->getDirectionalLight().setDirection(sun_pos);
Expand Down
2 changes: 2 additions & 0 deletions src/lighting.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#pragma once
#include "SColor.h"
#include "irr_v3d.h"


/**
Expand Down Expand Up @@ -51,4 +52,5 @@ struct Lighting
float bloom_intensity {0.05f};
float bloom_strength_factor {1.0f};
float bloom_radius {1.0f};
v3f shadow_direction;
};
5 changes: 5 additions & 0 deletions src/network/clientpackethandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1875,5 +1875,10 @@ void Client::handleCommand_SetLighting(NetworkPacket *pkt)
*pkt >> lighting.bloom_intensity
>> lighting.bloom_strength_factor
>> lighting.bloom_radius;

if (!pkt->hasRemainingBytes())
break;
// >= 5.16.0-dev
*pkt >> lighting.shadow_direction;
} while (0);
}
7 changes: 7 additions & 0 deletions src/network/networkprotocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,13 @@ enum ToClientCommand : u16
f32 speed_dark_bright
f32 speed_bright_dark
f32 center_weight_power
f32 volumetric_light_strength
SColor shadow_tint
bloom parameters
f32 bloom_intensity
f32 bloom_strength_factor
f32 bloom_radius
v3f shadow_direction ({0,0,0} = unset)
*/

TOCLIENT_SPAWN_PARTICLE_BATCH = 0x64,
Expand Down
6 changes: 6 additions & 0 deletions src/script/lua_api/l_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2691,6 +2691,10 @@ int ObjectRef::l_set_lighting(lua_State *L)
lua_getfield(L, -1, "tint");
read_color(L, -1, &lighting.shadow_tint);
lua_pop(L, 1); // tint
lua_getfield(L, -1, "direction");
if (!lua_isnil(L, -1))
lighting.shadow_direction = check_v3f(L, -1);
lua_pop(L, 1); // direction
}
lua_pop(L, 1); // shadows

Expand Down Expand Up @@ -2744,6 +2748,8 @@ int ObjectRef::l_get_lighting(lua_State *L)
lua_setfield(L, -2, "intensity");
push_ARGB8(L, lighting.shadow_tint);
lua_setfield(L, -2, "tint");
push_v3f(L, lighting.shadow_direction);
lua_setfield(L, -2, "direction");
lua_setfield(L, -2, "shadows");
lua_pushnumber(L, lighting.saturation);
lua_setfield(L, -2, "saturation");
Expand Down
2 changes: 2 additions & 0 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,8 @@ void Server::SendSetLighting(session_t peer_id, const Lighting &lighting)
pkt << lighting.bloom_intensity << lighting.bloom_strength_factor <<
lighting.bloom_radius;

pkt << lighting.shadow_direction;

Send(&pkt);
}

Expand Down
Loading