载入中...
搜索中...
未找到
LodSelection.cpp
浏览该文件的文档.
2
3#include <algorithm>
4#include <cmath>
5
6namespace eve::virtualgeometry {
7
8int selectClusters(const VirtualGeometryAsset &asset, float dist, float projScale, float errorPx,
9 std::vector<std::uint32_t> &outSelected) {
10 outSelected.clear();
11 const std::vector<VgCluster> &clusters = asset.clusters;
12 if (clusters.empty() || dist <= 0.f) return 0;
13
14 const float d = std::max(dist, 1e-4f);
15 for (std::size_t cid = 0; cid < clusters.size(); ++cid) {
16 const VgCluster &c = clusters[cid];
17 const float screenC = c.errorR * projScale / d;
18 const bool isLeaf = c.childCount == 0;
19
20 // Parent's screen error; +inf for roots so the root can be selected.
21 float screenP = 1e30f;
22 if (c.parent != 0xFFFFFFFFu && c.parent < clusters.size())
23 screenP = clusters[c.parent].errorR * projScale / d;
24
25 const bool accept = (screenC <= errorPx || isLeaf) && (screenP > errorPx);
26 if (accept) outSelected.push_back(static_cast<std::uint32_t>(cid));
27 }
28 return static_cast<int>(outSelected.size());
29}
30
31void lodHistogram(const VirtualGeometryAsset &asset, const std::vector<std::uint32_t> &selected,
32 std::vector<int> &perLevelCount) {
33 int maxLod = 0;
34 for (const auto &c : asset.clusters) maxLod = std::max(maxLod, static_cast<int>(c.lodLevel));
35 perLevelCount.assign(static_cast<std::size_t>(maxLod + 1), 0);
36 for (std::uint32_t cid : selected)
37 if (cid < asset.clusters.size())
38 ++perLevelCount[asset.clusters[cid].lodLevel];
39}
40
41} // namespace eve::virtualgeometry
uint32_t c
int d
int selectClusters(const VirtualGeometryAsset &asset, float dist, float projScale, float errorPx, std::vector< std::uint32_t > &outSelected)
CPU reference implementation of the GPU cluster-DAG LOD selection (mirrors shaders/vg_cull....
void lodHistogram(const VirtualGeometryAsset &asset, const std::vector< std::uint32_t > &selected, std::vector< int > &perLevelCount)
Per-LOD-level counts of the selected clusters (size = maxLod+1).
CPU-side processed cluster (before packing into VgGpuCluster).
Fully processed virtual-geometry asset (CPU representation). Produced by Builder from a Mesh; uploade...