载入中...
搜索中...
未找到
TreeWind.cpp
浏览该文件的文档.
1#include "graphics/TreeWind.h"
2#include <array>
3#include <cmath>
4#include <string>
5#include "common/Assert.h"
6#include "graphics/Shader.h"
8
9namespace eve::graphics {
10namespace {
11} // namespace
12
14 const VegetationWindProfile& vegetation, const TreeWindProfile& tree,
15 double seconds) {
16 if (!std::isfinite(tree.widthHeight.x) || tree.widthHeight.x <= 0 ||
17 !std::isfinite(tree.widthHeight.y) || tree.widthHeight.y <= 0 ||
18 !std::isfinite(tree.bendFactor) || tree.bendFactor < 0)
20 "tree.wind: positive finite dimensions and bend required"));
21 auto scaled = vegetation;
22 scaled.flex *= tree.bendFactor;
23 auto packet = packVegetationWind(state, scaled, seconds);
24 if (!packet.ok()) return Result<void>::failure(packet.status());
25 static const std::array<std::string, 6> names = {"windGlobals", "windPhaseDistance", "windFlex",
26 "windFrequency", "windSineTime", "treeDimensions"};
27 constexpr std::array<int, 6> offsets{0, 4, 6, 9, 12, 14};
28 constexpr std::array<int, 6> sizes{4, 2, 3, 3, 2, 2};
29 for (size_t i = 0; i < names.size(); ++i)
30 if (shader.usedFloats() != 16 || !shader.hasUniform(names[i]) ||
31 shader.getUniformIndex(names[i]) != offsets[i] || shader.getUniformFloatCount(names[i]) != sizes[i])
33 "tree.wind: canonical 16-float shader layout required"));
34 std::array<float, 16> values{};
35 std::copy(packet.value().begin(), packet.value().end(), values.begin());
36 values[14] = tree.widthHeight.x;
37 values[15] = tree.widthHeight.y;
38 for (size_t i = 0; i < names.size(); ++i) {
39 const auto bytes = size_t(sizes[i]) * sizeof(float);
40 const int written = shader.sendToVar(names[i], values.data() + offsets[i], bytes);
41 EV_ASSERT(written == int(bytes));
42 }
43 return Result<void>::success();
44}
45} // namespace eve::graphics
EVEngine assertion entry point, backed by zeroerr.
#define EV_ASSERT(cond,...)
Assert an internal engine invariant (state that must always hold).
Definition Assert.h:37
std::map< std::string, Var > values
std::uint64_t bytes
Shader * shader
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Custom GPU program.
Definition Shader.h:39
bool hasUniform(const std::string &name) const
Definition Shader.cpp:59
int usedFloats() const
Definition Shader.h:115
int getUniformIndex(const std::string &name) const
Definition Shader.cpp:61
int getUniformFloatCount(const std::string &name) const
Definition Shader.cpp:67
int sendToVar(const std::string &name, const void *data, size_t size)
Low-level blob write into a declared uniform (size must match declaration).
Definition Shader.cpp:73
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
Result< std::array< float, 14 > > packVegetationWind(const VegetationWindState &state, const VegetationWindProfile &profile, double seconds)
Pack a wind snapshot into the grass shader's final 14 float slots.
Result< void > applyTreeWind(Shader &shader, const VegetationWindState &state, const VegetationWindProfile &vegetation, const TreeWindProfile &tree, double seconds)
Atomically publish one validated tree wind snapshot to CPU-side shader parameters.
Definition TreeWind.cpp:13
Caller-owned tree prototype wind geometry matching Pcg ResourceProtoTree inputs.
Definition TreeWind.h:12
glm::vec2 widthHeight
Object-space crown width and source prototype height; both must be positive.
Definition TreeWind.h:14
float bendFactor
Pcg tree prototype bend factor. Zero disables deformation.
Definition TreeWind.h:16
Caller-owned material wind controls; billboard suppresses source branch and leaf motion....
Caller-owned wind globals; no hidden clock, singleton or retained scene link.