虚线的代码完成。

This commit is contained in:
xsl
2025-09-22 18:10:55 +08:00
parent 60afc59582
commit 3207c47dd2
4 changed files with 62 additions and 17 deletions
+12 -7
View File
@@ -2,9 +2,13 @@
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inColor;
layout(location = 2) in vec3 inLineStart;
layout(location = 3) in vec3 inLineEnd;
layout(location = 0) out vec3 fragColor;
layout(location = 1) out float fragLinePosition; // 用于虚线计算
layout(location = 1) out vec3 fragLineStart;
layout(location = 2) out vec3 fragLineEnd;
layout(binding = 0) uniform UniformBufferObject {
mat4 proj;
@@ -13,11 +17,12 @@ layout(binding = 0) uniform UniformBufferObject {
} ubo;
void main() {
mat4 mvp = ubo.proj * ubo.view * ubo.model;
gl_Position = mvp * vec4(inPosition, 1.0);
fragColor = inColor;
gl_PointSize = 2.0;
mat4 worldviewproj = ubo.proj * ubo.view * ubo.model;
gl_Position = worldviewproj * vec4(inPosition, 1.0);
// 硬编码虚线参数:使用模型空间的X坐标,你可以根据需要调整
fragLinePosition = inPosition.x;
fragColor = inColor;
// 传递裁剪空间坐标
fragLineStart = (worldviewproj * vec4(inLineStart, 1.0)).xyz;
fragLineEnd = (worldviewproj * vec4(inLineEnd, 1.0)).xyz;
}