Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NightVision - Don't apply AimDownSightsBlur on optics with integrated night vision #7548

Merged
merged 3 commits into from
Feb 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/nightvision/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ GVAR(ppeffectRadialBlur) = -1;
GVAR(ppeffectColorCorrect) = -1;
GVAR(ppeffectBlur) = -1;

GVAR(isUsingMagnification) = false;

["ace_settingsInitialized", {
TRACE_4("settingsInitialized",GVAR(disableNVGsWithSights),GVAR(fogScaling),GVAR(noiseScaling),GVAR(effectScaling));
Expand Down
2 changes: 1 addition & 1 deletion addons/nightvision/functions/fnc_onCameraViewChanged.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ params ["_unit", "_cameraView"];
TRACE_2("onCameraViewChanged",_unit,_cameraView);

// Refresh goggle effect (e.g. switching to vehicle's NVG)
[] call FUNC(refreshGoggleType);
call FUNC(refreshGoggleType);

if (GVAR(disableNVGsWithSights) && {(hmd _unit) != ""}) then {
if ((vehicle _unit == _unit)
Expand Down
29 changes: 20 additions & 9 deletions addons/nightvision/functions/fnc_pfeh.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* Public: No
*/

if ((currentVisionMode ACE_player) != 1) exitWith {
private _unit = ACE_player;

if (currentVisionMode _unit != 1) exitWith {
GVAR(running) = false;
[false] call FUNC(setupDisplayEffects);
[GVAR(PFID)] call CBA_fnc_removePerFrameHandler;
Expand All @@ -28,7 +30,7 @@ if ((currentVisionMode ACE_player) != 1) exitWith {
};
if (EGVAR(common,OldIsCamera)) exitWith {
if (GVAR(running)) then {
TRACE_2("pausing NVG for scripted camera",alive ACE_player,EGVAR(common,OldIsCamera));
TRACE_2("pausing NVG for scripted camera",alive _unit,EGVAR(common,OldIsCamera));
GVAR(running) = false;
[false] call FUNC(setupDisplayEffects);
};
Expand All @@ -45,7 +47,7 @@ BEGIN_COUNTER(borderScaling);
private _scale = (call EFUNC(common,getZoom)) * 1.12513;
if (!(GVAR(defaultPositionBorder) isEqualTo [])) then {
// Prevents issues when "zooming out" on ultra wide monitors - The square mask would be narrower than the screen
if (((GVAR(defaultPositionBorder) select 2) * _scale) < safeZoneW) then {
if ((GVAR(defaultPositionBorder) select 2) * _scale < safeZoneW) then {
_scale = safeZoneW / (GVAR(defaultPositionBorder) select 2);
};
[(uiNamespace getVariable QGVAR(titleDisplay)) displayCtrl 1000, GVAR(defaultPositionHex), _scale] call FUNC(scaleCtrl);
Expand All @@ -55,6 +57,11 @@ if (!(GVAR(defaultPositionBorder) isEqualTo [])) then {
};
END_COUNTER(borderScaling);

if !(IS_MAGNIFIED isEqualTo GVAR(isUsingMagnification)) then {
GVAR(isUsingMagnification) = IS_MAGNIFIED;
GVAR(nextEffectsUpdate) = -1;
};

if (CBA_missionTime < GVAR(nextEffectsUpdate)) then {
// Update radial blur as it depends on zoom level, so should be changed each frame like the border/hex
if (GVAR(ppeffectRadialBlur) != -1) then {
Expand Down Expand Up @@ -87,10 +94,11 @@ if (CBA_missionTime < GVAR(nextEffectsUpdate)) then {
private _fogApply = linearConversion [0, 1, _effectiveLight, ST_NVG_MAXFOG, ST_NVG_MINFOG, true];

// Modify blur if looking down scope
if ((cameraView == "GUNNER") && {[ACE_player] call CBA_fnc_canUseWeapon}) then {
if (currentWeapon ACE_player == "") exitWith {};
if (currentWeapon ACE_player == primaryWeapon ACE_player) exitWith {_blurFinal = _blurFinal * linearConversion [0, 1, GVAR(aimDownSightsBlur), 1, ST_NVG_CAMERA_BLUR_SIGHTS_RIFLE]}; // Rifles are bad
if (currentWeapon ACE_player == handgunWeapon ACE_player) exitWith {_blurFinal = _blurFinal * linearConversion [0, 1, GVAR(aimDownSightsBlur), 1, ST_NVG_CAMERA_BLUR_SIGHTS_PISTOL]}; // Pistols aren't so bad
if (cameraView == "GUNNER" && {[_unit] call CBA_fnc_canUseWeapon && {!GVAR(isUsingMagnification)}}) then {
private _weapon = currentWeapon _unit;
if (_weapon == "") exitWith {};
if (_weapon == primaryWeapon _unit) exitWith {_blurFinal = _blurFinal * linearConversion [0, 1, GVAR(aimDownSightsBlur), 1, ST_NVG_CAMERA_BLUR_SIGHTS_RIFLE]}; // Rifles are bad
if (_weapon == handgunWeapon _unit) exitWith {_blurFinal = _blurFinal * linearConversion [0, 1, GVAR(aimDownSightsBlur), 1, ST_NVG_CAMERA_BLUR_SIGHTS_PISTOL]}; // Pistols aren't so bad
};

// Scale general effects based on ace_nightvision_effectScaling setting
Expand All @@ -99,7 +107,7 @@ if (CBA_missionTime < GVAR(nextEffectsUpdate)) then {
_contrastFinal = linearConversion [0, 1, GVAR(effectScaling), 1, _contrastFinal];

// Add adjusted NVG brightness
private _playerBrightSetting = ACE_player getVariable [QGVAR(NVGBrightness), 0];
private _playerBrightSetting = _unit getVariable [QGVAR(NVGBrightness), 0];
_brightFinal = _brightFinal + (_playerBrightSetting / 20);

// Scale grain effects based on ace_nightvision_noiseScaling setting
Expand Down Expand Up @@ -148,9 +156,12 @@ if (CBA_missionTime < GVAR(nextEffectsUpdate)) then {

// Modify local fog:
if (GVAR(fogScaling) > 0) then {
if (((vehicle ACE_player) != ACE_player) && {(vehicle ACE_player) isKindOf "Air"}) then { // For flying in particular, can refine nicer later.
private _vehicle = vehicle _unit;

if (_vehicle != _unit && {_vehicle isKindOf "Air"}) then { // For flying in particular, can refine nicer later.
_fogApply = _fogApply * ST_NVG_AIR_FOG_MULTIPLIER;
};

_fogApply = linearConversion [0, 1, GVAR(priorFog) select 0, (GVAR(fogScaling) * _fogApply), 1]; // mix in old fog if present
GVAR(nvgFog) = [_fogApply, 0, 0];
0 setFog GVAR(nvgFog)
Expand Down
2 changes: 2 additions & 0 deletions addons/nightvision/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@

#define ST_NVG_NOISESHARPNESS_MIN 1.2
#define ST_NVG_NOISESHARPNESS_MAX 1

#define IS_MAGNIFIED (0.75 call CBA_fnc_getFOV select 1 > 3.01)