Files
FluidSimCpp/include/FluidSim/Desktop/PressurePalette.hpp

32 lines
1.5 KiB
C++

#pragma once
#include "FluidSim/AudioProcessing.hpp"
#include <algorithm>
#include <cmath>
namespace fluidsim::port::desktop {
// Keep the established absolute vacuum palette. Above atmosphere, use a
// narrower positive range so modest pulses stand out from the green baseline.
inline Vec3 pressure_tint(float pressure, bool exhaust=false, float temperature=300.f) {
if(pressure<=101325) {float t=std::clamp(pressure/101325,0.f,1.f);return {.05f,.15f+.70f*t,1-.95f*t};}
const float temperature_boost=std::sqrt(std::clamp(temperature/300.f,.25f,9.f));
const float pulse=(pressure-101325.f)*temperature_boost;
// Exhaust reaches the warm colors sooner, while using the same continuous
// ramp so the atmosphere boundary and pulse edges stay smooth.
const float scale=exhaust?45000.f:150000.f;
const float t=pulse/(pulse+scale);
const auto mix=[](Vec3 a,Vec3 b,float u) {
u=u*u*(3.f-2.f*u);
return Vec3{a.x+(b.x-a.x)*u,a.y+(b.y-a.y)*u,a.z+(b.z-a.z)*u};
};
constexpr Vec3 green{.05f,.85f,.05f},yellow{1.f,1.f,.03f},orange{1.f,.52f,.02f},red{1.f,0.f,0.f};
if(t<.35f)return mix(green,yellow,t/.35f);
if(t<.68f)return mix(yellow,orange,(t-.35f)/.33f);
return mix(orange,red,(t-.68f)/.32f);
}
inline float pressure_expansion(float pressure,float temperature=300.f) {
if(pressure<=101325.f)return 0.f;
const float temperature_boost=std::sqrt(std::clamp(temperature/300.f,.25f,9.f));
const float pulse=(pressure-101325.f)*temperature_boost;
return .10f*pulse/(pulse+80000.f);
}
}