diff --git a/shaders/texture_loading/glsl/bg.frag b/shaders/texture_loading/glsl/bg.frag index 6ead49d..b0c9aab 100644 --- a/shaders/texture_loading/glsl/bg.frag +++ b/shaders/texture_loading/glsl/bg.frag @@ -1,11 +1,17 @@ #version 450 -layout(binding = 0) uniform sampler2D backgroundTexture; // Binding 0 +// 输入变量(与顶点着色器输出对应) +layout(location = 0) in vec2 inPosition; -layout(location = 0) in vec2 inUV; +// 输出颜色 layout(location = 0) out vec4 outColor; void main() { - //outColor = texture(backgroundTexture, inUV); - outColor = vec4(1.0, 0.0, 0.0, 1.0); // 输出红色 + // 示例:基于位置生成颜色 + outColor = vec4( + (inPosition.x + 1.0) * 0.5, // 将X从[-1,1]映射到[0,1] + (inPosition.y + 1.0) * 0.5, // 将Y从[-1,1]映射到[0,1] + 0, // 蓝色分量固定 + 1.0 // Alpha固定 + ); } \ No newline at end of file diff --git a/shaders/texture_loading/glsl/bg.frag.spv b/shaders/texture_loading/glsl/bg.frag.spv index 1a968cf..279cea5 100644 Binary files a/shaders/texture_loading/glsl/bg.frag.spv and b/shaders/texture_loading/glsl/bg.frag.spv differ diff --git a/shaders/texture_loading/glsl/bg.vert b/shaders/texture_loading/glsl/bg.vert index 9e096f3..3dad2ab 100644 --- a/shaders/texture_loading/glsl/bg.vert +++ b/shaders/texture_loading/glsl/bg.vert @@ -1,14 +1,26 @@ #version 450 -layout(location = 0) out vec2 uv; +// 硬编码的顶点数据 - 4个顶点组成三角形带覆盖整个屏幕 +const vec2 positions[6] = vec2[6]( + vec2( 1.0, 1.0), // 右上 - 三角形1 + vec2(-1.0, 1.0), // 左上 - 三角形1 + vec2(-1.0, -1.0), // 左下 - 三角形1 + + vec2(-1.0, -1.0), // 左下 - 三角形2 + vec2( 1.0, -1.0), // 右下 - 三角形2 + vec2( 1.0, 1.0) // 右上 - 三角形2 +); + +// 输出变量 +layout(location = 0) out vec2 outPosition; void main() { - // 使用NDC坐标(-1到1),并为四个顶点分配位置 - vec2 positions[4] = vec2[]( - vec2(-1.0, -1.0), vec2(1.0, -1.0), - vec2(-1.0, 1.0), vec2(1.0, 1.0) - ); + // 获取顶点位置 + vec2 position = positions[gl_VertexIndex]; - uv = positions[gl_VertexIndex].xy * 0.5 + 0.5; - gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0); + // 设置输出位置(Vulkan使用不同的坐标系) + gl_Position = vec4(position, 0.0, 1.0); + + // 输出位置坐标(如果需要传递给片段着色器) + outPosition = position; } \ No newline at end of file diff --git a/shaders/texture_loading/glsl/bg.vert.spv b/shaders/texture_loading/glsl/bg.vert.spv index 7271ea0..5d1f271 100644 Binary files a/shaders/texture_loading/glsl/bg.vert.spv and b/shaders/texture_loading/glsl/bg.vert.spv differ