阿斯蒂芬

This commit is contained in:
xsl
2025-09-22 22:20:49 +08:00
parent b5f1e076a0
commit 2acce4ad70
3 changed files with 10 additions and 30 deletions
+10 -29
View File
@@ -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;
}
Binary file not shown.
@@ -22,7 +22,6 @@ void main() {
fragColor = inColor;
// 传递裁剪空间坐标
fragLineStart = (worldviewproj * vec4(inLineStart, 1.0)).xyz;
fragLineEnd = (worldviewproj * vec4(inLineEnd, 1.0)).xyz;
}