GTG Thermal Framework
Night vision and the infrared gate
An infrared light should be visible to everybody with night vision – and to nobody without. And a night-vision effect that is not given back burns the next picture out.
The game’s own night vision
Since game version 1.9 the night vision of the vanilla sights is a pair of materials. The component uses them by default, so a device with the framework looks like a vanilla night-vision sight:
| Effect | Slot | Default material |
|---|---|---|
| HDR (the green phosphor look) | 16 | Common/Postprocess/NightVision/NV_HDR_GreenPhosphor.emat |
| Film grain | 19 | Common/Postprocess/NightVision/NV_FilmGrain.emat |
| Thermal | 12 (m_iThermalSlot) | the 40 thermal materials |
Leave m_sNightVisionMaterial and m_sNightGrainMaterial empty for those. A material of your own goes into the same attributes. The slot numbers are not free choices: slot 16 holds the world’s HDR effect, which is why leaving night vision must put the game’s own back, see below.
Infrared is a per-viewer fact
Whether this client can see infrared light right now is purely local. A real IR laser is visible to anyone with night vision of their own, whatever the operator of the device selected. So nothing is replicated: each machine keeps one flag,
set while the player looks through a night-vision optic. It is a static field of GTG_SOFLAM_NVState.
class GTG_SOFLAM_NVState
{
protected static bool s_bTemporaryNV;
// set by devices: true = this client looks through a night-vision optic and can see IR light
static void SetTemporaryNVState(bool state)
{
s_bTemporaryNV = state;
}
static bool IsTemporaryNVState() { return s_bTemporaryNV; }
static bool CanLocalPlayerSeeIR() { ... }
}
The vision component sets the flag itself while night vision is on. Two things are yours:
Your own optic with its own night vision
protected void MyOptic_SetNight(bool on)
{
// FIRST, before any early return: the flag is pure state and has nothing to do with drawing
GTG_SOFLAM_NVState.SetTemporaryNVState(on);
if (!MyOptic_HasRenderer())
return;
// ... then write or clear your effect
}
Your own infrared light
Ask the gate before you switch an IR light on. The light of the SOFLAM does it in one place; this is the pattern:
protected void MyOptic_UpdateIrLight(bool wanted)
{
bool visible = wanted && GTG_SOFLAM_NVState.CanLocalPlayerSeeIR();
m_Light.SetEnabled(visible); // m_Light: your own light entity
}
If the viewer wears the goggles of another mod, that counts as well: CanLocalPlayerSeeIR() asks RHS_IsNVOff on the player controller by name at runtime. If that mod is loaded, the call returns the real answer; if not, it fails and only the framework’s own state counts. The framework therefore builds without that mod.
Effects on a camera of your own
Night vision is written to a camera by a method the framework adds to the vanilla SCR_ScreenEffectsManager. The camera id says which camera; -1 is the player camera:
modded class SCR_ScreenEffectsManager
{
// material = the effect, enable = on/off, camId = -1 for the player camera, keepCleared = do not restore the vanilla default on switch-off
void GTG_SOFLAM_SetHDR(ResourceName material, bool enable, int camId = -1, bool keepCleared = false);
void GTG_SOFLAM_SetGrain(ResourceName material, bool enable, int camId = -1, bool keepCleared = false);
}
SCR_ScreenEffectsManager effects = SCR_ScreenEffectsManager.GetScreenEffectsDisplay();
if (effects)
effects.GTG_SOFLAM_SetHDR(MYOPTIC_NIGHT_MATERIAL, true, MYOPTIC_FEED_CAMERA); // tint only the feed camera
Both methods do nothing on a dedicated server (no renderer).
Switching off means clearing, not replacing
An empty material clears the slot. An early version put the vanilla HDR material back on slot 16 when night vision ended, without the parameters the game runs it with. The slot stayed occupied and, by day, the whole picture burned out after leaving night vision. In game version 1.9 the problem has a second half: slot 16 carries the world’s HDR effect. Clearing it freezes the exposure at its last value and the picture goes white. So on the player camera the framework restores the game’s default HDR and grain on exit; on a foreign camera, which never had one, it clears the slot. That is what the camId and keepCleared parameters decide.
Camera brightness is an override you must give back
The night-vision gain writes a fixed brightness to the camera, SetCameraHDRBrightness(cameraId, value). That value is not a one-frame setting: it stays until somebody takes it away. Measured on a dedicated server: after the top gain step the camera read exactly that value from then on, the thermal picture was white, and so was the normal view after leaving and entering again.
The value -1 hands the brightness back to the game’s automatic exposure.
protected void MyOptic_ReleaseBrightness(BaseWorld world, int cameraId)
{
// -1 = automatic exposure again; any other value stays on the camera
world.SetCameraHDRBrightness(cameraId, -1);
}
The full story of the camera-id trap and of the exposure measurements is on the SOFLAM page Night and thermal vision.