docs: expand rendering core docs
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
# ObjectIdEncoding
|
||||
|
||||
**命名空间**: `XCEngine::Rendering`
|
||||
|
||||
**类型**: `utility header`
|
||||
|
||||
**头文件**: `XCEngine/Rendering/ObjectIdEncoding.h`
|
||||
|
||||
**描述**: 提供对象 ID 和颜色缓冲之间的轻量编解码 helper,供 object-id 渲染与拾取链路共享。
|
||||
|
||||
## 概览
|
||||
|
||||
`ObjectIdEncoding.h` 把“对象 ID 写进颜色缓冲,再从颜色缓冲读回来”的协议固定成了三段小函数。
|
||||
|
||||
当前这套协议主要服务于:
|
||||
|
||||
- [BuiltinObjectIdPass](../Passes/BuiltinObjectIdPass/BuiltinObjectIdPass.md) 把对象 ID 编码到 object-id 纹理
|
||||
- [BuiltinObjectIdOutlinePass](../Passes/BuiltinObjectIdOutlinePass/BuiltinObjectIdOutlinePass.md) 生成选中轮廓时复用同样的颜色表示
|
||||
- editor viewport 的 object picker 从像素颜色反解回 `entityId`
|
||||
|
||||
## 编码规则
|
||||
|
||||
### `EncodeObjectIdToUInt32()`
|
||||
|
||||
把传入的 `uint64_t objectId` 截断成低 `32` 位。
|
||||
|
||||
### `EncodeObjectIdToColor()`
|
||||
|
||||
把编码后的 `uint32` 拆成四个 `8-bit` 通道,并按 `0..255 -> 0..1` 归一化为 `Vector4`:
|
||||
|
||||
- `r` 对应最低 8 位
|
||||
- `g` 对应第 8-15 位
|
||||
- `b` 对应第 16-23 位
|
||||
- `a` 对应第 24-31 位
|
||||
|
||||
### `DecodeObjectIdFromColor()`
|
||||
|
||||
按同样的通道顺序把 `r/g/b/a` 重新拼回 `uint32_t`。
|
||||
|
||||
## 当前实现边界
|
||||
|
||||
- 高于 `32` 位的对象身份当前会被截断,无法通过 object-id 颜色缓冲完整保真。
|
||||
- 这里的 helper 只定义字节打包协议,不处理颜色空间、纹理格式选择或 GPU 读回流程。
|
||||
- `DecodeObjectIdFromColor()` 返回 `uint32_t`,调用方如果内部仍使用 `uint64_t`,需要自己做扩展或约定。
|
||||
|
||||
## 真实使用位置
|
||||
|
||||
- `engine/src/Rendering/Passes/BuiltinObjectIdPass.cpp` 用它把对象 ID 写进 shader 常量。
|
||||
- `engine/src/Rendering/Passes/BuiltinObjectIdOutlinePass.cpp` 用它构建选中对象颜色列表。
|
||||
- `editor/src/Viewport/ViewportObjectIdPicker.h` 用它把像素颜色解码成拾取结果。
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [当前模块](../Rendering.md)
|
||||
- [ObjectIdPass](../ObjectIdPass/ObjectIdPass.md)
|
||||
- [BuiltinObjectIdPass](../Passes/BuiltinObjectIdPass/BuiltinObjectIdPass.md)
|
||||
- [BuiltinObjectIdOutlinePass](../Passes/BuiltinObjectIdOutlinePass/BuiltinObjectIdOutlinePass.md)
|
||||
Reference in New Issue
Block a user