载入中...
搜索中...
未找到
VolumeDensityGraph.cpp
浏览该文件的文档.
2
3#include <algorithm>
4#include <cmath>
5
6#include <glm/common.hpp>
7#include <glm/geometric.hpp>
8
9namespace eve::graphics {
10namespace {
11
12float hash3(const glm::ivec3 &p, std::uint32_t seed) {
13 std::uint32_t h = seed ^ (std::uint32_t(p.x) * 0x8da6b343u) ^
14 (std::uint32_t(p.y) * 0xd8163841u) ^ (std::uint32_t(p.z) * 0xcb1ab31fu);
15 h ^= h >> 16;
16 h *= 0x7feb352du;
17 h ^= h >> 15;
18 return float(h & 0x00ffffffu) / float(0x01000000u);
19}
20
21} // namespace
22
24 nodes_.clear();
25 output_ = -1;
26}
27
28int VolumeDensityGraph::addNode(Op op, int inputA, int inputB, const glm::vec4 &params) {
29 const int next = int(nodes_.size());
30 Node node;
31 node.op = op;
32 node.inputA = inputA >= 0 && inputA < next ? inputA : -1;
33 node.inputB = inputB >= 0 && inputB < next ? inputB : -1;
34 node.params = params;
35 nodes_.push_back(node);
36 output_ = next;
37 return next;
38}
39
41 output_ = nodeIndex >= 0 && nodeIndex < int(nodes_.size()) ? nodeIndex
42 : int(nodes_.size()) - 1;
43}
44
45float VolumeDensityGraph::valueNoise(const glm::vec3 &p, std::uint32_t seed) {
46 const glm::ivec3 cell = glm::ivec3(glm::floor(p));
47 const glm::vec3 f = glm::fract(p);
48 const glm::vec3 u = f * f * (3.f - 2.f * f);
49 float corners[2][2][2];
50 for (int z = 0; z < 2; ++z)
51 for (int y = 0; y < 2; ++y)
52 for (int x = 0; x < 2; ++x)
53 corners[z][y][x] = hash3(cell + glm::ivec3(x, y, z), seed);
54 const float z0 = glm::mix(glm::mix(corners[0][0][0], corners[0][0][1], u.x),
55 glm::mix(corners[0][1][0], corners[0][1][1], u.x), u.y);
56 const float z1 = glm::mix(glm::mix(corners[1][0][0], corners[1][0][1], u.x),
57 glm::mix(corners[1][1][0], corners[1][1][1], u.x), u.y);
58 return glm::mix(z0, z1, u.z);
59}
60
61float VolumeDensityGraph::evaluate(const glm::vec3 &worldPosition, float time) const {
62 if (nodes_.empty()) return 0.f;
63 std::vector<float> values(nodes_.size(), 0.f);
64 for (std::size_t i = 0; i < nodes_.size(); ++i) {
65 const Node &n = nodes_[i];
66 const float a = n.inputA >= 0 ? values[std::size_t(n.inputA)] : 0.f;
67 const float b = n.inputB >= 0 ? values[std::size_t(n.inputB)] : 0.f;
68 switch (n.op) {
69 case Op::constant: values[i] = n.params.x; break;
70 case Op::height:
71 values[i] = std::exp(-std::max(n.params.y, 0.f) *
72 std::max(worldPosition.y - n.params.x, 0.f));
73 break;
74 case Op::sphere: {
75 const float radius = std::max(n.params.w, 1e-4f);
76 values[i] = std::clamp(1.f - glm::length(worldPosition - glm::vec3(n.params)) /
77 radius, 0.f, 1.f);
78 break;
79 }
80 case Op::box: {
81 const glm::vec3 q = glm::abs(worldPosition - glm::vec3(n.params));
82 const float extent = std::max(n.params.w, 1e-4f);
83 values[i] = std::clamp(1.f - std::max(std::max(q.x, q.y), q.z) / extent,
84 0.f, 1.f);
85 break;
86 }
87 case Op::noise: {
88 const float scale = std::max(std::fabs(n.params.x), 1e-4f);
89 const glm::vec3 wind(n.params.y, 0.f, n.params.z);
90 values[i] = valueNoise((worldPosition + wind * time) / scale,
91 std::uint32_t(std::max(n.params.w, 0.f)));
92 break;
93 }
94 case Op::add: values[i] = a + b; break;
95 case Op::multiply: values[i] = a * b; break;
96 case Op::subtract: values[i] = a - b; break;
97 case Op::clamp: values[i] = std::clamp(a, n.params.x, n.params.y); break;
98 }
99 }
100 const int selected = output_ >= 0 ? output_ : int(nodes_.size()) - 1;
101 return values[std::size_t(selected)];
102}
103
104} // namespace eve::graphics
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
glm::vec4 p[6]
std::map< std::string, Var > values
float u
Definition Grass.cpp:233
glm::vec3 n
Definition Grass.cpp:63
std::array< double, 10 > q
int h
std::array< float, 3 > scale
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
float f
float radius
std::uint32_t seed
Definition PointSet.cpp:807
const RoadNode * node
Cell cell
void clear()
Remove every node and reset the output.
float evaluate(const glm::vec3 &worldPosition, float time=0.f) const
Evaluate signed density at a world position and time.
void setOutput(int nodeIndex)
Select the node returned by evaluate; invalid indices select the last node.
int addNode(Op op, int inputA=-1, int inputB=-1, const glm::vec4 &params=glm::vec4(0.f))
Append a node and return its stable index. Inputs must precede the node.
std::vector< ParamSpec > params
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25