载入中...
搜索中...
未找到
RealtimeFog.cpp
浏览该文件的文档.
2
3#include "common/Exception.h"
5
6#include <simplesquirrel/simplesquirrel.hpp>
7
8#include <functional>
9#include <string>
10#include <vector>
11
12#include <glm/vec3.hpp>
13
14namespace eve::graphics::fog {
15namespace {
16
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");
21}
22
23template <typename T>
24T throwOrTake(Result<T>&& result, const char* where) {
25 if (!result.ok()) {
26 const auto* diagnostic = result.status().primaryDiagnostic();
27 throw Exception("%s: %s", where, diagnostic ? diagnostic->message().c_str() : "failed");
28 }
29 return std::move(result).value();
30}
31
32} // namespace
33
35
37 auto system = std::make_unique<FogSystem>();
38 auto quality = system->setQuality(FogQuality::Enhanced);
39 if (!quality.ok()) return Result<std::unique_ptr<FogSystem>>::failure(quality.status());
40 return Result<std::unique_ptr<FogSystem>>::success(std::move(system));
41}
42
44 auto created = newSystem();
45 if (!created.ok()) {
46 const auto* diagnostic = created.status().primaryDiagnostic();
47 throw Exception("RealtimeFog.newSystem: %s",
48 diagnostic ? diagnostic->message().c_str() : "creation failed");
49 }
50 return created.value().release();
51}
52
54 return std::string(fogQualityName(quality));
55}
56
57void RealtimeFog::expose(ssq::Class& cls) {
58 cls.addFunc("newSystem", &RealtimeFog::newSystemScript);
59 cls.addFunc("qualityName", [](RealtimeFog*, const std::string& quality) -> std::string {
60 return std::string(fogQualityName(fogQualityFromName(quality)));
61 });
62}
63
64void RealtimeFog::expose(ssq::Table& table) {
65 auto cls = table.addClass(name, RealtimeFog::create, false);
66 expose(cls);
67
68 auto system = table.addClass<FogSystem>(
69 "FogSystem", std::function<FogSystem*()>([]() -> FogSystem* { return nullptr; }), true);
70 system.addFunc("quality", [](FogSystem* self) {
71 return std::string(fogQualityName(self->quality()));
72 });
73 system.addFunc("setQuality", [](FogSystem* self, const std::string& quality) {
74 throwIfFailed(self->setQuality(fogQualityFromName(quality)), "FogSystem.setQuality");
75 });
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) {
80 FogWorldBounds bounds;
81 bounds.minimum = {minX, minY, minZ};
82 bounds.maximum = {maxX, maxY, maxZ};
83 throwIfFailed(self->configureDomain(w, h, d, bounds), "FogSystem.configureDomain");
84 });
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");
89 });
90 system.addFunc("setMainWind", [](FogSystem* self, float x, float y, float z) {
91 throwIfFailed(self->wind().setMainWind(glm::vec3(x, y, z)), "FogSystem.setMainWind");
92 });
93 system.addFunc("setCurlStrength", [](FogSystem* self, float strength) {
94 throwIfFailed(self->wind().setCurlStrength(strength), "FogSystem.setCurlStrength");
95 });
96 system.addFunc("setCurlTimeScale", [](FogSystem* self, float scale) {
97 throwIfFailed(self->wind().setCurlTimeScale(scale), "FogSystem.setCurlTimeScale");
98 });
99 system.addFunc("setWindResponseRate", [](FogSystem* self, float rate) {
100 throwIfFailed(self->wind().setResponseRate(rate), "FogSystem.setWindResponseRate");
101 });
102 system.addFunc("setSphereInteractor",
103 [](FogSystem* self, float x, float y, float z, float radius, float vx, float vy,
104 float vz) {
105 FogSolidProxy proxy;
106 proxy.shape = FogProxyShape::Sphere;
107 proxy.position = {x, y, z};
108 proxy.extents = {radius, radius, radius};
109 proxy.velocity = {vx, vy, vz};
110 proxy.drag = 0.4f;
111 proxy.wakeStrength = 1.5f;
112 throwIfFailed(self->interactor().setProxies({proxy}),
113 "FogSystem.setSphereInteractor");
114 });
115 system.addFunc("clearInteractors", [](FogSystem* self) {
116 throwIfFailed(self->interactor().setProxies({}), "FogSystem.clearInteractors");
117 });
118 system.addFunc("stepSimulation", [](FogSystem* self, float dt) {
119 return throwOrTake(self->stepSimulation(dt), "FogSystem.stepSimulation").cfl;
120 });
121 // Not `setProfile`: Binding Contracts match that name to ClimbingRuntime
122 // (last arg int), which rejects Fog's trailing anisotropy float (EVE2002).
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");
129 });
130 system.addFunc("injectToVolumetric", [](FogSystem* self, Volumetric* volumetric) {
131 return throwOrTake(self->injectToVolumetric(volumetric), "FogSystem.injectToVolumetric");
132 });
133 system.addFunc("syncToVolumetric",
134 [](FogSystem* self, Volumetric* volumetric, float lx, float ly, float lz, float r,
135 float g, float b, float intensity) {
136 return throwOrTake(
137 self->syncToVolumetric(volumetric, glm::vec3(lx, ly, lz),
138 glm::vec3(r, g, b), intensity),
139 "FogSystem.syncToVolumetric");
140 });
141}
142
143} // namespace eve::graphics::fog
float w
Definition AnimClip.cpp:738
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
HSQOBJECT cls
Definition ECS.cpp:21
tensor::Graph g
Definition GpuGraph.cpp:7
std::uint32_t ab
double r
HexVec3 up
int h
std::uint32_t height
std::array< float, 3 > scale
std::string name
MeleePoint3 b
Definition MeleeHit.cpp:41
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:26
float radius
float d
int created
Vec extinction
float vz
float vy
float vx
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Orchestrates density, MAC transport, optics, froxel mapping, and art.
Definition FogSystem.h:46
Optional graphics satellite for realtime fog (MAC + raymarch + froxel + analytic lights).
Definition RealtimeFog.h:21
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.
Definition FogTypes.h:13
@ Enhanced
Temporal + spatial reconstruction, Beer cache.
FogQuality fogQualityFromName(std::string_view name) noexcept
Parse a quality spelling; unknown values yield Enhanced.
Definition FogTypes.h:30
constexpr std::string_view fogQualityName(FogQuality quality) noexcept
Stable spelling of a quality preset.
Definition FogTypes.h:20
glm::vec4 bounds