6#include <simplesquirrel/simplesquirrel.hpp>
12#include <glm/vec3.hpp>
17void throwIfFailed(
const Result<void>& result,
const char* where) {
18 if (result.ok())
return;
19 const auto* diagnostic = result.status().primaryDiagnostic();
20 throw Exception(
"%s: %s", where, diagnostic ? diagnostic->message().c_str() :
"failed");
24T throwOrTake(Result<T>&& result,
const char* where) {
26 const auto* diagnostic = result.status().primaryDiagnostic();
27 throw Exception(
"%s: %s", where, diagnostic ? diagnostic->message().c_str() :
"failed");
29 return std::move(result).value();
37 auto system = std::make_unique<FogSystem>();
46 const auto* diagnostic =
created.status().primaryDiagnostic();
47 throw Exception(
"RealtimeFog.newSystem: %s",
48 diagnostic ? diagnostic->message().c_str() :
"creation failed");
50 return created.value().release();
57void RealtimeFog::expose(ssq::Class&
cls) {
59 cls.addFunc(
"qualityName", [](
RealtimeFog*,
const std::string& quality) -> std::string {
64void RealtimeFog::expose(ssq::Table& table) {
65 auto cls = table.addClass(
name, RealtimeFog::create,
false);
68 auto system = table.addClass<FogSystem>(
69 "FogSystem", std::function<FogSystem*()>([]() -> FogSystem* {
return nullptr; }),
true);
70 system.addFunc(
"quality", [](FogSystem* self) {
73 system.addFunc(
"setQuality", [](FogSystem* self,
const std::string& quality) {
76 system.addFunc(
"simulationTime", [](FogSystem* self) {
return self->simulationTime(); });
77 system.addFunc(
"configureDomain",
78 [](FogSystem* self,
int w,
int h,
int d,
float minX,
float minY,
float minZ,
float maxX,
79 float maxY,
float maxZ) {
81 bounds.minimum = {minX, minY, minZ};
82 bounds.maximum = {maxX, maxY, maxZ};
83 throwIfFailed(self->configureDomain(
w,
h,
d,
bounds),
"FogSystem.configureDomain");
85 system.addFunc(
"seedHeightFog",
86 [](FogSystem* self,
float density,
float height,
float falloff,
float curl) {
87 throwIfFailed(self->seedHeightFog(density,
height, falloff, curl),
88 "FogSystem.seedHeightFog");
90 system.addFunc(
"setMainWind", [](FogSystem* self,
float x,
float y,
float z) {
91 throwIfFailed(self->wind().setMainWind(glm::vec3(
x,
y,
z)),
"FogSystem.setMainWind");
93 system.addFunc(
"setCurlStrength", [](FogSystem* self,
float strength) {
94 throwIfFailed(self->wind().setCurlStrength(
strength),
"FogSystem.setCurlStrength");
96 system.addFunc(
"setCurlTimeScale", [](FogSystem* self,
float scale) {
97 throwIfFailed(self->wind().setCurlTimeScale(
scale),
"FogSystem.setCurlTimeScale");
99 system.addFunc(
"setWindResponseRate", [](FogSystem* self,
float rate) {
100 throwIfFailed(self->wind().setResponseRate(
rate),
"FogSystem.setWindResponseRate");
102 system.addFunc(
"setSphereInteractor",
103 [](FogSystem* self,
float x,
float y,
float z,
float radius,
float vx,
float vy,
107 proxy.position = {
x,
y,
z};
109 proxy.velocity = {
vx,
vy,
vz};
111 proxy.wakeStrength = 1.5f;
112 throwIfFailed(self->interactor().setProxies({proxy}),
113 "FogSystem.setSphereInteractor");
115 system.addFunc(
"clearInteractors", [](FogSystem* self) {
116 throwIfFailed(self->interactor().setProxies({}),
"FogSystem.clearInteractors");
118 system.addFunc(
"stepSimulation", [](FogSystem* self,
float dt) {
119 return throwOrTake(self->stepSimulation(dt),
"FogSystem.stepSimulation").cfl;
123 system.addFunc(
"setOpticalProfile",
124 [](FogSystem* self,
float extinction,
float ar,
float ag,
float ab,
float ao,
125 float up,
float down,
float anisotropy) {
126 throwIfFailed(self->profile().configure(
extinction, glm::vec3(ar, ag,
ab), ao,
127 up, down, anisotropy),
128 "FogSystem.setOpticalProfile");
130 system.addFunc(
"injectToVolumetric", [](FogSystem* self, Volumetric* volumetric) {
131 return throwOrTake(self->injectToVolumetric(volumetric),
"FogSystem.injectToVolumetric");
133 system.addFunc(
"syncToVolumetric",
134 [](FogSystem* self, Volumetric* volumetric,
float lx,
float ly,
float lz,
float r,
135 float g,
float b,
float intensity) {
137 self->syncToVolumetric(volumetric, glm::vec3(lx, ly, lz),
138 glm::vec3(
r,
g,
b), intensity),
139 "FogSystem.syncToVolumetric");
std::array< float, 3 > scale
#define Module_IMPL(ModuleName, newExpr)
EVENGINE_API_FOUNDATION public API.
Move-only operation result carrying either a value or Status.
Orchestrates density, MAC transport, optics, froxel mapping, and art.
Optional graphics satellite for realtime fog (MAC + raymarch + froxel + analytic lights).
Result< std::unique_ptr< FogSystem > > newSystem()
Create an empty FogSystem with Enhanced quality defaults. @ownership Caller owns the returned system....
static std::string qualityName(FogQuality quality)
Parse quality spelling used by scripts ("fast"|"enhanced"|"physical_reference").
FogSystem * newSystemScript()
Script facade: create system or throw; VM owns the pointer.
FogQuality
Tracking / cache / skip budget for the realtime fog pipeline.
@ Enhanced
Temporal + spatial reconstruction, Beer cache.
FogQuality fogQualityFromName(std::string_view name) noexcept
Parse a quality spelling; unknown values yield Enhanced.
constexpr std::string_view fogQualityName(FogQuality quality) noexcept
Stable spelling of a quality preset.