diff --git a/shaders/texture_loading/glsl/point_line.frag b/shaders/texture_loading/glsl/point_line.frag index 2104ed2..818bbec 100644 --- a/shaders/texture_loading/glsl/point_line.frag +++ b/shaders/texture_loading/glsl/point_line.frag @@ -9,38 +9,19 @@ layout(location = 0) out vec4 outColor; void main() { vec2 fragPos = gl_FragCoord.xy; - vec2 start = (fragLineStart.xy * 0.5 + 0.5) * 480.0; - vec2 end = (fragLineEnd.xy * 0.5 + 0.5) * 480.0; + // 网格参数 + float gridSize = 14.0; // 网格大小 + float dotRadius = 7.0; // 点状半径 - vec2 lineDir = end - start; - float lineLength = length(lineDir); + // 计算当前片段所在的网格和网格中心坐标 + vec2 gridCoord = fragPos / gridSize; + vec2 gridCenter = (floor(gridCoord) + 0.5) * gridSize; - if (lineLength < 1.0) { - outColor = vec4(fragColor, 1.0); - return; - } + // 计算片段到网格中心的距离 + float distanceToCenter = length(fragPos - gridCenter); - lineDir = normalize(lineDir); - vec2 toFrag = fragPos - start; - float projection = dot(toFrag, lineDir); - projection = clamp(projection, 0.0, lineLength); - - vec2 closestPoint = start + lineDir * projection; - float distanceToLine = length(fragPos - closestPoint); - - float lineWidth = 6.0; - - if (distanceToLine > lineWidth) { - discard; - } - - float dashLength = 50.0; - float gapLength = 20.0; - - float patternLength = dashLength + gapLength; - float patternPos = mod(projection, patternLength); - - if (patternPos > dashLength) { + // 如果距离超过点状半径,丢弃(创建点状虚线) + if (distanceToCenter > dotRadius) { discard; } diff --git a/shaders/texture_loading/glsl/point_line.frag.spv b/shaders/texture_loading/glsl/point_line.frag.spv index c2b932b..01b5ff5 100644 Binary files a/shaders/texture_loading/glsl/point_line.frag.spv and b/shaders/texture_loading/glsl/point_line.frag.spv differ diff --git a/shaders/texture_loading/glsl/point_line.vert b/shaders/texture_loading/glsl/point_line.vert index f5a0665..cc00794 100644 --- a/shaders/texture_loading/glsl/point_line.vert +++ b/shaders/texture_loading/glsl/point_line.vert @@ -22,7 +22,6 @@ void main() { fragColor = inColor; - // 传递裁剪空间坐标 fragLineStart = (worldviewproj * vec4(inLineStart, 1.0)).xyz; fragLineEnd = (worldviewproj * vec4(inLineEnd, 1.0)).xyz; } \ No newline at end of file