hilo3d 2.0.0-alpha.2 → 2.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +371 -13
- package/README.md +179 -271
- package/README_ZH.md +173 -250
- package/dist/Hilo3d.d.ts +3436 -911
- package/dist/Hilo3d.d.ts.map +1 -1
- package/dist/Hilo3d.js +47300 -24219
- package/dist/Hilo3d.js.map +1 -1
- package/dist/{web_naga-D4FbPGzE.js → web_naga-B71-0Gwu.js} +2 -2
- package/dist/{web_naga-D4FbPGzE.js.map → web_naga-B71-0Gwu.js.map} +1 -1
- package/package.json +7 -4
package/README_ZH.md
CHANGED
|
@@ -1,24 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="./website/assets/hilo3d-logo.png" width="320" alt="Hilo3D" />
|
|
3
|
+
|
|
4
|
+
<p><strong>面向生产级 2D 与 3D 体验的现代 Web 图形引擎。</strong></p>
|
|
5
|
+
|
|
6
|
+
<p>
|
|
7
|
+
可移植 RHI、经过验证的 Render Graph 与可脚本化渲染管线<br />
|
|
8
|
+
共同驱动 WebGPU 和 WebGL 2 的统一渲染器。
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p>
|
|
12
|
+
<a href="https://hilo3d.js.org/"><strong>官网</strong></a> ·
|
|
13
|
+
<a href="https://hilo3d.js.org/examples/list.html">示例</a> ·
|
|
14
|
+
<a href="https://hilo3d.js.org/docs/">文档</a> ·
|
|
15
|
+
<a href="https://hilo3d.js.org/docs/modules/Hilo3d.html">API</a> ·
|
|
16
|
+
<a href="./README.md">English</a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
<p>
|
|
20
|
+
<a href="https://www.npmjs.com/package/hilo3d"><img src="https://img.shields.io/npm/v/hilo3d.svg?style=flat-square" alt="npm 版本" /></a>
|
|
21
|
+
<a href="https://github.com/hiloteam/Hilo3d/actions/workflows/npm_test.yml"><img src="https://img.shields.io/github/actions/workflow/status/hiloteam/Hilo3d/npm_test.yml?style=flat-square" alt="CI 状态" /></a>
|
|
22
|
+
<a href="https://github.com/hiloteam/Hilo3d/blob/dev/LICENSE"><img src="https://img.shields.io/npm/l/hilo3d.svg?style=flat-square" alt="MIT 许可证" /></a>
|
|
23
|
+
</p>
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
> Hilo3D 2.0 目前处于 alpha 阶段。现有项目升级前应先查看
|
|
27
|
+
> [破坏性变更](./CHANGELOG.md#breaking-changes)。
|
|
28
|
+
|
|
29
|
+
## 为什么选择 Hilo3D
|
|
30
|
+
|
|
31
|
+
Hilo3D 在同一引擎中兼顾高层场景创作和底层 GPU 控制。应用始终使用同一套场景、材质、渲染目标与 shader 契约,渲染器则选择原生 WebGPU 路径或生产级 WebGL
|
|
32
|
+
2 兼容路径。
|
|
33
|
+
|
|
34
|
+
- **一个渲染器,两个后端** — `auto` 优先选择兼容的 WebGPU;WebGPU 不可用时使用 WebGL
|
|
35
|
+
2。显式请求的后端绝不会静默切换。
|
|
36
|
+
- **现代材质与显示输出** — 支持 glTF
|
|
37
|
+
2.0、分层 PBR、HDR 光照、Bloom、自动曝光、filmic 色调映射、transmission、volume、iridescence、clearcoat 与 anisotropy。
|
|
38
|
+
- **2D 与 3D 协同**
|
|
39
|
+
— 统一提供场景图、网格、动画、相机、灯光、阴影、Sprite、文本、批处理、拾取和分层多相机合成。
|
|
40
|
+
- **GPU 驱动渲染** — 两个后端均支持实例化与多 Pass 渲染;WebGPU high-end profile 进一步提供 GPU
|
|
41
|
+
Scene 剔除/LOD、Hi-Z、间接绘制 bucket 与 Clustered Forward+。
|
|
42
|
+
- **稳定的高端光照**
|
|
43
|
+
— 提供 TAA/TAAU、动态分辨率、GTAO、SSR、SSGI、froxel 体积光、物理大气、时域云、云影与眼适应。
|
|
44
|
+
- **可塑造的帧流程** — 经过验证的 Render
|
|
45
|
+
Graph 和可脚本化渲染管线统一协调阴影、场景 Pass、后处理、渲染目标、回读与最终呈现。
|
|
46
|
+
- **生产级生命周期** — 有界 GPU 缓存、增量上传、明确的资源所有权,以及 WebGPU device loss 和 WebGL
|
|
47
|
+
context loss 恢复。
|
|
22
48
|
|
|
23
49
|
## 安装
|
|
24
50
|
|
|
@@ -26,31 +52,37 @@ Hilo3d vNext 围绕 WebGPU-shaped RHI、显式 render pass、可复用 GPU 资
|
|
|
26
52
|
npm install hilo3d
|
|
27
53
|
```
|
|
28
54
|
|
|
29
|
-
|
|
30
|
-
1
|
|
55
|
+
Hilo3D 只提供 ESM。目标环境是支持 WebGPU 或 WebGL 2 的现代浏览器;WebGL
|
|
56
|
+
1 和旧式全局构建不属于 2.0 契约。
|
|
57
|
+
|
|
58
|
+
## 使用 Codex 构建游戏
|
|
31
59
|
|
|
32
|
-
|
|
60
|
+
独立的 [`hilo3d-game` Agent Skill](https://github.com/hiloteam/Hilo3d/tree/dev/skills/hilo3d-game)
|
|
61
|
+
可以帮助 Codex 规划、搭建、实现、调试和优化 Hilo3D 2D、3D 与混合浏览器游戏。它使用已发布的 `hilo3d`
|
|
62
|
+
包,并放在 `.agents/skills` 之外,因此可随仓库分发,同时不会成为维护引擎源码时自动加载的贡献者指引。
|
|
33
63
|
|
|
34
|
-
|
|
35
|
-
`backend: 'auto'`,存在兼容 adapter 时优先 WebGPU,并等待最终选中的后端完成初始化;返回的 stage 可以直接渲染。
|
|
64
|
+
## 创建第一个场景
|
|
36
65
|
|
|
37
66
|
```ts
|
|
38
67
|
import * as Hilo3d from 'hilo3d';
|
|
39
68
|
|
|
40
|
-
const camera = new Hilo3d.PerspectiveCamera({
|
|
69
|
+
const camera = new Hilo3d.PerspectiveCamera({
|
|
70
|
+
aspect: innerWidth / innerHeight,
|
|
71
|
+
z: 4
|
|
72
|
+
});
|
|
41
73
|
|
|
42
74
|
const stage = await Hilo3d.Stage.create({
|
|
43
|
-
backend: '
|
|
75
|
+
backend: 'auto',
|
|
44
76
|
container: document.querySelector('#app')!,
|
|
45
77
|
camera,
|
|
46
78
|
width: innerWidth,
|
|
47
79
|
height: innerHeight
|
|
48
80
|
});
|
|
49
81
|
|
|
50
|
-
|
|
82
|
+
new Hilo3d.Mesh({
|
|
51
83
|
geometry: new Hilo3d.BoxGeometry(),
|
|
52
84
|
material: new Hilo3d.PBRMaterial({
|
|
53
|
-
baseColor: new Hilo3d.Color(0.
|
|
85
|
+
baseColor: new Hilo3d.Color(0.83, 0.12, 0.09)
|
|
54
86
|
})
|
|
55
87
|
}).addTo(stage);
|
|
56
88
|
|
|
@@ -61,237 +93,128 @@ ticker.addTick(stage);
|
|
|
61
93
|
ticker.start();
|
|
62
94
|
```
|
|
63
95
|
|
|
64
|
-
|
|
65
|
-
`
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
##
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
后端选择和 GPU 初始化都是异步过程,因此 `Stage.create()` 也是异步工厂。应用需要指定后端时,可以使用
|
|
97
|
+
`backend: 'webgpu'` 或 `backend: 'webgl2'`。
|
|
98
|
+
|
|
99
|
+
## 查看引擎实际效果
|
|
100
|
+
|
|
101
|
+
<table>
|
|
102
|
+
<tr>
|
|
103
|
+
<td width="33.33%"><a href="https://hilo3d.js.org/examples/bloom.html?backend=webgpu"><img src="./website/assets/example-bloom.webp" alt="HDR Bloom 示例" /></a></td>
|
|
104
|
+
<td width="33.33%"><a href="https://hilo3d.js.org/examples/gltf_material_extensions.html"><img src="./website/assets/example-gltf-materials.webp" alt="glTF 材质扩展示例" /></a></td>
|
|
105
|
+
<td width="33.33%"><a href="https://hilo3d.js.org/examples/compute_raytracing.html?backend=webgpu"><img src="./website/assets/example-compute-raytracing.webp" alt="Compute 路径追踪示例" /></a></td>
|
|
106
|
+
</tr>
|
|
107
|
+
<tr>
|
|
108
|
+
<td><strong>HDR Bloom</strong><br />由引擎后处理管线塑造的 compute 驱动光效。</td>
|
|
109
|
+
<td><strong>glTF 材质扩展</strong><br />在共享 WebGPU/WebGL 2 渲染器中展示分层 Khronos 资产。</td>
|
|
110
|
+
<td><strong>Compute 路径追踪</strong><br />包含降噪、焦散和 HDR 输出的渐进式 WebGPU 路径追踪。</td>
|
|
111
|
+
</tr>
|
|
112
|
+
</table>
|
|
113
|
+
|
|
114
|
+
[浏览完整示例库 →](https://hilo3d.js.org/examples/list.html)
|
|
115
|
+
|
|
116
|
+
## 现代渲染技术栈
|
|
117
|
+
|
|
118
|
+
可选的 WebGPU high-end profile 与可移植渲染器共用同一套 Scene、Material、Render
|
|
119
|
+
Graph 和 RHI 契约。不支持的设备会在 runtime 创建前通过 capability 检查明确失败;不在原生 GPU
|
|
120
|
+
Scene 覆盖范围内的兼容 Mesh 会继续走共享 Forward 路径,并合成进同一线性 HDR 帧。
|
|
121
|
+
|
|
122
|
+
| 系统 | 当前生产切片 |
|
|
123
|
+
| ------------------ | ----------------------------------------------------------------------------------------------------- |
|
|
124
|
+
| GPU Scene | 脏对象/材质数据库、previous-frame Hi-Z 遮挡、projected-radius LOD、紧凑可见区间与固定 indirect bucket |
|
|
125
|
+
| Clustered Forward+ | depth-driven 3D cluster、有界且确定性的灯光分配、storage PBR、共享方向光/聚光/点光阴影与 LTC 面光 |
|
|
126
|
+
| 时域渲染 | Motion Vector、authored reactive mask、原生 TAA、0.5–1.0 TAAU 与 timestamp 驱动的动态分辨率 |
|
|
127
|
+
| 屏幕空间光照 | WebGPU/WebGL 2 可移植 GTAO 与 SSGI,以及 WebGPU Clustered hierarchical SSR |
|
|
128
|
+
| 体积与天气 | Froxel 高度雾/局部雾、方向光/点光/聚光注入、物理大气 LUT、时域云与云影 |
|
|
129
|
+
| HDR 显示 | GPU histogram 曝光、非对称眼适应、Bloom 与可配置 filmic 显示变换 |
|
|
130
|
+
|
|
131
|
+
可以体验
|
|
132
|
+
[Clustered Sponza 实验室](https://hilo3d.js.org/examples/clustered_forward_plus_sponza.html)、
|
|
133
|
+
[Temporal Observatory](https://hilo3d.js.org/examples/temporal_aa_observatory.html)、
|
|
134
|
+
[Silent Dragon GTAO](https://hilo3d.js.org/examples/ground_truth_ambient_occlusion.html)、
|
|
135
|
+
[Afterimage SSR](https://hilo3d.js.org/examples/screen_space_reflections_palace.html)、
|
|
136
|
+
[Prismatic Vespers SSGI](https://hilo3d.js.org/examples/screen_space_global_illumination_chapel.html)、
|
|
137
|
+
[Neon Reliquary 体积光](https://hilo3d.js.org/examples/volumetric_neon_reliquary.html)和
|
|
138
|
+
[Stormfront Observatory](https://hilo3d.js.org/examples/stormfront_observatory.html)。
|
|
139
|
+
|
|
140
|
+
完整的已完成边界、兼容路径和后续流送/虚拟化工作见
|
|
141
|
+
[现代 WebGPU 渲染路线图](./documentation/MODERN_WEBGPU_RENDERING_ROADMAP.md)。
|
|
142
|
+
|
|
143
|
+
## 渲染 Profile
|
|
144
|
+
|
|
145
|
+
| | 可移植 Profile | WebGPU High-end Profile |
|
|
146
|
+
| ------------ | ---------------------------------------------------------- | ------------------------------------------------------------------ |
|
|
147
|
+
| 后端 | WebGPU 与 WebGL 2 | WebGPU |
|
|
148
|
+
| 场景与材质 | 共享场景图、PBR 材质、glTF、Sprite、文本 | 同一公开模型,加注册 PBR bucket 与 Forward fallback |
|
|
149
|
+
| 帧合成 | Render Graph、渲染目标、MRT、MSAA、后处理 | 同一 Render Graph,加 GPU Scene、clustered lighting 与原生 compute |
|
|
150
|
+
| 光照与画质 | Forward PBR、阴影、GTAO、SSGI、TAA/TAAU、Bloom、Color Uber | 追加 Hi-Z SSR、动态分辨率、froxel、大气/云、自动曝光 |
|
|
151
|
+
| GPU 工作负载 | 实例化、uniform buffer、增量资源上传 | Compute、storage buffer/texture、indirect GPU 工作流 |
|
|
152
|
+
| Shader 路径 | 人工编写 GLSL ES 3.00 | Raster GLSL → Naga → WGSL;经过验证的 Direct WGSL compute |
|
|
153
|
+
| 恢复 | WebGL context 恢复或 WebGPU 资源重建 | WebGPU device 重获取与 submission-aware history 重建 |
|
|
154
|
+
|
|
155
|
+
WebGPU-only 功能在 WebGL 2 上会明确通过 capability 检查失败,不会被不完整地模拟。
|
|
156
|
+
|
|
157
|
+
## 架构概览
|
|
158
|
+
|
|
159
|
+
```text
|
|
160
|
+
场景 · 材质 · 2D · 动画 · 灯光
|
|
161
|
+
│
|
|
162
|
+
共享渲染器
|
|
163
|
+
│
|
|
164
|
+
Render Graph · 可脚本化渲染管线
|
|
165
|
+
│
|
|
166
|
+
可移植 RHI
|
|
167
|
+
┌─────┴─────┐
|
|
168
|
+
WebGPU WebGL 2
|
|
94
169
|
```
|
|
95
170
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
## 直接创建 Renderer
|
|
171
|
+
共享渲染器负责场景收集、剔除、排序、实例化、阴影、后处理、绘制准备和资源协调。生产帧统一流经 Render
|
|
172
|
+
Graph 与可移植 RHI;后端代码只负责原生 API 执行。
|
|
100
173
|
|
|
101
|
-
|
|
174
|
+
Raster shader 只有一份 GLSL ES 3.00 源码。WebGL
|
|
175
|
+
2 直接编译该源码;WebGPU 路径先进行引擎预处理,再通过 Naga 生成 WGSL。WebGPU-only
|
|
176
|
+
compute 使用引擎经过验证的 `ComputeShader` 契约。
|
|
102
177
|
|
|
103
|
-
|
|
104
|
-
const webglRenderer = await Hilo3d.Renderer.create({
|
|
105
|
-
backend: 'webgl2',
|
|
106
|
-
domElement: document.querySelector('canvas')!
|
|
107
|
-
});
|
|
178
|
+
完整的帧、资源、shader 与恢复契约见 [渲染架构文档](./documentation/RENDERING_ARCHITECTURE.md)。
|
|
108
179
|
|
|
109
|
-
|
|
110
|
-
backend: 'auto',
|
|
111
|
-
domElement: document.createElement('canvas')
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
const webgpuRenderer = await Hilo3d.Renderer.create({
|
|
115
|
-
backend: 'webgpu',
|
|
116
|
-
domElement: document.createElement('canvas')
|
|
117
|
-
});
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
所有 Renderer 都创建同一公开 `RenderTarget` 契约。可以通过 `renderer.backend`
|
|
121
|
-
观察最终后端,但 scene、material、target 与 shader API 不随之变化。
|
|
122
|
-
|
|
123
|
-
## 能力矩阵
|
|
124
|
-
|
|
125
|
-
| 能力 | WebGPU | WebGL 2 |
|
|
126
|
-
| --------------------- | -------------------------------------------------- | -------------------------------------------------------- |
|
|
127
|
-
| RHI 执行 | 薄封装 native encoder/pass/queue | encoder/pass 语义下的即时 GL 执行 |
|
|
128
|
-
| Shader module 输入 | Renderer 准备好的 WGSL | Renderer 准备好的 GLSL ES 3.00 |
|
|
129
|
-
| 多 pass `renderFrame` | 资源已就绪的 renderer pass 使用一个 encoder/submit | 按顺序即时执行;submit 绝不回放命令 |
|
|
130
|
-
| Device 对象复用 | 有界 pipeline、layout 与 sampler cache | 有界 pipeline、layout、sampler、framebuffer 与 VAO cache |
|
|
131
|
-
| 增量上传 | UBO/geometry dirty range;texture revision | UBO/geometry dirty range;texture revision |
|
|
132
|
-
| Render target | MRT、1×/4× MSAA、可采样 attachment、异步回读 | 相同引擎契约 |
|
|
133
|
-
| RHI 不支持能力 | 通过 `features`/`limits` 声明,请求时拒绝 | compute/storage/1D/异步 buffer mapping 明确不支持 |
|
|
134
|
-
| 丢失处理 | 重新获取 device 并恢复资源 | 恢复 context 与资源 |
|
|
135
|
-
| 后端选择 | 显式请求失败即 reject;`auto` 只做 adapter 探测 | `auto` 探测不支持时直接选择;不回退 WebGL 1 |
|
|
136
|
-
|
|
137
|
-
## 一帧,多 pass
|
|
138
|
-
|
|
139
|
-
应用自主管理 frame graph 时使用
|
|
140
|
-
`renderFrame()`。WebGPU 中,回调内资源已就绪的 scene、target 与 present 调用共享一个应用 command
|
|
141
|
-
encoder,最终最多产生一次应用提交;WebGL 2 则通过相同的后端中立 facade 按顺序执行同一组命令。
|
|
180
|
+
## 文档
|
|
142
181
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
182
|
+
- [入门与 API 文档](https://hilo3d.js.org/docs/)
|
|
183
|
+
- [示例库](https://hilo3d.js.org/examples/list.html)
|
|
184
|
+
- [`hilo3d-game` Agent Skill](https://github.com/hiloteam/Hilo3d/tree/dev/skills/hilo3d-game)
|
|
185
|
+
- [工程文档索引](./documentation/README.md)
|
|
186
|
+
- [渲染架构](./documentation/RENDERING_ARCHITECTURE.md)
|
|
187
|
+
- [PBR、HDR 与后处理](./documentation/PBR_AND_POST_PROCESSING.md)
|
|
188
|
+
- [现代 WebGPU 渲染路线图](./documentation/MODERN_WEBGPU_RENDERING_ROADMAP.md)
|
|
189
|
+
- [材质系统现代化](./documentation/MATERIAL_SYSTEM_MODERNIZATION.md)
|
|
190
|
+
- [时域渲染](./documentation/TEMPORAL_RENDERING_REMEDIATION.md)
|
|
191
|
+
- [屏幕空间全局光照](./documentation/SCREEN_SPACE_GLOBAL_ILLUMINATION.md)
|
|
192
|
+
- [Froxel 体积光](./documentation/VOLUMETRIC_LIGHTING.md)
|
|
193
|
+
- [物理大气与天气](./documentation/PHYSICAL_ATMOSPHERE_AND_WEATHER.md)
|
|
194
|
+
- [2D 渲染与多相机合成](./documentation/2D_RENDERING.md)
|
|
195
|
+
- [可脚本化渲染管线](./documentation/SCRIPTABLE_RENDER_PIPELINE_PLAN.md)
|
|
196
|
+
- [破坏性变更](./CHANGELOG.md#breaking-changes)
|
|
197
|
+
|
|
198
|
+
## 本地开发
|
|
199
|
+
|
|
200
|
+
需要 Node.js 20.19.0 或更高版本,以及仓库声明的 npm 版本。
|
|
149
201
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
frame.present(sceneTarget);
|
|
154
|
-
});
|
|
202
|
+
```sh
|
|
203
|
+
npm ci
|
|
204
|
+
npm run dev
|
|
155
205
|
```
|
|
156
206
|
|
|
157
|
-
|
|
158
|
-
callback,不要同时让 `Stage`
|
|
159
|
-
执行默认渲染。callback 必须同步执行,不能返回 Promise,也不能在返回后继续持有 `frame`
|
|
160
|
-
facade。进入 callback 前应确定 scene transform、material、`GeometryData`
|
|
161
|
-
与 texture 更新;同一帧首次使用后不能再改变 geometry 或 texture 内容。冷启动 texture
|
|
162
|
-
mipmap 准备和显式 readback 属于独立 GPU 工作,不计入应用 pass 的单次提交承诺。renderer 的 resize、`setRenderTarget()`、资源释放/销毁,以及 render
|
|
163
|
-
target 的 resize、readback、destroy 必须在 callback 外执行;WebGPU 录制期间尝试这些操作会中止整帧,且不会提交部分 command。
|
|
164
|
-
|
|
165
|
-
## 可脚本化渲染管线
|
|
166
|
-
|
|
167
|
-
可以在 `Renderer.create()` 或 `Stage.create()` 中传入可复用的 `renderPipeline`
|
|
168
|
-
factory 来完整替换帧编排,也可以通过 `ForwardRenderPipelineFactory`
|
|
169
|
-
feature 在 shadow、opaque、transparent、post-process 和 output 阶段之间注入工作。每个 Renderer 都获得独立 pipeline/feature
|
|
170
|
-
runtime;record 保持同步,并与普通 renderer 命令写入同一个事务化 Render
|
|
171
|
-
Graph。默认空 feature 集继续走原有 direct forward 快路径,不创建中间 scene target,也不增加 present
|
|
172
|
-
pass。
|
|
173
|
-
|
|
174
|
-
图采样与纹理 copy 使用不同声明:fullscreen 输入必须支持线性过滤;copy
|
|
175
|
-
pass 必须声明精确的 source/destination pair,并在 backend frame 开始前验证解析后的 RHI texture。
|
|
176
|
-
|
|
177
|
-
[可脚本化管线示例](https://hilo3d.js.org/examples/scriptable_pipeline.html)展示了使用 retained
|
|
178
|
-
fullscreen feature 采样 scene color;
|
|
179
|
-
[SRP 架构文档](./documentation/SCRIPTABLE_RENDER_PIPELINE_PLAN.md)说明资源所有权、失败回滚、性能门禁,以及 storage
|
|
180
|
-
buffer/compute 的 capability-gated 扩展路线。当前 compute/storage
|
|
181
|
-
capability 会明确失败,不会在 WebGL 2 上提供不完整模拟。
|
|
182
|
-
|
|
183
|
-
## 现代渲染架构
|
|
184
|
-
|
|
185
|
-
- `src/render` 负责唯一公开的 Renderer、scene traversal、frame planning、render target 契约、std140
|
|
186
|
-
uniform 数据、shader 接口准备和确定性引擎资源归属。
|
|
187
|
-
- `src/shader` 负责 GLSL 预处理和引擎 shader variant;`src/render/shader`
|
|
188
|
-
负责反射 binding 与 GLSL→WGSL 编译;RHI 不知道 shader variant 或 material。
|
|
189
|
-
- `src/render/rhi/RHI.ts` 定义 WebGPU-shaped 的 device、resource、pipeline、bind group、render
|
|
190
|
-
pass、encoder、queue、surface、feature 与 limit 契约。
|
|
191
|
-
- `src/render/rhi/RHIFactory.ts`
|
|
192
|
-
是唯一硬件组合根:只构造一次具体 RHI 并负责后端能力探测,不在每条 command 外再包一层 facade。
|
|
193
|
-
- `src/render/rhi/backends/webgpu` 直接包装 native WebGPU;`src/render/rhi/backends/webgl2`
|
|
194
|
-
包含 WebGL 2 语义模拟、state cache、framebuffer/VAO 归属和 context
|
|
195
|
-
recovery。两个 RHI 都不引用引擎 scene 类型。
|
|
196
|
-
- 后端准备与 native 执行全部是内部实现,不存在后端专属的公开 Renderer 或 RenderTarget 类;内部 Renderer
|
|
197
|
-
factory 只在构造时选择一次具体 driver,并直接返回该实例。
|
|
198
|
-
|
|
199
|
-
抽象边界刻意采用 WebGPU 模型,而不是 WebGL 状态机。WebGPU render pass 与 native pass 一对一,command
|
|
200
|
-
encoder 直接持有 native encoder。WebGL2RHI 只在 pipeline 或 bind
|
|
201
|
-
group 状态变化时应用 GL 状态,draw/copy 在编码期间已执行;返回的 command buffer 只是一次性 submit
|
|
202
|
-
token。生产 WebGPU 路径直接使用同一个 concrete device 上的一跳 native fast path,主 draw
|
|
203
|
-
loop 保留 native handle,不承担逐 draw wrapper 或虚调用开销。WebGL 2 路径则在 frame-scoped
|
|
204
|
-
session 中执行 Program/VAO,并共享 RHI 唯一的 context、canonical state
|
|
205
|
-
differential、lifecycle 与 device-owned sampler
|
|
206
|
-
cache;Program、VAO、framebuffer 仍属于 render 层 cache,不会创建并行 context 或可回放命令列表。无法在 WebGL
|
|
207
|
-
2 中正确实现的 compute pipeline、storage texture/buffer、1D texture、异步 buffer
|
|
208
|
-
mapping、base-vertex 与 first-instance draw 会从 `features` 中缺席或以 0
|
|
209
|
-
limit 暴露,请求时明确报错。RHI 契约内部会保守声明格式相关的采样、过滤、attachment、storage 和 MSAA 能力,包括 extension/tier 导致的差异。
|
|
210
|
-
|
|
211
|
-
全部引擎 shader 都以 GLSL ES 3.00 为起点。WebGL 2 直接编译;WebGPU 先解析 shader
|
|
212
|
-
variant,把生效接口改写成 Vulkan GLSL 4.50,再交给 Naga WASM frontend 生成 WGSL。引擎内部 utility
|
|
213
|
-
pass 也使用相同路径,不维护手写 fallback WGSL shader 集。
|
|
214
|
-
|
|
215
|
-
Shader variant 使用结构化、带类型与长度边界的双通道 64-bit
|
|
216
|
-
hash,不生成中间序列化 key;同时保留精确字段用于碰撞检查,发生碰撞时会得到确定性 bucket
|
|
217
|
-
key,不会错误复用另一个 shader。Cache 归属只保留一层:每个 RHI device 持有有界的 immutable
|
|
218
|
-
sampler、bind-group-layout、pipeline-layout 与 render-pipeline
|
|
219
|
-
cache;Renderer 持有 material、Mesh、shader variant、binding set 和 upload revision
|
|
220
|
-
cache。RHI 不按 descriptor 去重 buffer、texture、shader module 或 bind
|
|
221
|
-
group,因为它们的 identity 与生命周期属于应用数据;label 不参与 device cache key。Device
|
|
222
|
-
lost/context restore 和显式 destroy 会清空所有 device cache。
|
|
223
|
-
|
|
224
|
-
Texture identity 保持后端中立:共享对象只保存 CPU 内容、不可变 update
|
|
225
|
-
snapshot 与单调 revision;每个 WebGL context 和 WebGPU device 分别持有 native allocation 与 upload
|
|
226
|
-
cursor。WebGL descriptor snapshot 让 framebuffer resize/reset 可稳定复用 native
|
|
227
|
-
object;WebGPU 会延迟销毁仍被待提交 command 引用的 buffer 与 texture。不可取消的内部生命周期 observer 会先释放所有后端 allocation,再执行可被用户取消的公开事件,context/device
|
|
228
|
-
lost 与显式资源释放也遵循同一规则。WebGL sampler variant 是不可变、有界且按 texture
|
|
229
|
-
unit 绑定的,因此同一张 depth texture 可以在一次 draw 中同时用于数值读取和 comparison
|
|
230
|
-
sampling,不需要改写 texture 全局状态。
|
|
231
|
-
|
|
232
|
-
两个后端的 render target owner 都会跟踪 attachment allocation generation。Texture
|
|
233
|
-
target 变化、上传失败或显式销毁 attachment 时会使旧 allocation 失效;target 会在再次使用前重建资源或重新挂接,并拒绝陈旧的 native
|
|
234
|
-
handle。
|
|
235
|
-
|
|
236
|
-
Uniform buffer、动态 geometry 与 texture 都携带后端本地 revision;allocation
|
|
237
|
-
shape 稳定时,两个后端只上传 UBO 与 geometry 合并后的 dirty
|
|
238
|
-
range,texture 则从所需 revision 重放不可变的 subresource update snapshot。WebGPU command-state
|
|
239
|
-
cache 还会在单个 pass 内消除重复的 pipeline、bind group、vertex/index
|
|
240
|
-
buffer、viewport 与 stencil 命令。
|
|
241
|
-
|
|
242
|
-
## 自定义 GLSL 与 UBO 契约
|
|
243
|
-
|
|
244
|
-
数值 shader 数据必须放入已注册的 std140 block;sampler 是唯一允许放在 block 外的 uniform。
|
|
245
|
-
|
|
246
|
-
```ts
|
|
247
|
-
Hilo3d.registerUniformBlockBinding('EffectBlock');
|
|
248
|
-
const effectLayout = Hilo3d.createStd140Layout({ tint: 'vec4' });
|
|
249
|
-
const effectBlock = Hilo3d.UniformBuffer.fromSchema(effectLayout, {
|
|
250
|
-
tint: [0.6, 0.8, 1, 1]
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
const material = new Hilo3d.ShaderMaterial({
|
|
254
|
-
attributes: { a_position: 'POSITION' },
|
|
255
|
-
uniformBlocks: { EffectBlock: effectBlock },
|
|
256
|
-
vs: `#version 300 es
|
|
257
|
-
layout(std140) uniform EffectBlock { vec4 tint; };
|
|
258
|
-
in vec3 a_position; out vec4 v_tint;
|
|
259
|
-
void main() { v_tint = tint; gl_Position = vec4(a_position, 1.0); }`,
|
|
260
|
-
fs: `#version 300 es
|
|
261
|
-
precision highp float;
|
|
262
|
-
in vec4 v_tint; layout(location = 0) out vec4 outColor;
|
|
263
|
-
void main() { outColor = v_tint; }`
|
|
264
|
-
});
|
|
207
|
+
常用命令:
|
|
265
208
|
|
|
266
|
-
|
|
209
|
+
```sh
|
|
210
|
+
npm run examples:dev # 在本地运行示例库
|
|
211
|
+
npm run typecheck # 检查维护中的 TypeScript
|
|
212
|
+
npm run test # 运行测试套件
|
|
213
|
+
npm run validate # 运行完整发布验证
|
|
267
214
|
```
|
|
268
215
|
|
|
269
|
-
|
|
270
|
-
block 必须在首次使用前注册;跨 stage 的同名 block
|
|
271
|
-
layout 必须相同;schema 只使用 scalar、vector、matrix 或定长数组组成的扁平结构。
|
|
272
|
-
|
|
273
|
-
## Device 与资源生命周期
|
|
274
|
-
|
|
275
|
-
WebGPU device lost 后先触发
|
|
276
|
-
`webgpuDeviceLost`,使用冻结的要求重新获取等价 adapter/device,复核 feature 与 limit,重建 device-owned
|
|
277
|
-
manager/cache,在不改变公开 target 对象 identity 的前提下恢复 render-target 资源,最后触发
|
|
278
|
-
`webgpuDeviceRestored`。恢复期间安全跳帧;最终失败会触发
|
|
279
|
-
`webgpuDeviceRecoveryFailed`,之后的 render 显式抛错,并且绝不切换到 WebGL
|
|
280
|
-
2。`releaseGPUResources()` 会清理自有 GPU 状态,但 renderer 仍可继续使用。
|
|
216
|
+
提交 Pull Request 前请先阅读[贡献指南](./.github/CONTRIBUTING.md)。
|
|
281
217
|
|
|
282
|
-
|
|
283
|
-
`renderer.getExtension('webgl2-native')` 或 `renderer.getExtension('webgpu-native')`
|
|
284
|
-
获取,公开 Renderer 不直接暴露 context 或 device 字段。使用前必须检查 extension 是否存在,常规渲染继续使用共享的 Renderer/RenderTarget
|
|
285
|
-
API。
|
|
218
|
+
## 许可证
|
|
286
219
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
- [API 文档](https://hilo3d.js.org/docs/)
|
|
290
|
-
- [完整示例库](https://hilo3d.js.org/examples/list.html)
|
|
291
|
-
- [glTF Viewer](https://hilo3d.js.org/examples/glTFViewer/index.html)
|
|
292
|
-
- [工程文档索引](./documentation/README.md)
|
|
293
|
-
- [当前渲染架构](./documentation/RENDERING_ARCHITECTURE.md)
|
|
294
|
-
- [vNext 渲染工程记录](./documentation/ENGINEERING_MODERNIZATION.md#双后端渲染与-shader-abi)
|
|
295
|
-
- [ShaderMaterial 迁移指南](./documentation/ENGINEERING_MODERNIZATION.md#shadermaterial-迁移)
|
|
296
|
-
- [Breaking changes](./CHANGELOG.md#breaking-changes)
|
|
297
|
-
- [贡献指南](./.github/CONTRIBUTING.md)
|
|
220
|
+
[MIT](./LICENSE) © Hilo3D contributors.
|