feat: 环境背景管线(IBL 阶段①)——HDR 等距柱状转 cube + Skybox pass
- Cubemap:stbi_loadf 加载 .hdr,CPU 双线性重采样 6 面(GL 规范方向表), f32→fp16 转换后整块上传 eCubeCompatible image(R16G16B16A16Sfloat) - SkyboxPass:HDRColor 的 first writer,承担清屏职责;无环境贴图自动 退化为纯清屏(Forward 不受影响) - frag 逐像素 NDC 反投影取世界方向(invVP push,投影变换不可线性插值) - Forward color 附件 Clear→Load:几何合成在天空之上 - SceneRenderer 产出 skyInvVP = inverse(proj × mat4(mat3(view)))
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
#version 450
|
||||
|
||||
// 天空盒像素:NDC → 世界方向 → cube 采样。
|
||||
// invVP = inverse(projNoJitter × mat4(mat3(view))):去掉平移的视图,
|
||||
// 反投影结果即"相机相对"的世界方向,normalize 后直接采样 cube。
|
||||
|
||||
layout(location = 0) in vec2 fragUV;
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
layout(set = 0, binding = 0) uniform samplerCube envMap;
|
||||
|
||||
// push 与 skybox.vert 一致声明(VUID-08878)
|
||||
layout(push_constant) uniform PushConstants {
|
||||
mat4 invVP;
|
||||
} pc;
|
||||
|
||||
void main() {
|
||||
vec4 target = pc.invVP * vec4(fragUV * 2.0 - 1.0, 1.0, 1.0);
|
||||
vec3 dir = normalize(target.xyz / target.w);
|
||||
outColor = vec4(texture(envMap, dir).rgb, 1.0);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#version 450
|
||||
|
||||
// 天空盒顶点:全屏三角形(无顶点缓冲),UV 交给 fragment 反投影。
|
||||
// 方向在 fragment 逐像素计算(invVP 是投影变换,对 NDC 线性插值方向
|
||||
// 不精确;UV 插值是仿射的,逐像素重建方向零误差)。
|
||||
|
||||
layout(location = 0) out vec2 fragUV;
|
||||
|
||||
// push 与 skybox.frag 一致声明(VUID-08878:shader object 接口一致)
|
||||
layout(push_constant) uniform PushConstants {
|
||||
mat4 invVP;
|
||||
} pc;
|
||||
|
||||
void main() {
|
||||
vec2 p = vec2(
|
||||
float((gl_VertexIndex << 1) & 2),
|
||||
float(gl_VertexIndex & 2));
|
||||
fragUV = p;
|
||||
// 远平面:z = 1(Vulkan [0,1] 深度),无深度附件,只关心覆盖屏幕
|
||||
gl_Position = vec4(p * 2.0 - 1.0, 1.0, 1.0);
|
||||
}
|
||||
Reference in New Issue
Block a user