Rise
The Vieneo Province
Loading...
Searching...
No Matches
RunwayEdgeLights.h
Go to the documentation of this file.
1#pragma once
2#include "RtsTerrainSurface.h"
3#include <algorithm>
4#include <cmath>
5
7{
8 // Inverse of the user-airfield mapping in CustomUI.fx, PS0 and PS1.
9 // RunwayEdgeLight.dds has one lamp centered at UV (0.5, 0.5).
10 constexpr float StripLeft = .7367412f;
11 constexpr float AcrossRepeat = 565.6621f;
12 constexpr float AlongRepeat = 67.f;
13 constexpr unsigned LampsPerSide = 50;
14
15 template<class Emit> void ForEachAnchor(Emit emit)
16 {
17 // The runway occupies terrain V > .25. Repeats 17..66 lie inside it;
18 // only repeats 0 and 14 across the strip lie outside the pavement.
19 for(unsigned along=17; along<67; ++along)
20 for(unsigned across : {0u,14u})
21 emit(StripLeft+(float(across)+.5f)/AcrossRepeat,
22 (float(along)+.5f)/AlongRepeat);
23 }
24
25 template<class Vector> Vector SurfacePoint(const RtsTerrain::Surface<Vector>& surface,float u,float v)
26 {
27 const unsigned x=u<.5f ? 0 : 1, y=v<.5f ? 0 : 1;
28 u=u*2-float(x); v=v*2-float(y);
29 const auto& ne=surface.points[y][x+1];
30 const auto& sw=surface.points[y+1][x];
31 if(u+v<=1)
32 {
33 const auto& nw=surface.points[y][x];
34 return nw+(ne-nw)*u+(sw-nw)*v;
35 }
36 const auto& se=surface.points[y+1][x+1];
37 return se+(sw-se)*(1-u)+(ne-se)*(1-v);
38 }
39
40 struct Appearance {float diameter,intensity;};
41 inline Appearance SizeAndIntensity(float distanceKm,float displayScale,float night)
42 {
43 if(!std::isfinite(distanceKm) || !std::isfinite(displayScale) || displayScale<=0 || night<=0)
44 return {};
45 const float projected=3.f*displayScale/std::pow((std::max)(.01f,distanceKm),.75f);
46 const float diameter=(std::max)(3.f,(std::min)(8.f*displayScale,projected));
47 // Preserve energy when a distant light is widened to three pixels for
48 // stable coverage. The minimum footprint must not imply infinite range.
49 const float coverage=(std::min)(1.f,projected/diameter);
50 return {diameter,.55f*night*coverage*coverage};
51 }
52}
constexpr float AcrossRepeat
constexpr float AlongRepeat
Appearance SizeAndIntensity(float distanceKm, float displayScale, float night)
void ForEachAnchor(Emit emit)
constexpr float StripLeft
Vector SurfacePoint(const RtsTerrain::Surface< Vector > &surface, float u, float v)
constexpr unsigned LampsPerSide