Add per-player shadow direction override via set_lighting#17014
Add per-player shadow direction override via set_lighting#17014sofar wants to merge 1 commit intoluanti-org:masterfrom
Conversation
If you also want to have a different time-of-day that doesn't match the sun direction, yes. |
dcf421f to
d751eec
Compare
|
Thanks @sfan5 - those were spot on comments. I've fixed all of them up. While testing I ran into the "what about old clients" problem and there's no clean way to handle them gracefully without bumping the protocol version, so that's in this new updated version. Maybe that's too aggressive, but, without that servers that want to use this feature have no way to tell clients apart that support it and clients that will use the time based shadow direction. (Tested with a modified version of the |
|
Ah so this isn't entirely right yet with the proto version bump. Want me to drop it from this patch, or, figure out how to fix it up? |
d751eec to
2e4d55a
Compare
Hm? Looks good to me. |
Nah It needs an entry in the unittest lua file for 5.16. I'll add it in a sec. |
2e4d55a to
287b72d
Compare
287b72d to
dc5d3a7
Compare
|
Applied the three suggestions. |
|
Win build failure is a dependency download issue. |
SmallJoker
left a comment
There was a problem hiding this comment.
Looks good overall. A few remarks.
dc5d3a7 to
0b2151e
Compare
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 = vector.new(0.3, 0.9, 0.3)}})
player:set_lighting({shadows = {direction = vector.zero()}}) -- clear
A zero vector is treated as "unset" throughout: Lua API, network
protocol, and client all use the same convention. The shadow direction
is always sent as a v3f on the wire (no flag byte), with {0,0,0}
meaning "use default sun/moon-based direction".
Removed dead code: the timeoftheday fmod computation in updateShadows()
was unused even before this change, and is now removed. The remaining
timeoftheday variable is scoped to the else branch where it is needed.
Updated TOCLIENT_SET_LIGHTING packet documentation in networkprotocol.h
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.
To ensure that servers can differentiate between clients that can, and
can not use this feature, the LATEST_PROTOCOL_VERSION must be bumped before
or at the next release.
0b2151e to
4908adc
Compare
|
Dropped protocol version bump because @SmallJoker told me to ;) |
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 =
falsevector.zero()}}) -- clear overrideThe 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.