diff --git a/packages/layers/src/line/shaders/line_arc_3d_frag.glsl b/packages/layers/src/line/shaders/line_arc_3d_frag.glsl index ca4b162623..e4df635985 100644 --- a/packages/layers/src/line/shaders/line_arc_3d_frag.glsl +++ b/packages/layers/src/line/shaders/line_arc_3d_frag.glsl @@ -7,9 +7,8 @@ uniform float u_opacity; uniform float u_textureBlend; uniform float u_blur : 0.9; uniform float u_line_type: 0.0; -varying vec2 v_normal; +// varying vec2 v_normal; varying vec4 v_dash_array; -varying float v_distance_ratio; varying vec4 v_color; uniform float u_line_texture: 0.0; @@ -17,10 +16,9 @@ uniform sampler2D u_texture; uniform vec2 u_textSize; varying float v_segmentIndex; uniform float segmentNumber; -varying float v_arcDistrance; -varying float v_pixelLen; -varying float v_a; -varying vec2 v_offset; + +varying vec4 v_dataset; // 数据集 + varying vec2 v_iconMapUV; uniform float u_time; @@ -37,6 +35,7 @@ varying mat4 styleMappingMat; void main() { float opacity = styleMappingMat[0][0]; float animateSpeed = 0.0; // 运动速度 + float d_distance_ratio = v_dataset.g; // 当前点位距离占线总长的比例 if(u_linearColor == 1.0) { // 使用渐变颜色 gl_FragColor = mix(u_sourceColor, u_targetColor, v_segmentIndex/segmentNumber); @@ -49,7 +48,7 @@ void main() { gl_FragColor.a *= opacity; if(u_line_type == LineTypeDash) { float flag = 0.; - float dashLength = mod(v_distance_ratio, v_dash_array.x + v_dash_array.y + v_dash_array.z + v_dash_array.w); + float dashLength = mod(d_distance_ratio, v_dash_array.x + v_dash_array.y + v_dash_array.z + v_dash_array.w); if(dashLength < v_dash_array.x || (dashLength > (v_dash_array.x + v_dash_array.y) && dashLength < v_dash_array.x + v_dash_array.y + v_dash_array.z)) { flag = 1.; } @@ -58,7 +57,7 @@ void main() { if(u_aimate.x == Animate) { animateSpeed = u_time / u_aimate.y; - float alpha =1.0 - fract( mod(1.0- v_distance_ratio, u_aimate.z)* (1.0/ u_aimate.z) + u_time / u_aimate.y); + float alpha =1.0 - fract( mod(1.0- d_distance_ratio, u_aimate.z)* (1.0/ u_aimate.z) + u_time / u_aimate.y); alpha = (alpha + u_aimate.w -1.0) / u_aimate.w; // alpha = smoothstep(0., 1., alpha); @@ -69,15 +68,15 @@ void main() { if(u_line_texture == LineTexture && u_line_type != LineTypeDash) { // while load texture // float arcRadio = smoothstep( 0.0, 1.0, (v_segmentIndex / segmentNumber)); float arcRadio = v_segmentIndex / (segmentNumber - 1.0); - float count = floor(v_arcDistrance/v_pixelLen); + float count = v_dataset.b; // // 贴图在弧线上重复的数量 float u = fract(arcRadio * count - animateSpeed * count); if(u_aimate.x == Animate) { u = gl_FragColor.a/opacity; } - float v = length(v_offset)/(v_a); // 横向 + float v = v_dataset.a; // 线图层贴图部分的 v 坐标值 vec2 uv= v_iconMapUV / u_textSize + vec2(u, v) / u_textSize * 64.; vec4 pattern = texture2D(u_texture, uv); diff --git a/packages/layers/src/line/shaders/line_arc_3d_vert.glsl b/packages/layers/src/line/shaders/line_arc_3d_vert.glsl index 8d15ce54a3..ce8ede29ea 100644 --- a/packages/layers/src/line/shaders/line_arc_3d_vert.glsl +++ b/packages/layers/src/line/shaders/line_arc_3d_vert.glsl @@ -12,8 +12,7 @@ uniform mat4 u_Mvp; uniform float segmentNumber; uniform vec4 u_aimate: [ 0, 2., 1.0, 0.2 ]; varying vec4 v_color; -varying vec2 v_normal; -varying float v_distance_ratio; +// varying vec2 v_normal; uniform float u_line_type: 0.0; uniform vec4 u_dash_array: [10.0, 5., 0, 0]; varying vec4 v_dash_array; @@ -21,10 +20,9 @@ varying vec4 v_dash_array; uniform float u_icon_step: 100; uniform float u_line_texture: 0.0; varying float v_segmentIndex; -varying float v_arcDistrance; -varying float v_pixelLen; -varying float v_a; -varying vec2 v_offset; + +varying vec4 v_dataset; // 数据集 + attribute vec2 a_iconMapUV; varying vec2 v_iconMapUV; @@ -114,8 +112,9 @@ void main() { float segmentRatio = getSegmentRatio(segmentIndex); float indexDir = mix(-1.0, 1.0, step(segmentIndex, 0.0)); + float d_distance_ratio; if(u_line_type == LineTypeDash) { - v_distance_ratio = segmentIndex / segmentNumber; + d_distance_ratio = segmentIndex / segmentNumber; // float total_Distance = pixelDistance(a_Instance.rg, a_Instance.ba) / 2.0 * PI; vec2 s = source; vec2 t = target; @@ -128,24 +127,29 @@ void main() { v_dash_array = pow(2.0, 20.0 - u_Zoom) * u_dash_array / (total_Distance / segmentNumber * segmentIndex); } if(u_aimate.x == Animate) { - v_distance_ratio = segmentIndex / segmentNumber; + d_distance_ratio = segmentIndex / segmentNumber; } + v_dataset.g = d_distance_ratio; // 当前点位距离占线总长的比例 float nextSegmentRatio = getSegmentRatio(segmentIndex + indexDir); vec3 curr = getPos(source, target, segmentRatio); vec3 next = getPos(source, target, nextSegmentRatio); vec2 offset = getExtrusionOffset((next.xy - curr.xy) * indexDir, a_Position.y); - v_normal = getNormal((next.xy - curr.xy) * indexDir, a_Position.y); + // v_normal = getNormal((next.xy - curr.xy) * indexDir, a_Position.y); v_segmentIndex = a_Position.x; if(LineTexture == u_line_texture && u_line_type != LineTypeDash) { // 开启贴图模式 - v_arcDistrance = length(source - target); - v_pixelLen = project_pixel(u_icon_step); + + float arcDistrance = length(source - target); + float pixelLen = project_pixel(u_icon_step); + v_dataset.b = floor(arcDistrance/pixelLen); // 贴图在弧线上重复的数量 vec2 projectOffset = project_pixel(offset); - v_offset = projectOffset + projectOffset * sign(a_Position.y); - v_a = project_pixel(a_Size); + float lineOffsetWidth = length(projectOffset + projectOffset * sign(a_Position.y)); // 线横向偏移的距离 + float linePixelSize = project_pixel(a_Size); // 定点位置偏移,按地图等级缩放后的距离 + v_dataset.a = lineOffsetWidth/linePixelSize; // 线图层贴图部分的 v 坐标值 + v_iconMapUV = a_iconMapUV; } diff --git a/packages/layers/src/line/shaders/line_frag.glsl b/packages/layers/src/line/shaders/line_frag.glsl index 6b250a875b..8fb9721b1f 100644 --- a/packages/layers/src/line/shaders/line_frag.glsl +++ b/packages/layers/src/line/shaders/line_frag.glsl @@ -69,7 +69,7 @@ void main() { float aDistance = v_dataset.g; // 当前顶点的距离 float d_texPixelLen = v_dataset.b; // 贴图的像素长度,根据地图层级缩放 float u = fract(mod(aDistance, d_texPixelLen)/d_texPixelLen - animateSpeed); - float v = v_dataset.a; + float v = v_dataset.a; // 线图层贴图部分的 v 坐标值 v = max(smoothstep(0.95, 1.0, v), v); vec2 uv= v_iconMapUV / u_textSize + vec2(u, v) / u_textSize * 64.; diff --git a/packages/layers/src/line/shaders/line_vert.glsl b/packages/layers/src/line/shaders/line_vert.glsl index c09c564fc6..1dc6685177 100644 --- a/packages/layers/src/line/shaders/line_vert.glsl +++ b/packages/layers/src/line/shaders/line_vert.glsl @@ -99,7 +99,7 @@ void main() { v_dataset.r = d_distance_ratio; // 当前点位距离占线总长的比例 v_dataset.g = a_Distance; // 当前顶点的距离 v_dataset.b = d_texPixelLen; // 贴图的像素长度,根据地图层级缩放 - v_dataset.a = texV; + v_dataset.a = texV; // 线图层贴图部分的 v 坐标值 vec4 project_pos = project_position(vec4(a_Position.xy, 0, 1.0));