Rise
The Vieneo Province
Toggle main menu visibility
Loading...
Searching...
No Matches
BeamProfile.h
Go to the documentation of this file.
1
#pragma once
2
#include <algorithm>
3
#include <cmath>
4
5
namespace
LandingLights
6
{
7
// Full beam angles in degrees. The core is the half-intensity width;
8
// the outer ellipse is the edge of the much weaker spill. Distances are km.
9
// Peak candela is PER LAMP, so adding a lamp increases light, not its range.
10
struct
Profile
11
{
12
float
coreHorizontal
= 12,
coreVertical
= 12;
13
float
outerHorizontal
= 22,
outerVertical
= 22;
14
float
peakCandela
= 625000,
rangeKm
= 1.6f;
15
float
spill
= .02f;
16
float
cutoffSlope
= 1000;
// road low beam: upper edge relative to authored aim
17
18
template
<
class
PackedVector> PackedVector
Angles
()
const
19
{
20
constexpr
float
halfDegree = 3.141592654f / 360;
21
return
PackedVector(std::tan(
coreHorizontal
* halfDegree), std::tan(
coreVertical
* halfDegree),
22
std::tan(
outerHorizontal
* halfDegree), std::tan(
outerVertical
* halfDegree));
23
}
24
template
<
class
PackedVector> PackedVector
Parameters
(
float
extinctionPerKm = 0)
const
25
{
26
// 20 lux maps to unit scene light; 1e6 converts square km to square m.
27
return
PackedVector(
peakCandela
/ 20000000.f,
spill
,
cutoffSlope
, extinctionPerKm);
28
}
29
};
30
// Clear-air tuning targets, not regulatory specifications. Two overlapping
31
// lamps reach ~5 lux at 80/200/250/500/300 m respectively, before angular loss.
32
// A shallow bright core reaches down the road. The wider 2% spill fills
33
// the foreground from about 1 m ahead for a 0.5 m-high lamp; the upper
34
// cutoff applies to both, keeping the wash below the horizon.
35
inline
constexpr
Profile
RoadLow
{30, 6, 80, 60, 16000, .25f, .02f, -.01f};
36
inline
constexpr
Profile
CarHigh
{12, 12, 30, 30, 100000, .65f, .02f};
37
inline
constexpr
Profile
TruckDriving
{10, 10, 30, 30, 156250, .8f, .02f};
38
inline
constexpr
Profile
AircraftLanding
{};
39
inline
constexpr
Profile
AircraftTaxi
{40, 12, 50, 15, 35000, .45f, .02f};
40
inline
constexpr
Profile
Train
{8, 8, 40, 40, 225000, .95f, .002f};
41
inline
constexpr
Profile
Helmet
{20, 20, 40, 40, 4000, .18f, .02f};
42
43
template
<
class
Vector> Vector
OrthonormalUp
(Vector up,
const
Vector& direction)
44
{
45
auto
project = [&]() {
46
const
float
dot = up.x*direction.x+up.y*direction.y+up.z*direction.z;
47
up.x-=dot*direction.x; up.y-=dot*direction.y; up.z-=dot*direction.z;
48
return
up.x*up.x+up.y*up.y+up.z*up.z;
49
};
50
float
length = project();
51
if
(!std::isfinite(length) || length < 1e-8f)
52
{
53
up = std::abs(direction.y) < .9f ? Vector(0,1,0) : Vector(1,0,0);
54
length = project();
55
}
56
const
float
inverse = 1/std::sqrt(length);
57
return
Vector(up.x*inverse,up.y*inverse,up.z*inverse);
58
}
59
60
inline
float
Smooth
(
float
low,
float
high,
float
value)
61
{
62
const
float
t = (std::clamp)((value - low) / (high - low), 0.f, 1.f);
63
return
t * t * (3 - 2 * t);
64
}
65
// Shared CPU fallback, also used to verify the photometric contract.
66
inline
float
Angular
(
const
Profile
& profile,
float
horizontalSlope,
float
verticalSlope,
float
axialDistanceKm)
67
{
68
constexpr
float
halfDegree = 3.141592654f / 360;
69
const
float
x = horizontalSlope / std::tan(profile.
coreHorizontal
* halfDegree);
70
const
float
y = verticalSlope / std::tan(profile.
coreVertical
* halfDegree);
71
const
float
u = horizontalSlope / std::tan(profile.
outerHorizontal
* halfDegree);
72
const
float
v = verticalSlope / std::tan(profile.
outerVertical
* halfDegree);
73
// Keep the upper limit, but feather below it over 6 cm at the lens
74
// plus 0.8% of throw. The near-field edge no longer becomes a knife
75
// edge, and its physical width grows with distance. Match BeamLighting.fxh.
76
const
float
cutoffWidth = .008f + .00006f / (std::max)(axialDistanceKm, .000001f);
77
return
((1-profile.
spill
)*std::exp2(-x*x-y*y)+profile.
spill
)
78
* (1-
Smooth
(.8f, 1.f, std::sqrt(u*u+v*v)))
79
* (1-
Smooth
(profile.
cutoffSlope
-cutoffWidth, profile.
cutoffSlope
, verticalSlope));
80
}
81
inline
float
IlluminanceLux
(
const
Profile
& profile,
float
distanceKm)
82
{
83
if
(distanceKm <= 0 || distanceKm >= profile.
rangeKm
)
return
0;
84
return
profile.
peakCandela
/ (1000000 * (std::max)(distanceKm*distanceKm, .000001f))
85
* (1-
Smooth
(profile.
rangeKm
*.8f, profile.
rangeKm
, distanceKm));
86
}
87
}
LandingLights
Definition
BeamProfile.h:6
LandingLights::AircraftLanding
constexpr Profile AircraftLanding
Definition
BeamProfile.h:38
LandingLights::Helmet
constexpr Profile Helmet
Definition
BeamProfile.h:41
LandingLights::IlluminanceLux
float IlluminanceLux(const Profile &profile, float distanceKm)
Definition
BeamProfile.h:81
LandingLights::AircraftTaxi
constexpr Profile AircraftTaxi
Definition
BeamProfile.h:39
LandingLights::OrthonormalUp
Vector OrthonormalUp(Vector up, const Vector &direction)
Definition
BeamProfile.h:43
LandingLights::RoadLow
constexpr Profile RoadLow
Definition
BeamProfile.h:35
LandingLights::Smooth
float Smooth(float low, float high, float value)
Definition
BeamProfile.h:60
LandingLights::CarHigh
constexpr Profile CarHigh
Definition
BeamProfile.h:36
LandingLights::Train
constexpr Profile Train
Definition
BeamProfile.h:40
LandingLights::Angular
float Angular(const Profile &profile, float horizontalSlope, float verticalSlope, float axialDistanceKm)
Definition
BeamProfile.h:66
LandingLights::TruckDriving
constexpr Profile TruckDriving
Definition
BeamProfile.h:37
LandingLights::Profile
Definition
BeamProfile.h:11
LandingLights::Profile::outerVertical
float outerVertical
Definition
BeamProfile.h:13
LandingLights::Profile::coreVertical
float coreVertical
Definition
BeamProfile.h:12
LandingLights::Profile::Parameters
PackedVector Parameters(float extinctionPerKm=0) const
Definition
BeamProfile.h:24
LandingLights::Profile::coreHorizontal
float coreHorizontal
Definition
BeamProfile.h:12
LandingLights::Profile::spill
float spill
Definition
BeamProfile.h:15
LandingLights::Profile::rangeKm
float rangeKm
Definition
BeamProfile.h:14
LandingLights::Profile::Angles
PackedVector Angles() const
Definition
BeamProfile.h:18
LandingLights::Profile::outerHorizontal
float outerHorizontal
Definition
BeamProfile.h:13
LandingLights::Profile::peakCandela
float peakCandela
Definition
BeamProfile.h:14
LandingLights::Profile::cutoffSlope
float cutoffSlope
Definition
BeamProfile.h:16
Viewscreen
BeamProfile.h
Generated on
for Rise by
1.18.0