Add per-player shadow direction override via set_lighting#17014
Open
sofar wants to merge 1 commit intoluanti-org:masterfrom
Open
Add per-player shadow direction override via set_lighting#17014sofar wants to merge 1 commit intoluanti-org:masterfrom
sofar wants to merge 1 commit intoluanti-org:masterfrom
Conversation
Add an optional shadow.direction field to the lighting struct, allowing
server mods to override the shadow light direction on a per-player basis.
This is needed for games that use custom skyboxes where the sun/moon
position in the skybox texture does not correspond to the engine's
internal time-of-day cycle.
When shadow_direction is set, Game::updateShadows() uses it directly
instead of computing direction from getSunDirection()/getMoonDirection(),
and applies shadow_intensity unconditionally (bypassing the sun/moon
visibility check that would otherwise zero out shadows).
Lua API:
player:set_lighting({shadows = {direction = {x=0.3, y=0.9, z=0.3}}})
player:set_lighting({shadows = {direction = false}}) -- clear override
The TOCLIENT_SET_LIGHTING packet documentation in networkprotocol.h was
outdated, listing only the original fields (shadow_intensity, saturation,
exposure parameters) while the actual packet has grown over several
releases to include volumetric_light_strength, shadow_tint, and bloom
parameters. The documentation is now updated to reflect all fields
actually sent and parsed, plus the new shadow direction.
Network compatibility: the new field is appended to the end of the
packet. Old clients ignore the extra bytes. New clients handle missing
bytes via the existing hasRemainingBytes() pattern, falling back to
sun/moon-based shadows when the server does not send a direction.
Member
If you also want to have a different time-of-day that doesn't match the sun direction, yes. |
sfan5
requested changes
Mar 11, 2026
| light = is_day ? sky->getSunDirection() : sky->getMoonDirection(); | ||
| } | ||
|
|
||
| timeoftheday = std::fmod(timeoftheday + 0.75f, 0.5f) + 0.25f; |
Member
There was a problem hiding this comment.
timeoftheday is never read after this, I think it's supposed to be before the if
| if (!pkt->hasRemainingBytes()) | ||
| break; | ||
|
|
||
| u8 has_shadow_dir; |
Member
There was a problem hiding this comment.
Suggested change
| u8 has_shadow_dir; | |
| // >= 5.16.0-dev | |
| u8 has_shadow_dir; |
| getfloatfield(L, -1, "x", dir.X); | ||
| getfloatfield(L, -1, "y", dir.Y); | ||
| getfloatfield(L, -1, "z", dir.Z); | ||
| lighting.shadow_direction = dir; |
| lua_pushnumber(L, dir.Y); | ||
| lua_setfield(L, -2, "y"); | ||
| lua_pushnumber(L, dir.Z); | ||
| lua_setfield(L, -2, "z"); |
| lua_pushnumber(L, dir.Z); | ||
| lua_setfield(L, -2, "z"); | ||
| lua_setfield(L, -2, "direction"); | ||
| } |
Member
There was a problem hiding this comment.
also missing documentation for this
| f32 bloom_intensity | ||
| f32 bloom_strength_factor | ||
| f32 bloom_radius | ||
| u8 has_shadow_direction |
Member
There was a problem hiding this comment.
we could actually skip this byte, since (0, 0, 0) can already represent "no direction"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add an optional shadow.direction field to the lighting struct, allowing server mods to override the shadow light direction on a per-player basis. This is needed for games that use custom skyboxes where the sun/moon position in the skybox texture does not correspond to the engine's internal time-of-day cycle.
When shadow_direction is set, Game::updateShadows() uses it directly instead of computing direction from getSunDirection()/getMoonDirection(), and applies shadow_intensity unconditionally (bypassing the sun/moon visibility check that would otherwise zero out shadows).
Lua API:
player:set_lighting({shadows = {direction = {x=0.3, y=0.9, z=0.3}}})
player:set_lighting({shadows = {direction = false}}) -- clear override
The TOCLIENT_SET_LIGHTING packet documentation in networkprotocol.h was outdated, listing only the original fields (shadow_intensity, saturation, exposure parameters) while the actual packet has grown over several releases to include volumetric_light_strength, shadow_tint, and bloom parameters. The documentation is now updated to reflect all fields actually sent and parsed, plus the new shadow direction.
Network compatibility: the new field is appended to the end of the packet. Old clients ignore the extra bytes. New clients handle missing bytes via the existing hasRemainingBytes() pattern, falling back to sun/moon-based shadows when the server does not send a direction.