- RenderGraph 声明 ShadowMap 虚拟资源(D32,2048²固定分辨率,独立于 swapchain 尺寸),Shadow pass 写深度 → Forward 声明 ShaderRead 采样, barrier/layout(DepthAttachment→ShaderReadOnly)全部由图自动预算 - Shadow pass:空 fragment shader + 深度偏移(斜率缩放)抗 shadow acne - Forward:UBO 增加 lightSpace 矩阵;Set 2 采样阴影图,手动对比 + 斜率缩放偏差;clamp-to-border 白色边界(光视锥外 = 全亮) - 光空间矩阵:主光方向反推 30 单位正交盒;深度重映射 [-1,1]→[0,1] - GetPhysicalView(slot):物理镜像按帧槽位隔离,描述符 Compile 后一次性写入 - 修复 RG 隐蔽 bug:ShaderStage 与 PipelineStage2 位值不同 (eFragment=0x10 vs eFragmentShader=0x80),位值直转会撞出 TESSELLATION_CONTROL stage;改为逐位显式映射 - 修复 Camera 投影深度未重映射到 [0,1] 的潜在裁剪问题 validation 零错误零警告(3 passes / 5 barriers / 4 gpu images)
44 lines
1.0 KiB
GLSL
44 lines
1.0 KiB
GLSL
#version 450
|
|
|
|
const int MAX_LIGHTS = 4;
|
|
|
|
struct Light {
|
|
vec4 direction;
|
|
vec4 color;
|
|
};
|
|
|
|
layout(location = 0) in vec3 inPosition;
|
|
layout(location = 1) in vec3 inNormal;
|
|
layout(location = 2) in vec2 inUV;
|
|
|
|
layout(location = 0) out vec2 fragUV;
|
|
layout(location = 1) out vec3 fragNormal;
|
|
layout(location = 2) out vec3 fragWorldPos;
|
|
layout(location = 3) out vec4 fragLightPos; // 光空间裁剪坐标(阴影采样用)
|
|
|
|
layout(push_constant) uniform PushConstants {
|
|
mat4 model;
|
|
} pc;
|
|
|
|
layout(set = 0, binding = 0) uniform UniformBufferObject {
|
|
mat4 view;
|
|
mat4 proj;
|
|
mat4 lightSpace; // 主光(lights[0])的正交光空间变换
|
|
vec4 ambientColor;
|
|
Light lights[MAX_LIGHTS];
|
|
} ubo;
|
|
|
|
void main() {
|
|
vec4 worldPos = pc.model * vec4(inPosition, 1.0);
|
|
gl_Position = ubo.proj * ubo.view * worldPos;
|
|
|
|
fragWorldPos = worldPos.xyz;
|
|
|
|
mat3 normalMatrix = mat3(transpose(inverse(pc.model)));
|
|
fragNormal = normalize(normalMatrix * inNormal);
|
|
|
|
fragUV = inUV;
|
|
|
|
fragLightPos = ubo.lightSpace * worldPos;
|
|
}
|