Rise
The Vieneo Province
Loading...
Searching...
No Matches
LightningAfterimage.h
Go to the documentation of this file.
1#pragma once
2#include <algorithm>
3#include <cmath>
4#include <cstdint>
5
6// Display tuning for a human observer, not additional lightning emission or a
7// physiological prediction. Vieneo's extinction is already in the captured bolt.
9{
10 inline constexpr float PeakOpacity=.12f;
11 inline constexpr double DecaySeconds=.9;
12 inline constexpr double LifetimeSeconds=4;
13 inline constexpr float DarkLuminance=.03f, DayLuminance=.18f;
14 inline constexpr float CaptureThreshold=.15f, FullExposure=2.f;
15 inline float NightGain(float ambient)
16 {
17 return std::isfinite(ambient) ?
18 (std::clamp)((DayLuminance-ambient)/(DayLuminance-DarkLuminance),0.f,1.f) : 0.f;
19 }
20 struct State
21 {
22 double time=0, lastCapture=0;
23 uint64_t viewer=0;
24 float gain=0, decay=0;
25 bool initialized=false, active=false;
26 // Returns true when GPU history must be discarded. Time is wall-clock,
27 // so a pause/minimize cannot freeze a ghost and replay it on return.
28 bool Begin(double now,bool enabled,float ambient,uint64_t view)
29 {
30 const float nextGain=enabled ? NightGain(ambient) : 0;
31 const double dt=now-time;
32 const bool clear=!initialized || !std::isfinite(now) || nextGain<=0 || gain<=0 || view!=viewer
33 || dt<0 || dt>LifetimeSeconds || (active && now-lastCapture>=LifetimeSeconds);
34 if(clear)active=false;
35 decay=clear ? 0.f : float(std::exp(-dt/DecaySeconds));
36 gain=std::isfinite(now) ? nextGain : 0;
37 time=now;viewer=view;initialized=std::isfinite(now);
38 return clear;
39 }
40 void Capture() {if(gain>0){active=true;lastCapture=time;}}
41 };
42}
float NightGain(float ambient)
constexpr float FullExposure
constexpr float DayLuminance
constexpr double LifetimeSeconds
constexpr float DarkLuminance
constexpr float CaptureThreshold
constexpr float PeakOpacity
constexpr double DecaySeconds
bool Begin(double now, bool enabled, float ambient, uint64_t view)