Skip to content

Night Vision: Make it work everywhere, reparent to active camera - #164

Open
ratijas wants to merge 6 commits into
giosuel:developmentfrom
ratijas:work/ratijas/night-vision
Open

Night Vision: Make it work everywhere, reparent to active camera#164
ratijas wants to merge 6 commits into
giosuel:developmentfrom
ratijas:work/ratijas/night-vision

Conversation

@ratijas

@ratijas ratijas commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

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.

1 Light.intensity == 4 * π * HDAdditionalLightData.intensity

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 of
Imperium 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).

ratijas added 6 commits April 16, 2026 01:07
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
ratijas marked this pull request as ready for review April 16, 2026 01:32
@ratijas

ratijas commented Apr 16, 2026

Copy link
Copy Markdown
Contributor Author

By the way, please don't squash when merging. All individual commits are are perfectly curated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant