Night Vision: Make it work everywhere, reparent to active camera - #164
Open
ratijas wants to merge 6 commits into
Open
Night Vision: Make it work everywhere, reparent to active camera#164ratijas wants to merge 6 commits into
ratijas wants to merge 6 commits into
Conversation
For the sake of bookkeeping let's store all relevant objects in an ad-hoc record structure instead of half a dozen flat members. This will become more impactful with a new upcoming component. Also sort the two lights consistently: Near, then Far.
In HDRP graphics modifying Light.intensity directly is wrong, and will
be overridden (reset) by HDAdditionalLightData once Unity engine
automatically adds one for each Light anyway.
This was not a noticeable bug, because HD light only overrides Light
property in setter and during initialization, but we override it every
frame during Update. However, with an upcoming patch to remove Update
hook, it will become relevant, as in my testing the Light intensity
would be reset at start until the player moves the slider control.
Also, HDAdditionalLightData.intensity uses a different formula than
Light.intensity, which for the default lightUnit = Lumen would be a
factor of `1 / (4 * π)`, i.e.
1 Light.intensity == 4 * π * HDAdditionalLightData.intensity
Allow Imperium's Night Vision to work outdoors and in orbit by decoupling its state from vanilla PlayerControllerB.nightVision state. Vanilla only enables night vision for local or spectated client who is also inside facility (`isInsideFactory`), which limited usefulness of Imperium feature at late hours outdoor. Fixes giosuel#53
Makes it work in Spectate mode, Freecam mode -- everywhere all the time.
Instead of running the code every frame for values which don't change often, subscribe to their updates. This optimization was made possible by removing an unobservable Imperium.Player.nightVision.enabled from the equation earlier.
This is a tiny optimization that avoid processing camera switch events when the whole Night Vision feature is disabled (slider value set to 0).
ratijas
marked this pull request as ready for review
April 16, 2026 01:32
Contributor
Author
|
By the way, please don't squash when merging. All individual commits are are perfectly curated. |
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.
Night Vision: refactor to store objects and components in a struct
For the sake of bookkeeping let's store all relevant objects in an
ad-hoc record structure instead of half a dozen flat members. This will
become more impactful with a new upcoming component.
Also sort the two lights consistently: Near, then Far.
Night Vision: refactor to set intensity on HDAdditionalLightData
In HDRP graphics modifying Light.intensity directly is wrong, and will
be overridden (reset) by HDAdditionalLightData once Unity engine
automatically adds one for each Light anyway.
This was not a noticeable bug, because HD light only overrides Light
property in setter and during initialization, but we override it every
frame during Update. However, with an upcoming patch to remove Update
hook, it will become relevant, as in my testing the Light intensity
would be reset at start until the player moves the slider control.
Also, HDAdditionalLightData.intensity uses a different formula than
Light.intensity, which for the default lightUnit = Lumen would be a
factor of
1 / (4 * π), i.e.Night Vision: Make it work outdoor
Allow Imperium's Night Vision to work outdoors and in orbit by
decoupling its state from vanilla PlayerControllerB.nightVision state.
Vanilla only enables night vision for local or spectated client who is
also inside facility (
isInsideFactory), which limited usefulness ofImperium feature at late hours outdoor.
Fixes #53
Night Vision: Always follow the active camera
Makes it work in Spectate mode, Freecam mode -- everywhere all the time.
Night Vision: Port Update to reactive event handler
Instead of running the code every frame for values which don't change
often, subscribe to their updates.
This optimization was made possible by removing an unobservable
Imperium.Player.nightVision.enabled from the equation earlier.
Night Vision: Disable completely when unused
This is a tiny optimization that avoid processing camera switch events
when the whole Night Vision feature is disabled (slider value set to 0).