载入中...
搜索中...
未找到
ContinuousArt.cpp
浏览该文件的文档.
2#include <algorithm>
3#include <cmath>
4#include <glm/vec3.hpp>
5#include "common/Diagnostic.h"
7
8// ContinuousArt.cpp
9namespace eve::graphics::fog {
10
12 auto ok01 = [](float v) { return std::isfinite(v) && v >= 0.f && v <= 2.f; };
13 if (!std::isfinite(params.colorTint.x) || !std::isfinite(params.colorTint.y) ||
14 !std::isfinite(params.colorTint.z) || params.colorTint.x < 0.f || params.colorTint.y < 0.f ||
15 params.colorTint.z < 0.f) {
17 DiagnosticCode::InvalidArgument, "colorTint must be finite and >= 0", "colorTint", {}, "graphics.fog"));
18 }
19 if (!ok01(params.edgeBoost) || !ok01(params.silhouetteSoftness) || !ok01(params.internalGlow) ||
20 !ok01(params.silverDust)) {
22 DiagnosticCode::InvalidArgument, "art scalars must be finite and in [0,2]", "art", {}, "graphics.fog"));
23 }
24 params_ = params;
25 return Result<void>::success();
26}
27
29 float neighborOpacity) const noexcept {
31 const float opacity = std::clamp(1.f - physical.transmittance, 0.f, 1.f);
32 out.opacity = opacity;
33 out.color = physical.inScatter * params_.colorTint;
34
35 const float depthCue = 1.f - std::exp(-std::max(viewZ, 0.f) * 0.05f);
36 out.edgeMask = std::clamp(std::fabs(opacity - neighborOpacity) * (0.5f + params_.edgeBoost), 0.f, 1.f);
37 out.edgeMask *= std::clamp(1.f - params_.silhouetteSoftness * depthCue, 0.f, 1.f);
38
39 const float glow = params_.internalGlow * opacity * (0.35f + 0.65f * depthCue);
40 out.color += glm::vec3(glow) * params_.colorTint;
41
42 // Silver dust: cool highlight on bright in-scatter without touching optics.
43 const float luma = 0.2126f * physical.inScatter.r + 0.7152f * physical.inScatter.g + 0.0722f * physical.inScatter.b;
44 out.dustHighlight = std::clamp(params_.silverDust * luma, 0.f, 1.f);
45 out.color += glm::vec3(0.85f, 0.9f, 1.f) * out.dustHighlight * 0.15f;
46 return out;
47}
48
49} // namespace eve::graphics::fog
50
51// SceneWind.cpp
52namespace eve::graphics::fog {
53namespace {
54
55[[nodiscard]] float approach(float current, float target, float maxDelta) noexcept {
56 const float delta = target - current;
57 if (std::fabs(delta) <= maxDelta) return target;
58 return current + std::copysign(maxDelta, delta);
59}
60
61[[nodiscard]] glm::vec3 approach3(const glm::vec3& current, const glm::vec3& target, float maxDelta) noexcept {
62 return {approach(current.x, target.x, maxDelta), approach(current.y, target.y, maxDelta),
63 approach(current.z, target.z, maxDelta)};
64}
65
66} // namespace
67
68Result<void> SceneWind::setMainWind(const glm::vec3& metersPerSecond) {
69 if (!std::isfinite(metersPerSecond.x) || !std::isfinite(metersPerSecond.y) || !std::isfinite(metersPerSecond.z)) {
71 "mainWind", {}, "graphics.fog"));
72 }
73 targetMain_ = metersPerSecond;
74 return Result<void>::success();
75}
76
78 if (!std::isfinite(metersPerSecond) || metersPerSecond < 0.f) {
80 "curl strength must be finite and >= 0", "curlStrength", {},
81 "graphics.fog"));
82 }
83 targetCurl_ = metersPerSecond;
84 return Result<void>::success();
85}
86
88 if (!std::isfinite(frequency) || frequency <= 0.f) {
90 "curl frequency must be finite and > 0", "curlFrequency", {},
91 "graphics.fog"));
92 }
93 curlFrequency_ = frequency;
94 return Result<void>::success();
95}
96
98 if (!std::isfinite(scale) || scale < 0.f) {
100 "curl time scale must be finite and >= 0", "curlTimeScale", {},
101 "graphics.fog"));
102 }
103 curlTimeScale_ = scale;
104 return Result<void>::success();
105}
106
107Result<void> SceneWind::setResponseRate(float metersPerSecondPerSecond) {
108 if (!std::isfinite(metersPerSecondPerSecond) || metersPerSecondPerSecond <= 0.f) {
110 "response rate must be finite and > 0", "responseRate", {},
111 "graphics.fog"));
112 }
113 responseRate_ = metersPerSecondPerSecond;
114 return Result<void>::success();
115}
116
118 if (!std::isfinite(dt) || dt < 0.f) {
120 Diagnostic::error(DiagnosticCode::InvalidArgument, "dt must be finite and >= 0", "dt", {}, "graphics.fog"));
121 }
122 const float maxDelta = responseRate_ * dt;
123 currentMain_ = approach3(currentMain_, targetMain_, maxDelta);
124 currentCurl_ = approach(currentCurl_, targetCurl_, maxDelta);
125 return Result<void>::success();
126}
127
128glm::vec3 SceneWind::sample(const glm::vec3& world, float timeSeconds) const noexcept {
129 const float t = timeSeconds * curlTimeScale_;
130 const float f = curlFrequency_;
131 // Analytic curl of a smooth potential → locally swirling, nearly div-free.
132 const float sx = std::sin(f * world.y + 0.7f * t);
133 const float sy = std::sin(f * world.z + 1.1f * t);
134 const float sz = std::sin(f * world.x + 0.5f * t);
135 const float cx = std::cos(f * world.z + 0.9f * t);
136 const float cy = std::cos(f * world.x + 0.3f * t);
137 const float cz = std::cos(f * world.y + 1.3f * t);
138 const glm::vec3 curl(currentCurl_ * (sy - cz), currentCurl_ * (sz - cx), currentCurl_ * (sx - cy));
139 return currentMain_ + curl;
140}
141
142} // namespace eve::graphics::fog
LogicalId target
float cx
Definition CardTypes.cpp:36
float cy
Definition CardTypes.cpp:37
Stable, structured diagnostics shared by engine modules.
float v
std::array< float, 3 > scale
std::vector< RecipeParam > params
double dt
float f
float t
ScriptStructure out
double current
float opacity
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
const ContinuousArtParams & params() const noexcept
Params.
ContinuousArtOutput stylize(const FogRayResult &physical, float viewZ, float neighborOpacity=0.f) const noexcept
Stylize a physical fog integration result.
Result< void > setParams(const ContinuousArtParams &params)
Replace art parameters after validation.
Result< void > setCurlStrength(float metersPerSecond)
Target curl amplitude in m/s.
Result< void > setMainWind(const glm::vec3 &metersPerSecond)
Target main wind in m/s (world space).
Result< void > tick(float dt)
Advance the limited-response filters by dt seconds.
Result< void > setResponseRate(float metersPerSecondPerSecond)
Max response rate for wind changes (m/s per second).
glm::vec3 sample(const glm::vec3 &world, float timeSeconds) const noexcept
Sample combined wind at a world position and simulation time. Curl is divergence-free on average and ...
Result< void > setCurlTimeScale(float scale)
Time scale for curl animation (dimensionless, >= 0).
Result< void > setCurlFrequency(float frequency)
Curl field spatial frequency (1/m).
Stylized fog presentation derived from a physical FogRayResult.
Definition FogTypes.h:169
Continuous-art stylization that never mutates density or optics.
Definition FogTypes.h:160
Optical result of integrating one view ray through fog.
Definition FogTypes.h:122