This commit is contained in:
xsl
2025-09-15 22:31:52 +08:00
parent bf8a14f549
commit 2e059eef07
3 changed files with 9 additions and 24 deletions
Binary file not shown.
+9 -24
View File
@@ -1,29 +1,14 @@
#version 450
// 在没有顶点缓冲区的情况下,通过顶点ID生成全屏 quad
// 顶点ID: 0=(-1,-1), 1=(1,-1), 2=(-1,1), 3=(1,1)
out gl_PerVertex {
vec4 gl_Position;
};
layout(location = 0) out vec2 outUV;
layout(location = 0) out vec2 uv;
void main() {
vec2 pos;
vec2 uv;
if (gl_VertexIndex == 0) {
pos = vec2(-1.0, -1.0);
uv = vec2(0.0, 0.0);
} else if (gl_VertexIndex == 1) {
pos = vec2(1.0, -1.0);
uv = vec2(1.0, 0.0);
} else if (gl_VertexIndex == 2) {
pos = vec2(-1.0, 1.0);
uv = vec2(0.0, 1.0);
} else { // gl_VertexIndex == 3
pos = vec2(1.0, 1.0);
uv = vec2(1.0, 1.0);
}
gl_Position = vec4(pos, 0.0, 1.0);
outUV = uv;
// 使用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)
);
uv = positions[gl_VertexIndex].xy * 0.5 + 0.5;
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
}
Binary file not shown.