From 2acce4ad70d99b5786995a5627e719ea5394e05b Mon Sep 17 00:00:00 2001 From: Xiang Silian Date: Mon, 22 Sep 2025 22:20:49 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=BF=E6=96=AF=E8=92=82=E8=8A=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shaders/texture_loading/glsl/point_line.frag | 39 +++++------------- .../texture_loading/glsl/point_line.frag.spv | Bin 2844 -> 1568 bytes shaders/texture_loading/glsl/point_line.vert | 1 - 3 files changed, 10 insertions(+), 30 deletions(-) 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 c2b932b2d7ad8871b5b6ab0a9f53556f3d46422a..01b5ff5bde518e8ed5d9f998c34bcf9b66b6525a 100644 GIT binary patch literal 1568 zcmYk5TW`}q5QUefX-lt^mU4%La<2%twiFN)h)P~8B@o_C6r0MDu`9Rsgn zndt$ZzQD{1&egdq-ziII!<>So@GUnQq3f-dR;Q7(#V|7L!#PI2XS>scmIg^k3$7E>1%xz7E zzE^BHGc7szFP1wYpL@i}$s6EY&QtQ?=9Q5er)BiTdx^Q+XXW#au}?NPJBpr|>*>6F zdirWL4f*Kcsn5(BGFShCeD@~muglPUw)Zc}M*~lfy!(=j9-qmGleei8-t}==KAgi> zxiCve$u`~F8R1qJJob2cw8Ti6I1s))3Qh6%gat2j?Jjj%yz(^{rK( z=~I79#S`Ke^$mntsq33FJB&Ee*6g+RnwdR&_SmB%Q)`_2$Zc>N-OsN4wz?59PTaU3 zYxTwY^swkmpFDLO#U?lEg=jXr^=?cf_NW&8wnj^L)?|6hEdjI5#X>gTmu+pF8vF%3*PpA9bH8o@5=(sra** zX3leCZc1_TzLE~S=1{=(B{apg$e$Opc`qL*>^bVgT1Jx7d2vNfs->nX+#lpm zsYk9VbDnu|?Or}ihD9S!Gt&3`4UL^tC(7E%t(;SoYb=Tc-12*#GP{~`r_LK>)D=uG?2*wgVEO_~4}j?rFdvwD7~Uoo zx_!QD$~imbkBgg>?UJ6J0;8K0UaJufBfefEar%QexseO}xq!(T4*eF5=;?CwTQw4c zM-S#qa7TsF?vUx5G5o2A|IC`6Goxp{gBmSo(;xHt-)6S!6kiA33611nd4j1GoUKc( z;ymVr`E1==9=)m>e(3T1<P1cXSo5uzibmF^hP)s0G|YX*nD-FlsR$pGe<;GN zM^Brccs0Vr=Oavh1g;Q6TQMOB76 z5Mv%auuaDO+q~_8gXd%3pQh1u}>UYVwT5#`S6wp_YOxM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