载入中...
搜索中...
未找到
ParallaxMap.h
浏览该文件的文档.
1#pragma once
2
3#include <algorithm>
4#include <cmath>
5
6namespace eve::graphics {
7
16 float scale = 0.f; // 0 = off
17 float minLayers = 8.f; // adaptive POM min steps
18 float maxLayers = 32.f; // adaptive POM max steps
19 bool silhouette = false; // SilPOM: discard when displaced UV leaves mesh UV bounds
20};
21
23inline void parallaxOffsetUV(float u, float v, float height01, float viewTSx, float viewTSy,
24 float viewTSz, float scale, float &ou, float &ov) {
25 if (scale < 1e-5f) {
26 ou = u;
27 ov = v;
28 return;
29 }
30 const float depth = 1.f - height01;
31 const float vz = std::max(std::fabs(viewTSz), 0.08f);
32 ou = u - (viewTSx / vz) * depth * scale;
33 ov = v - (viewTSy / vz) * depth * scale;
34}
35
46inline float silPomCoverage(float displacedU, float displacedV, float padding = 0.f) {
47 // padding expands the keep region to [-pad, 1+pad].
48 const float pad = std::max(0.f, padding);
49 return (displacedU >= -pad && displacedV >= -pad && displacedU <= 1.f + pad &&
50 displacedV <= 1.f + pad)
51 ? 1.f
52 : 0.f;
53}
54
62inline float silPomCoverageSoft(float displacedU, float displacedV, float feather) {
63 const float f = std::max(feather, 1e-4f);
64 auto edge = [f](float t) {
65 if (t <= 0.f) return 0.f;
66 if (t >= f) return 1.f;
67 const float x = t / f;
68 return x * x * (3.f - 2.f * x); // smoothstep
69 };
70 const float cx = std::min(edge(displacedU), edge(1.f - displacedU));
71 const float cy = std::min(edge(displacedV), edge(1.f - displacedV));
72 return cx * cy;
73}
74
83inline float silPomHorizonTrim(float height01, float ndotv, float strength,
84 float bias = 0.02f) {
85 const float t = std::clamp(1.f - std::fabs(ndotv) / 0.35f, 0.f, 1.f);
86 const float threshold = std::clamp(std::pow(t, 1.5f) * strength, 0.f, 1.f);
87 return (height01 - bias >= threshold) ? 1.f : 0.f;
88}
89
104inline void ssdmScreenOffset(float height01, float viewNdcX, float viewNdcY, float scale,
105 float &outX, float &outY) {
106 if (scale < 1e-5f) {
107 outX = 0.f;
108 outY = 0.f;
109 return;
110 }
111 // Raised texels push toward the viewer in screen space (opposite to POM's UV dig).
112 const float h = std::clamp(height01, 0.f, 1.f);
113 const float len = std::sqrt(viewNdcX * viewNdcX + viewNdcY * viewNdcY);
114 if (len < 1e-5f) {
115 outX = 0.f;
116 outY = 0.f;
117 return;
118 }
119 outX = (viewNdcX / len) * h * scale;
120 outY = (viewNdcY / len) * h * scale;
121}
122
128inline float ssdmCoverage(float baseU, float baseV, float offsetU, float offsetV,
129 float padding = 0.f) {
131 return silPomCoverage(baseU + offsetU, baseV + offsetV, padding);
132}
133
136 if (p.scale < 0.f) p.scale = 0.f;
137 if (p.scale > 0.25f) p.scale = 0.25f;
138 if (p.minLayers < 1.f) p.minLayers = 1.f;
139 if (p.maxLayers < p.minLayers) p.maxLayers = p.minLayers;
140 if (p.maxLayers > 64.f) p.maxLayers = 64.f;
141}
142
143} // namespace eve::graphics
float x
Definition AnimClip.cpp:738
float cx
Definition CardTypes.cpp:33
float cy
Definition CardTypes.cpp:34
glm::vec4 p[6]
float u
Definition Grass.cpp:233
float v
int h
std::array< float, 3 > scale
float f
float t
const RoadEdge * edge
float bias
std::uint32_t depth
float vz
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
void parallaxOffsetUV(float u, float v, float height01, float viewTSx, float viewTSy, float viewTSz, float scale, float &ou, float &ov)
Single-sample offset mapping (cheap approximation of the first POM step).
Definition ParallaxMap.h:23
float silPomCoverage(float displacedU, float displacedV, float padding=0.f)
Silhouette POM coverage in raw mesh UV space [0,1].
Definition ParallaxMap.h:46
float ssdmCoverage(float baseU, float baseV, float offsetU, float offsetV, float padding=0.f)
Whether an SSDM-displaced screen sample still covers the surface footprint.
void ssdmScreenOffset(float height01, float viewNdcX, float viewNdcY, float scale, float &outX, float &outY)
Screen-space displacement offset (educational SSDM CPU reference).
float silPomHorizonTrim(float height01, float ndotv, float strength, float bias=0.02f)
View-dependent horizon trim (SPOM-style) for grazing SilPOM limbs.
Definition ParallaxMap.h:83
float silPomCoverageSoft(float displacedU, float displacedV, float feather)
Soft chart coverage in [0,1] — feathers near the UV border (full SilPOM).
Definition ParallaxMap.h:62
void clampParallaxParams(ParallaxParams &p)
Clamp parallax params.
CPU reference for simple offset parallax (matches the scale / height convention of parallax_map....
Definition ParallaxMap.h:15
uint32_t pad[2]