feat: HitProxy GPU 拾取 + UE 选中描边 + 编辑器拾取交互

- HitProxy 拾取:RG 管线渲染实体 id → host readback,点击帧
  PickEntity 精确命中;拾取按视觉几何(Model 联合包围球射线求交),
  与 Collider 解耦(UE/Unity 编辑器语义),命中打印实体名+碰撞体参数
- 选中描边(UE 语义):SelectionMask pass(R8Unorm 完整投影轮廓,
  无深度测试透墙可见)→ Outline pass(边缘检测 + alpha 叠加,
  必须注册在 Tonemap 后);edgeCut 贴视口边缘;widthPx=6 可调
- shader object 实证修复:VUID-08879 同程序 set layouts 超集一致、
  VUID-10065 push block 4×float 平铺、新 pass 析构销毁 VkShaderEXT
- RG:SideEffect() 保活"产出无 RG 内消费者"的 pass 链
- Editor:层次面板点击选中、Inspector 姿态编辑、Stats 面板拾取信息
- 相机 Update 改 const(姿态写入 Transform 引用,Camera 本身无状态变更)
This commit is contained in:
2026-10-02 20:09:05 +08:00
parent 1c4b6f37ff
commit 1449bea86d
29 changed files with 1360 additions and 43 deletions
+13
View File
@@ -0,0 +1,13 @@
#version 450
// HitProxy 片元:把顶点传来的实体 id 原样写进 R32Uint 目标。
// flat 限定 = 无插值,像素值即命中图元的实体位模式;
// 清屏色 0xFFFFFFFF(kPickMiss)= 天空/空隙未命中。
layout(location = 0) flat in uint inEntityId;
layout(location = 0) out uvec4 outColor;
void main() {
outColor = uvec4(inEntityId, 0u, 0u, 0u);
}
+57
View File
@@ -0,0 +1,57 @@
#version 450
// HitProxy 顶点:UE 式 GPU 拾取——Forward 同结构画一遍(无光照无纹理),
// 输出 per-instance 实体 id。位置变换与 simple_shader.vert 完全同源
//(模型矩阵 + 蒙皮),保证拾取像素与可见画面像素一致。
//
// Set0 与 simple_shader 共用同一 uboSetLayout(SceneGpu 契约);
// 本 shader 只声明用到的绑定,描述符集合里未用的绑定合法。
layout(location = 0) in vec3 inPosition;
layout(location = 4) in uvec4 inBoneIds; // 骨骼槽(palette 下标)
layout(location = 5) in vec4 inWeights; // 无骨骼顶点 = (1,0,0,0)
layout(location = 0) flat out uint outEntityId; // 整数 varying 必须 flat
layout(std430, set = 0, binding = 1) readonly buffer ObjectBuffer {
mat4 models[];
} objects;
layout(std430, set = 0, binding = 3) readonly buffer SkinOffsetBuffer {
uint skinBases[];
} skinOffsets;
layout(std430, set = 0, binding = 4) readonly buffer SkinPaletteBuffer {
mat4 bones[];
} skinPalettes;
// per-instance 实体 id(与 models 平行对齐,SceneRenderer 收集时写入)
layout(std430, set = 0, binding = 5) readonly buffer EntityIdBuffer {
uint ids[];
} entityIds;
// 只用 view/proj:std140 前两个 mat4 与完整 UBO 的布局前缀一致
layout(set = 0, binding = 0) uniform Ubo {
mat4 view;
mat4 proj;
} ubo;
// 4 权重混合的蒙皮矩阵(与 simple_shader.vert 同逻辑)
mat4 SkinMatrix() {
uint base = skinOffsets.skinBases[gl_InstanceIndex];
return skinPalettes.bones[base + inBoneIds.x] * inWeights.x +
skinPalettes.bones[base + inBoneIds.y] * inWeights.y +
skinPalettes.bones[base + inBoneIds.z] * inWeights.z +
skinPalettes.bones[base + inBoneIds.w] * inWeights.w;
}
void main() {
mat4 model = objects.models[gl_InstanceIndex];
mat4 skin = SkinMatrix();
vec3 skinnedPos = (skin * vec4(inPosition, 1.0)).xyz;
vec4 worldPos = model * vec4(skinnedPos, 1.0);
gl_Position = ubo.proj * ubo.view * worldPos;
outEntityId = entityIds.ids[gl_InstanceIndex];
}
+61
View File
@@ -0,0 +1,61 @@
#version 450
// UE 编辑器选中描边:对 SelectionMask 做 16 方向圆周边缘检测,
// alpha 叠加在 Tonemap 之后的 PresentTarget 上(LDR 恒定 UI 色,
// 不进 bloom/曝光/TAA——与 UE 编辑器选中轮廓一致)。
//
// 规则:
// 外描边 自身 mask=0 且邻域有 1 → 描边(物体外圈一圈)
// 贴边线 自身 mask=1 且邻域采样越出视口(视为 0)→ 描边——物体
// 延伸出视口时 mask 在边缘截断,描边自动贴着渲染视口边缘
// 完全出视野 mask 全 0 → 无描边
// 描边不做深度遮挡判定(透墙可见)——UE 编辑器同行为,便于找到
// 被挡住的选中物体。
layout(location = 0) in vec2 fragUV;
layout(location = 0) out vec4 outColor;
layout(set = 0, binding = 0) uniform sampler2D maskImage;
// 全屏 pass 通用 push(16B,程序级统一声明,VUID-08878)。
// 注意:必须用 4×float 平铺——"float + vec3" 会被 GLSL 对齐成 28B
// (vec3 落 16 偏移),超出 FullscreenPush 的 [0,16] 声明范围
// (VUID-10065)。语义与 FullscreenPush 对齐:exposure 槽位=描边宽度,
// param0-2=描边色。
layout(push_constant) uniform PushConstants {
float widthPx; // 描边宽度(物理像素)
float colorR; // 描边色 R
float colorG; // 描边色 G
float colorB; // 描边色 B
} pc;
void main() {
const float m = texture(maskImage, fragUV).r;
const vec2 texel = vec2(pc.widthPx) / vec2(textureSize(maskImage, 0));
float ringMax = 0.0;
bool anyOutside = false;
const int N = 16;
for (int i = 0; i < N; ++i) {
const float a = float(i) * (6.2831853 / float(N));
const vec2 suv = fragUV + vec2(cos(a), sin(a)) * texel;
// 越界 = 视口截断(视为无 mask)→ 贴边像素产生描边
const bool outside = suv.x < 0.0 || suv.x > 1.0 ||
suv.y < 0.0 || suv.y > 1.0;
anyOutside = anyOutside || outside;
if (!outside) {
ringMax = max(ringMax, texture(maskImage, suv).r);
}
}
// 外描边:自身 mask=0 且邻域有 1(真轮廓;mask 无洞,不会描出
// 前方遮挡物的轮廓)
// 贴边内描边:自身 mask=1 且邻域越出视口(仅视口截断,物体延伸
// 出视野时描边贴着渲染视口边缘)
const bool outer = m < 0.5 && ringMax > 0.5;
const bool edgeCut = m > 0.5 && anyOutside;
const float edge = (outer || edgeCut) ? 1.0 : 0.0;
// LDR 恒定色直出,alpha 混合叠加在 Tonemap 输出上
outColor = vec4(pc.colorR, pc.colorG, pc.colorB, edge);
}
+17
View File
@@ -0,0 +1,17 @@
#version 450
// 选中描边 mask 片元:恒输出 1(选中标记)。
//
// 与 forwardVert 配对(复用 SceneGpu 的 Set0:UBO + 蒙皮 SSBO,静态/
// 蒙皮同一 shader 内分支)。写入 R8Unorm SelectionMask;任何非零 = 该
// 像素属于选中实体(黑色物体也可靠——颜色无关,恒 1)。
layout(location = 0) out vec4 outColor;
// 仅接口对齐(simple_shader.vert 同槽位输出 float,未消费会刷
// validation 警告),mask 不需要视图深度
layout(location = 3) in float fragViewDepth;
void main() {
outColor = vec4(1.0);
}