载入中...
搜索中...
未找到
AtmosphereClipmap.cpp
浏览该文件的文档.
2
3#include <algorithm>
4#include <cmath>
5
6#include <glm/common.hpp>
7
8namespace eve::graphics {
9
10void AtmosphereClipmap::configure(int levelCount, int resolution, float firstExtent) {
11 const int count = std::max(levelCount, 1);
12 const int res = std::max(resolution, 2);
13 const float baseExtent = std::max(firstExtent, 1e-3f);
14 levels_.resize(std::size_t(count));
15 for (int i = 0; i < count; ++i) {
16 AtmosphereClipmapLevel &level = levels_[std::size_t(i)];
17 level.extent = baseExtent * std::pow(2.f, float(i));
18 level.voxelSize = (level.extent * 2.f) / float(res);
19 level.center = glm::vec3(0.f);
20 level.volume.resize(res, res, res);
21 level.volume.setDepthRange(level.voxelSize, level.extent * 2.f);
22 }
23}
24
25void AtmosphereClipmap::updateCenter(const glm::vec3 &cameraPosition) {
26 for (AtmosphereClipmapLevel &level : levels_) {
27 level.center = glm::floor(cameraPosition / level.voxelSize) * level.voxelSize;
28 }
29}
30
32 return levels_[std::size_t(std::clamp(level, 0, int(levels_.size()) - 1))];
33}
34
36 return levels_[std::size_t(std::clamp(level, 0, int(levels_.size()) - 1))];
37}
38
39int AtmosphereClipmap::levelForPosition(const glm::vec3 &worldPosition) const {
40 for (std::size_t i = 0; i < levels_.size(); ++i) {
41 const AtmosphereClipmapLevel &level = levels_[i];
42 const glm::vec3 d = glm::abs(worldPosition - level.center);
43 if (d.x <= level.extent && d.y <= level.extent && d.z <= level.extent) return int(i);
44 }
45 return -1;
46}
47
48FogFroxel AtmosphereClipmap::sample(const glm::vec3 &worldPosition) const {
49 const int index = levelForPosition(worldPosition);
50 if (index < 0) return {};
51 const AtmosphereClipmapLevel &level = levels_[std::size_t(index)];
52 const glm::vec3 minCorner = level.center - glm::vec3(level.extent);
53 const glm::vec3 uvw = (worldPosition - minCorner) / (level.extent * 2.f);
54 return level.volume.sampleMedia(uvw.x, uvw.y, uvw.z);
55}
56
57} // namespace eve::graphics
int level
float d
std::uint32_t count
uint32_t index
void configure(int levelCount, int resolution, float firstExtent)
Allocate nested cubic levels and center them at the origin.
FogFroxel sample(const glm::vec3 &worldPosition) const
Sample raw media from the finest containing level.
void updateCenter(const glm::vec3 &cameraPosition)
Snap all levels around a new camera position.
int levelForPosition(const glm::vec3 &worldPosition) const
Select the finest level containing a world position, or -1.
AtmosphereClipmapLevel & getLevel(int level)
Returns the level.
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
One camera-centered, world-space atmosphere clipmap level.
Participating-media coefficients stored in one froxel.