AMFP Enhanced
C++ reference: the code this unofficial fork added
Loading...
Searching...
No Matches
LuxComfort.h
Go to the documentation of this file.
1/*
2 * AMFP-2026: the comfort pass (PLAN.md "Comfort pass"). Separates what makes the body sick
3 * (roll, smearing, shake, zoom pulses, fast forced turns, view lag) from what tells the story
4 * (sound, the fever): the effects keep their vanilla values and these multipliers are applied
5 * where each one reaches the camera or the screen ("scale on output"), so effects the game code
6 * starts itself are covered too, saves keep vanilla values, and changing the option applies at once.
7 *
8 * Profiles: Original (exactly vanilla, built in), Reduced, Comfort (default under Modern); any
9 * change on the Comfort tab makes it Custom. Pure, unit tested in tests/cpp/test_comfort.cpp.
10 */
11#ifndef LUX_COMFORT_H
12#define LUX_COMFORT_H
13
14#include <cmath>
15
17{
23};
24
25/** Multipliers: 1 = vanilla, 0 = none. */
27{
28 float mfHeadBob; // walk / run / crouch bob, landing bounce, hurt panting
29 float mfRoll; // camera tilt: scripted roll, lean tilt, death roll
30 float mfShake; // screen shake amount
31 float mfBlur; // radial blur and image trail (smearing); low values keep the centre sharp
32 float mfZoom; // FOV / aspect pulses
33 float mfHeadSpin; // the view jerk when hit (as an angle)
34 float mfTurnSpeed; // forced camera turns: 1 = vanilla speed, lower caps the turn rate
35 float mfLanternSway; // lantern pendulum
36 float mfArmLag; // arms trailing behind turns
37 float mfFov; // vertical field of view, degrees
38 bool mbCentreDot; // a small dot even when scripts hide the crosshair
39 bool mbEdgeCue; // soft edge darkening where a distortion is removed
40 bool mbSteadyView; // no look lag at high infection
41};
42
43static const float kLuxVanillaFov = 70.0f;
44static const float kLuxFovMin = 60.0f;
45static const float kLuxFovMax = 90.0f;
46static const float kLuxVanillaHeadSpinDeg = 46.0f; // about, at stock settings (audit)
47
49{
51 switch(alProfile)
52 {
54 v.mfHeadBob = 0.25f; v.mfRoll = 0.35f; v.mfShake = 0.35f; v.mfBlur = 0.35f; v.mfZoom = 0.35f;
55 v.mfHeadSpin = 0.35f; v.mfTurnSpeed = 0.5f; v.mfLanternSway = 0.6f; v.mfArmLag = 0.5f;
56 v.mfFov = kLuxVanillaFov; v.mbCentreDot = true; v.mbEdgeCue = true; v.mbSteadyView = true;
57 break;
59 v.mfHeadBob = 0.0f; v.mfRoll = 0.0f; v.mfShake = 0.15f; v.mfBlur = 0.2f; v.mfZoom = 0.2f;
60 v.mfHeadSpin = 0.15f; v.mfTurnSpeed = 0.15f; v.mfLanternSway = 0.3f; v.mfArmLag = 0.2f;
61 v.mfFov = 75.0f; v.mbCentreDot = true; v.mbEdgeCue = true; v.mbSteadyView = true;
62 break;
63 default: // Original: exactly vanilla
64 v.mfHeadBob = 1; v.mfRoll = 1; v.mfShake = 1; v.mfBlur = 1; v.mfZoom = 1;
65 v.mfHeadSpin = 1; v.mfTurnSpeed = 1; v.mfLanternSway = 1; v.mfArmLag = 1;
66 v.mfFov = kLuxVanillaFov; v.mbCentreDot = false; v.mbEdgeCue = false; v.mbSteadyView = false;
67 break;
68 }
69 return v;
70}
71
72inline float LuxComfortClamp01(float x) { return x < 0 ? 0 : (x > 1 ? 1 : x); }
73
74/** Values read from a config: multipliers 0..1, FOV within the slider range. */
76{
77 float* vMul[] = { &v.mfHeadBob, &v.mfRoll, &v.mfShake, &v.mfBlur, &v.mfZoom, &v.mfHeadSpin,
79 for(int i = 0; i < 9; ++i) *vMul[i] = (*vMul[i] == *vMul[i]) ? LuxComfortClamp01(*vMul[i]) : 1.0f; // NaN -> vanilla
80 if(!(v.mfFov >= kLuxFovMin)) v.mfFov = v.mfFov == v.mfFov && v.mfFov < kLuxFovMin ? kLuxFovMin : kLuxVanillaFov;
81 if(v.mfFov > kLuxFovMax) v.mfFov = kLuxFovMax;
82 return v;
83}
84
85inline bool LuxComfortSame(const cLuxComfortValues& a, const cLuxComfortValues& b)
86{
87 const float e = 0.005f;
88 return std::fabs(a.mfHeadBob - b.mfHeadBob) < e && std::fabs(a.mfRoll - b.mfRoll) < e
89 && std::fabs(a.mfShake - b.mfShake) < e && std::fabs(a.mfBlur - b.mfBlur) < e
90 && std::fabs(a.mfZoom - b.mfZoom) < e && std::fabs(a.mfHeadSpin - b.mfHeadSpin) < e
91 && std::fabs(a.mfTurnSpeed - b.mfTurnSpeed) < e && std::fabs(a.mfLanternSway - b.mfLanternSway) < e
92 && std::fabs(a.mfArmLag - b.mfArmLag) < e && std::fabs(a.mfFov - b.mfFov) < 0.5f
94}
95
96/** Which profile the values are, or Custom. */
98{
99 for(int i = 0; i < eLuxComfort_Custom; ++i)
100 if(LuxComfortSame(v, LuxComfortProfile(i))) return i;
101 return eLuxComfort_Custom;
102}
103
104/** Profiles saved before the comfort tab: "Scripted camera effects" and "Reduce head bob". The old
105 * default (Reduced) moves to the new default, Comfort; only a deliberate stock setup stays Original. */
106inline int LuxComfortFromOld(int alScriptedMotion /*0 Full, 1 Reduced, 2 Off*/, bool abReduceHeadBob)
107{
108 if(alScriptedMotion == 0 && abReduceHeadBob == false) return eLuxComfort_Original;
109 return eLuxComfort_Comfort;
110}
111
112//////////////////////////////////////////////////////////////////////////
113// Helpers used where the effects reach the camera / screen
114
115/** Effects whose neutral value is 0 (shake, blur size, trail amount, roll angle, bob). */
116inline float LuxComfortAmount(float afVanilla, float afMul) { return afVanilla * afMul; }
117
118/** Effects whose neutral value is 1 (FOV and aspect multipliers). */
119inline float LuxComfortMul(float afVanilla, float afMul) { return 1.0f + (afVanilla - 1.0f) * afMul; }
120
121/** Radial blur start distance (0 = from the centre, 1 = edges only): lower blur keeps more of the
122 * centre sharp (Comfort 0.2 -> at least 0.7). Vanilla blur leaves it untouched. */
123inline float LuxComfortBlurStart(float afVanillaStart, float afBlur)
124{
125 if(afBlur >= 1.0f) return afVanillaStart;
126 float fMin = 0.875f * (1.0f - LuxComfortClamp01(afBlur));
127 return afVanillaStart > fMin ? afVanillaStart : fMin;
128}
129
130/** Head spin start speed: the spin slows at a fixed rate, so its angle grows with speed squared;
131 * the square root makes mfHeadSpin scale the angle (Comfort 0.15 -> about 7 degrees). */
132inline float LuxComfortSpinSpeed(float afVanillaSpeed, float afHeadSpin)
133{
134 return afVanillaSpeed * std::sqrt(LuxComfortClamp01(afHeadSpin));
135}
136
137/** Forced turn cap in degrees per second, or 0 for no cap (vanilla). Comfort 0.15 -> 52.5. */
138inline float LuxComfortTurnCapDeg(float afTurnSpeed)
139{
140 if(afTurnSpeed >= 1.0f) return 0;
141 return 30.0f + 150.0f * LuxComfortClamp01(afTurnSpeed);
142}
143
144/** Limit one frame's angle step (radians) to the cap; 0 cap = untouched. */
145inline float LuxComfortLimitStep(float afStepRad, float afTimeStep, float afCapDeg)
146{
147 if(afCapDeg <= 0 || afTimeStep <= 0) return afStepRad;
148 float fMax = afCapDeg * 3.14159265f / 180.0f * afTimeStep;
149 if(afStepRad > fMax) return fMax;
150 if(afStepRad < -fMax) return -fMax;
151 return afStepRad;
152}
153
154/** Arm lag: number of camera samples averaged (vanilla 13); at least 1 (no lag). */
155inline int LuxComfortArmSamples(int alVanilla, float afArmLag)
156{
157 int l = (int)std::floor((float)alVanilla * LuxComfortClamp01(afArmLag) + 0.5f);
158 return l < 1 ? 1 : l;
159}
160
161/** How much of a distortion was removed, 0..1, relative to a full-strength amount. Drives the
162 * edge darkening that stands in for it. */
163inline float LuxComfortRemoved(float afVanilla, float afApplied, float afFullScale)
164{
165 if(afFullScale <= 0) return 0;
166 return LuxComfortClamp01(std::fabs(afVanilla - afApplied) / afFullScale);
167}
168
169static const float kLuxEdgeCueMaxAlpha = 0.35f;
170static const float kLuxEdgeCueFadeTime = 0.3f;
171
172/** Ease the edge darkening toward its goal (0..1) over about kLuxEdgeCueFadeTime. */
173inline float LuxComfortEaseCue(float afCurrent, float afGoal, float afTimeStep)
174{
175 float fStep = afTimeStep / kLuxEdgeCueFadeTime;
176 if(afCurrent < afGoal) return afCurrent + fStep > afGoal ? afGoal : afCurrent + fStep;
177 return afCurrent - fStep < afGoal ? afGoal : afCurrent - fStep;
178}
179
180#endif
static const float kLuxFovMin
Definition LuxComfort.h:44
eLuxComfortProfile
Definition LuxComfort.h:17
@ eLuxComfort_LastEnum
Definition LuxComfort.h:22
@ eLuxComfort_Custom
Definition LuxComfort.h:21
@ eLuxComfort_Reduced
Definition LuxComfort.h:19
@ eLuxComfort_Comfort
Definition LuxComfort.h:20
@ eLuxComfort_Original
Definition LuxComfort.h:18
int LuxComfortDetect(const cLuxComfortValues &v)
Which profile the values are, or Custom.
Definition LuxComfort.h:97
float LuxComfortSpinSpeed(float afVanillaSpeed, float afHeadSpin)
Head spin start speed: the spin slows at a fixed rate, so its angle grows with speed squared; the squ...
Definition LuxComfort.h:132
static const float kLuxFovMax
Definition LuxComfort.h:45
float LuxComfortBlurStart(float afVanillaStart, float afBlur)
Radial blur start distance (0 = from the centre, 1 = edges only): lower blur keeps more of the centre...
Definition LuxComfort.h:123
static const float kLuxVanillaFov
Definition LuxComfort.h:43
float LuxComfortMul(float afVanilla, float afMul)
Effects whose neutral value is 1 (FOV and aspect multipliers).
Definition LuxComfort.h:119
float LuxComfortRemoved(float afVanilla, float afApplied, float afFullScale)
How much of a distortion was removed, 0..1, relative to a full-strength amount.
Definition LuxComfort.h:163
float LuxComfortEaseCue(float afCurrent, float afGoal, float afTimeStep)
Ease the edge darkening toward its goal (0..1) over about kLuxEdgeCueFadeTime.
Definition LuxComfort.h:173
static const float kLuxEdgeCueFadeTime
Definition LuxComfort.h:170
float LuxComfortClamp01(float x)
Definition LuxComfort.h:72
int LuxComfortArmSamples(int alVanilla, float afArmLag)
Arm lag: number of camera samples averaged (vanilla 13); at least 1 (no lag).
Definition LuxComfort.h:155
float LuxComfortAmount(float afVanilla, float afMul)
Effects whose neutral value is 0 (shake, blur size, trail amount, roll angle, bob).
Definition LuxComfort.h:116
float LuxComfortLimitStep(float afStepRad, float afTimeStep, float afCapDeg)
Limit one frame's angle step (radians) to the cap; 0 cap = untouched.
Definition LuxComfort.h:145
cLuxComfortValues LuxComfortProfile(int alProfile)
Definition LuxComfort.h:48
float LuxComfortTurnCapDeg(float afTurnSpeed)
Forced turn cap in degrees per second, or 0 for no cap (vanilla).
Definition LuxComfort.h:138
cLuxComfortValues LuxComfortSanitize(cLuxComfortValues v)
Values read from a config: multipliers 0..1, FOV within the slider range.
Definition LuxComfort.h:75
int LuxComfortFromOld(int alScriptedMotion, bool abReduceHeadBob)
Profiles saved before the comfort tab: "Scripted camera effects" and "Reduce head bob".
Definition LuxComfort.h:106
static const float kLuxVanillaHeadSpinDeg
Definition LuxComfort.h:46
bool LuxComfortSame(const cLuxComfortValues &a, const cLuxComfortValues &b)
Definition LuxComfort.h:85
static const float kLuxEdgeCueMaxAlpha
Definition LuxComfort.h:169
Multipliers: 1 = vanilla, 0 = none.
Definition LuxComfort.h:27