From 80370075415707a022fad5c7bab7b8a5379343f3 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Wed, 21 Oct 2020 17:12:55 -0500 Subject: [PATCH 1/3] Night Vision - Add scotopic effects to normal vision when dark --- addons/nightvision/XEH_PREP.hpp | 1 + addons/nightvision/XEH_postInit.sqf | 15 +++++- .../functions/fnc_scotopicEffects.sqf | 48 +++++++++++++++++++ addons/nightvision/initSettings.sqf | 8 ++++ 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 addons/nightvision/functions/fnc_scotopicEffects.sqf diff --git a/addons/nightvision/XEH_PREP.hpp b/addons/nightvision/XEH_PREP.hpp index c212d22b188..75f9d4613d7 100644 --- a/addons/nightvision/XEH_PREP.hpp +++ b/addons/nightvision/XEH_PREP.hpp @@ -9,4 +9,5 @@ PREP(onVisionModeChanged); PREP(pfeh); PREP(refreshGoggleType); PREP(scaleCtrl); +PREP(scotopicEffects); PREP(setupDisplayEffects); diff --git a/addons/nightvision/XEH_postInit.sqf b/addons/nightvision/XEH_postInit.sqf index 70023223fb7..dd6e2922f30 100644 --- a/addons/nightvision/XEH_postInit.sqf +++ b/addons/nightvision/XEH_postInit.sqf @@ -24,7 +24,7 @@ GVAR(ppeffectBlur) = -1; GVAR(isUsingMagnification) = false; ["ace_settingsInitialized", { - TRACE_4("settingsInitialized",GVAR(disableNVGsWithSights),GVAR(fogScaling),GVAR(noiseScaling),GVAR(effectScaling)); + TRACE_5("settingsInitialized",GVAR(disableNVGsWithSights),GVAR(fogScaling),GVAR(noiseScaling),GVAR(effectScaling),GVAR(scotopicEffects)); ["visionMode", LINKFUNC(onVisionModeChanged), false] call CBA_fnc_addPlayerEventHandler; ["loadout", LINKFUNC(onLoadoutChanged), true] call CBA_fnc_addPlayerEventHandler; @@ -46,6 +46,19 @@ GVAR(isUsingMagnification) = false; [true] call FUNC(setupDisplayEffects); }; }]; + + if (GVAR(scotopicEffects)) then { + +GVAR(scoTestToggle) = true; +["test", "test", "test", { + GVAR(scoTestToggle) = !GVAR(scoTestToggle); +}, {false}, [0x21, [false, false, false]], false] call CBA_fnc_addKeybind; // F Key + + + GVAR(scotopicCC) = ppEffectCreate ["colorCorrections", 1502]; + GVAR(scotopicCC) ppEffectForceInNVG false; + [FUNC(scotopicEffects), [], 1] call CBA_fnc_waitAndExecute; + }; }] call CBA_fnc_addEventHandler; diff --git a/addons/nightvision/functions/fnc_scotopicEffects.sqf b/addons/nightvision/functions/fnc_scotopicEffects.sqf new file mode 100644 index 00000000000..df0baf3fa5e --- /dev/null +++ b/addons/nightvision/functions/fnc_scotopicEffects.sqf @@ -0,0 +1,48 @@ +#include "script_component.hpp" +/* + * Author: PabstMirror + * Adjusts color and luminosity when in dark conditions. + * Simulates rod and cones vision by decreasing color intensity when dark. + * + * Arguments: + * None + * + * Return Value: + * None + * + * Example: + * [] call ace_nightvision_fnc_scotopicEffects + * + * Public: No + */ +private _unit = ACE_player; + +if (EGVAR(common,OldIsCamera) || {!alive _unit} || {currentVisionMode _unit != 0}) exitWith { + GVAR(scotopicCC) ppEffectEnable false; + [FUNC(scotopicEffects), [], 0.1] call CBA_fnc_waitAndExecute; +}; + +getLighting params ["", "_ambientLightBrightness"]; +(getLightingAt _unit) params ["", "", "", "_dynamiclightBrightness"]; + +private _light = _ambientLightBrightness + 5 * _dynamiclightBrightness; +if (_light > 30) exitWith { + GVAR(scotopicCC) ppEffectEnable false; + // if it's day, we can go to sleep for a long while (but won't be responsive to skipTime?) + [FUNC(scotopicEffects), [], [1, 120] select (_ambientLightBrightness > 100)] call CBA_fnc_waitAndExecute; +}; + +private _intensity = if (_light > 5) then { + linearConversion [5, 30, _light, 0.3, 0, true]; // Mesopic +} else { + linearConversion [0, 5, _light, 0.6, 0.3, true]; // Scotopic +}; + +systemChat format ["%1 - %2", _light, _intensity]; + +GVAR(scotopicCC) ppEffectEnable GVAR(scoTestToggle) && true; +// "players like the night blue" +GVAR(scotopicCC) ppEffectAdjust [1,1,0,[1,1,1,0],[_intensity*.95, _intensity*.95,_intensity*1.1, 1-_intensity], [0.15, 1.0, 1.50, 1]]; +GVAR(scotopicCC) ppEffectCommit 1; + +[FUNC(scotopicEffects), [], 1] call CBA_fnc_waitAndExecute; diff --git a/addons/nightvision/initSettings.sqf b/addons/nightvision/initSettings.sqf index 9ccf2cc7f92..6a82fcf595d 100644 --- a/addons/nightvision/initSettings.sqf +++ b/addons/nightvision/initSettings.sqf @@ -84,3 +84,11 @@ true, // default value false // isGlobal ] call CBA_settings_fnc_init; + +[ + QGVAR(scotopicEffects), "CHECKBOX", + [LSTRING(scotopicEffects_DisplayName), LSTRING(scotopicEffects_description)], + localize LSTRING(Category), + false, // default value + true // isGlobal +] call CBA_settings_fnc_init; From 559581f3838abb7561687f1e57572f88b0625356 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 19 Oct 2021 01:12:34 -0500 Subject: [PATCH 2/3] tweak numbers --- addons/nightvision/XEH_postInit.sqf | 19 ++++++---- .../functions/fnc_scotopicEffects.sqf | 38 +++++++++++-------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/addons/nightvision/XEH_postInit.sqf b/addons/nightvision/XEH_postInit.sqf index 12d31a1f0fe..6ad7f5990be 100644 --- a/addons/nightvision/XEH_postInit.sqf +++ b/addons/nightvision/XEH_postInit.sqf @@ -21,6 +21,8 @@ GVAR(ppeffectRadialBlur) = -1; GVAR(ppeffectColorCorrect) = -1; GVAR(ppeffectBlur) = -1; +GVAR(scotopicCC) = -1; + GVAR(isUsingMagnification) = false; ["CBA_settingsInitialized", { @@ -45,19 +47,22 @@ GVAR(isUsingMagnification) = false; [false] call FUNC(setupDisplayEffects); [true] call FUNC(setupDisplayEffects); }; + if (GVAR(scotopicCC) > -1) then { + ppEffectDestroy GVAR(scotopicCC); + GVAR(scotopicCC) = ppEffectCreate ["colorCorrections", 1502]; + GVAR(scotopicCC) ppEffectForceInNVG false; + }; }]; if (GVAR(scotopicEffects)) then { - -GVAR(scoTestToggle) = true; -["test", "test", "test", { - GVAR(scoTestToggle) = !GVAR(scoTestToggle); -}, {false}, [0x21, [false, false, false]], false] call CBA_fnc_addKeybind; // F Key - + GVAR(scoTestToggle) = true; + ["test", "test", "test", { + GVAR(scoTestToggle) = !GVAR(scoTestToggle); + }, {false}, [0x21, [false, false, false]], false] call CBA_fnc_addKeybind; // F Key GVAR(scotopicCC) = ppEffectCreate ["colorCorrections", 1502]; GVAR(scotopicCC) ppEffectForceInNVG false; - [FUNC(scotopicEffects), [], 1] call CBA_fnc_waitAndExecute; + [0] call FUNC(scotopicEffects); // self-loops }; }] call CBA_fnc_addEventHandler; diff --git a/addons/nightvision/functions/fnc_scotopicEffects.sqf b/addons/nightvision/functions/fnc_scotopicEffects.sqf index df0baf3fa5e..80de01f28f4 100644 --- a/addons/nightvision/functions/fnc_scotopicEffects.sqf +++ b/addons/nightvision/functions/fnc_scotopicEffects.sqf @@ -5,44 +5,50 @@ * Simulates rod and cones vision by decreasing color intensity when dark. * * Arguments: - * None + * 0: Last Intensity * * Return Value: * None * * Example: - * [] call ace_nightvision_fnc_scotopicEffects + * [0] call ace_nightvision_fnc_scotopicEffects * * Public: No */ +#define TIME_INTERVAL 0.333 private _unit = ACE_player; if (EGVAR(common,OldIsCamera) || {!alive _unit} || {currentVisionMode _unit != 0}) exitWith { GVAR(scotopicCC) ppEffectEnable false; - [FUNC(scotopicEffects), [], 0.1] call CBA_fnc_waitAndExecute; + [FUNC(scotopicEffects), [0], 0.1] call CBA_fnc_waitAndExecute; }; -getLighting params ["", "_ambientLightBrightness"]; -(getLightingAt _unit) params ["", "", "", "_dynamiclightBrightness"]; +(getLightingAt _unit) params ["", "_ambientLight", "", "_dynamiclight"]; +private _light = _ambientLight + 2 * _dynamiclight; + +#ifdef DEBUG_MODE_FULL +systemChat format ["[%1, %2] = %3", [_ambientLight,1,1] call CBA_fnc_formatNumber, [_dynamiclight,1,1] call CBA_fnc_formatNumber, _light]; +#endif -private _light = _ambientLightBrightness + 5 * _dynamiclightBrightness; -if (_light > 30) exitWith { +if ((_light > 50) && {(param [0, 0]) == 0}) exitWith { // make sure we've faded out before disabling GVAR(scotopicCC) ppEffectEnable false; - // if it's day, we can go to sleep for a long while (but won't be responsive to skipTime?) - [FUNC(scotopicEffects), [], [1, 120] select (_ambientLightBrightness > 100)] call CBA_fnc_waitAndExecute; + // if it's day, we can go to sleep for a long while (won't be responsive to scripted-skipTime) + [FUNC(scotopicEffects), [0], [TIME_INTERVAL, 60] select (_ambientLight > 100)] call CBA_fnc_waitAndExecute; }; private _intensity = if (_light > 5) then { - linearConversion [5, 30, _light, 0.3, 0, true]; // Mesopic + linearConversion [5, 50, _light, 0.3, 0, true]; // Mesopic } else { - linearConversion [0, 5, _light, 0.6, 0.3, true]; // Scotopic + linearConversion [0, 6, _light, 0.6, 0.3, true]; // Scotopic }; -systemChat format ["%1 - %2", _light, _intensity]; +#ifdef DEBUG_MODE_FULL +systemChat format ["@%1", _intensity]; +#endif -GVAR(scotopicCC) ppEffectEnable GVAR(scoTestToggle) && true; +GVAR(scotopicCC) ppEffectEnable GVAR(scoTestToggle); // true; // "players like the night blue" -GVAR(scotopicCC) ppEffectAdjust [1,1,0,[1,1,1,0],[_intensity*.95, _intensity*.95,_intensity*1.1, 1-_intensity], [0.15, 1.0, 1.50, 1]]; -GVAR(scotopicCC) ppEffectCommit 1; +GVAR(scotopicCC) ppEffectAdjust [1,1,0,[1,1,1,0],[_intensity*.95,_intensity*.95,_intensity*1.1,1-_intensity],[0.15, 1.0, 1.50, 1]]; +GVAR(scotopicCC) ppEffectCommit TIME_INTERVAL; -[FUNC(scotopicEffects), [], 1] call CBA_fnc_waitAndExecute; +[FUNC(scotopicEffects), [_intensity], TIME_INTERVAL] call CBA_fnc_waitAndExecute; From f6eb30ec08bb333ca4c9cd63fb67259597c1787a Mon Sep 17 00:00:00 2001 From: Mike-MF Date: Fri, 22 Sep 2023 18:39:55 +0100 Subject: [PATCH 3/3] Fix build failure, add stringtable entries. --- addons/nightvision/functions/fnc_scotopicEffects.sqf | 4 ++-- addons/nightvision/stringtable.xml | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/nightvision/functions/fnc_scotopicEffects.sqf b/addons/nightvision/functions/fnc_scotopicEffects.sqf index 80de01f28f4..69553643106 100644 --- a/addons/nightvision/functions/fnc_scotopicEffects.sqf +++ b/addons/nightvision/functions/fnc_scotopicEffects.sqf @@ -1,7 +1,7 @@ -#include "script_component.hpp" +#include "..\script_component.hpp" /* * Author: PabstMirror - * Adjusts color and luminosity when in dark conditions. + * Adjusts color and luminosity when in dark conditions. * Simulates rod and cones vision by decreasing color intensity when dark. * * Arguments: diff --git a/addons/nightvision/stringtable.xml b/addons/nightvision/stringtable.xml index c7d9e6e9135..c3aa5ab7727 100644 --- a/addons/nightvision/stringtable.xml +++ b/addons/nightvision/stringtable.xml @@ -538,5 +538,11 @@ Gen %1 Gen %1 + + Scotopic Effects + + + Adjusts color and luminosity when in dark conditions. Simulates rod and cones vision by decreasing color intensity when dark. +