diff --git a/android/src/main/cpp/graphics/shader/ColorLineGroup2dShaderOpenGl.cpp b/android/src/main/cpp/graphics/shader/ColorLineGroup2dShaderOpenGl.cpp index cf2841078..4243760b6 100644 --- a/android/src/main/cpp/graphics/shader/ColorLineGroup2dShaderOpenGl.cpp +++ b/android/src/main/cpp/graphics/shader/ColorLineGroup2dShaderOpenGl.cpp @@ -192,8 +192,16 @@ std::string ColorLineGroup2dShaderOpenGl::getFragmentShader() { int iCapType = int(floor(lineValues[int(fStyleIndexBase) + 12] + 0.5)); float lineLength = length(pointBDeltaA); float t = dot(pointDeltaA, normalize(pointBDeltaA)) / lineLength; + + int dashBase = int(fStyleIndexBase) + 13; + // dash values: {int numDashInfo, vec4 dashArray} -> stride = 5 + int numDashInfos = int(floor(lineValues[dashBase] + 0.5)); + float d; if (t < 0.0 || t > 1.0) { + if (numDashInfos > 0) { + discard; + } if (segmentType == 0 || iCapType == 1 || (segmentType == 2 && t < 0.0) || (segmentType == 1 && t > 1.0)) { d = min(length(pointDeltaA), length(pointDeltaA - pointBDeltaA)); } else if (iCapType == 2) { @@ -216,9 +224,6 @@ std::string ColorLineGroup2dShaderOpenGl::getFragmentShader() { vec4 fragColor = color; float opacity = lineValues[int(fStyleIndexBase) + 10]; - int dashBase = int(fStyleIndexBase) + 13; - // dash values: {int numDashInfo, vec4 dashArray} -> stride = 5 - int numDashInfos = int(floor(lineValues[dashBase] + 0.5)); if (numDashInfos > 0) { int gapColorIndexBase = int(fStyleIndexBase) + 5; vec4 gapColor = vec4(lineValues[gapColorIndexBase], lineValues[gapColorIndexBase + 1], diff --git a/ios/graphics/Shader/Metal/LineShader.metal b/ios/graphics/Shader/Metal/LineShader.metal index 8ac83c4a9..656ba036d 100644 --- a/ios/graphics/Shader/Metal/LineShader.metal +++ b/ios/graphics/Shader/Metal/LineShader.metal @@ -139,9 +139,14 @@ lineGroupFragmentShader(LineVertexOut in [[stage_in]], int capType = int(styling[in.stylingIndex + 12]); char segmentType = in.segmentType; + float numDash = styling[in.stylingIndex + 13]; + float d; if (t < 0.0 || t > 1.0) { + if (numDash > 0) { + discard_fragment(); + } if (segmentType == 0 || capType == 1 || (segmentType == 2 && t < 0.0) || (segmentType == 1 && t > 1.0)) { d = min(length(in.lineA), length(in.lineA - in.lineB)); } else if (capType == 2) { @@ -176,8 +181,6 @@ lineGroupFragmentShader(LineVertexOut in [[stage_in]], } } - float numDash = styling[in.stylingIndex + 13]; - if(numDash > 0) { float dashArray[4] = { styling[in.stylingIndex + 14], styling[in.stylingIndex + 15],