7#include <glm/common.hpp>
8#include <glm/geometric.hpp>
14float hashNoise(
int x,
int y,
int z,
int seed) {
15 uint32_t
value = uint32_t(
x) * 0x8da6b343u ^ uint32_t(
y) * 0xd8163841u ^
16 uint32_t(
z) * 0xcb1ab31fu ^ uint32_t(
seed) * 0x165667b1u;
20 return float(
value & 0x00ffffffu) / float(0x01000000u);
23float smoothNoise(
const glm::vec3 &
p,
int seed) {
24 const glm::ivec3
cell = glm::ivec3(glm::floor(
p));
25 const glm::vec3 fraction = glm::fract(
p);
26 const glm::vec3
blend = fraction * fraction * (glm::vec3(3.f) - 2.f * fraction);
27 float corners[2][2][2];
28 for (
int z = 0;
z < 2; ++
z)
29 for (
int y = 0;
y < 2; ++
y)
30 for (
int x = 0;
x < 2; ++
x)
32 const float z0 = glm::mix(glm::mix(corners[0][0][0], corners[1][0][0],
blend.x),
33 glm::mix(corners[0][1][0], corners[1][1][0],
blend.x),
blend.y);
34 const float z1 = glm::mix(glm::mix(corners[0][0][1], corners[1][0][1],
blend.x),
35 glm::mix(corners[0][1][1], corners[1][1][1],
blend.x),
blend.y);
36 return glm::mix(z0, z1,
blend.z);
42 if (
shape ==
"sphere")
44 else if (
shape ==
"cylinder")
57 size_ = glm::max(glm::vec3(
x,
y,
z), glm::vec3(1e-3f));
61 albedo_ = glm::clamp(glm::vec3(
r,
g,
b), glm::vec3(0.f), glm::vec3(1.f));
65 emissive_ = glm::max(glm::vec3(
r,
g,
b), glm::vec3(0.f));
69 anisotropy_ = std::clamp(anisotropy, -0.99f, 0.99f);
73 edgeFalloff_ = std::clamp(falloff, 0.f, 1.f);
77 noiseAmount_ = std::clamp(amount, 0.f, 1.f);
78 noiseScale_ = std::max(
scale, 1e-3f);
83 const glm::vec3
p = (worldPosition - position_) / (size_ * 0.5f);
88 radius = std::max(glm::length(glm::vec2(
p.x,
p.z)), std::fabs(
p.y));
90 radius = std::max(std::max(std::fabs(
p.x), std::fabs(
p.y)), std::fabs(
p.z));
92 if (
radius >= 1.f)
return 0.f;
93 const float inner = 1.f - edgeFalloff_;
94 const float coverage = edgeFalloff_ <= 1e-6f ||
radius <= inner
96 : 1.f - glm::smoothstep(inner, 1.f,
radius);
97 const float noise = smoothNoise(worldPosition * noiseScale_, noiseSeed_);
98 const float densityVariation = glm::mix(1.f, 0.18f + 1.32f * noise, noiseAmount_);
99 return extinction_ * coverage * densityVariation;
std::array< float, 3 > scale
float sampleExtinction(const glm::vec3 &worldPosition) const
Normalized analytic density at a world position, including signed extinction.
void setAnisotropy(float anisotropy)
HG anisotropy in [-0.99,0.99].
std::string getShapeName() const
void setShape(const std::string &shape)
Set shape using "sphere", "box" or "cylinder"; unknown selects box.
void setAlbedo(float r, float g, float b)
Single-scattering albedo, clamped to [0,1].
void setEmissive(float r, float g, float b)
Unlit radiance emitted per unit density.
void setEdgeFalloff(float falloff)
Fraction of normalized radius used for a smooth edge, in [0,1].
void setSize(float x, float y, float z)
Set full world-space dimensions; values are clamped positive.
void setNoise(float amount, float scale, int seed)
Configure deterministic world-space density variation.
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...