export declare enum Location { BARYCENTRIC = 0, PREV = 1, POINTA = 2, POINTB = 3, NEXT = 4, VERTEX_JOINT = 5, VERTEX_NUM = 6, TRAVEL = 7 } export declare enum JointType { NONE = 0, FILL = 1, JOINT_BEVEL = 4, JOINT_MITER = 8, JOINT_ROUND = 12, JOINT_CAP_BUTT = 16, JOINT_CAP_SQUARE = 18, JOINT_CAP_ROUND = 20, FILL_EXPAND = 24, CAP_BUTT = 32, CAP_SQUARE = 64, CAP_ROUND = 96, CAP_BUTT2 = 128 } export declare const vert = "\nlayout(std140) uniform SceneUniforms {\n mat3 u_ProjectionMatrix;\n mat3 u_ViewMatrix;\n mat3 u_ViewProjectionInvMatrix;\n vec4 u_BackgroundColor;\n vec4 u_GridColor;\n float u_ZoomScale;\n float u_CheckboardStyle;\n vec2 u_Viewport;\n};\n\n\n#ifdef USE_WIREFRAME\n layout(location = 0) in vec3 a_Barycentric;\n out vec3 v_Barycentric;\n#endif\n\nlayout(location = 1) in vec2 a_Prev;\nlayout(location = 2) in vec2 a_PointA;\nlayout(location = 3) in vec2 a_PointB;\nlayout(location = 4) in vec2 a_Next;\nlayout(location = 5) in float a_VertexJoint;\nlayout(location = 6) in float a_VertexNum;\nlayout(location = 7) in float a_Travel;\n\nlayout(std140) uniform ShapeUniforms {\n mat3 u_ModelMatrix;\n vec4 u_StrokeColor;\n vec4 u_ZIndexStrokeWidth;\n vec4 u_Opacity;\n vec4 u_StrokeDash;\n};\n\nconst float FILL = 1.0;\nconst float BEVEL = 4.0;\nconst float MITER = 8.0;\nconst float ROUND = 12.0;\nconst float JOINT_CAP_BUTT = 16.0;\nconst float JOINT_CAP_SQUARE = 18.0;\nconst float JOINT_CAP_ROUND = 20.0;\nconst float FILL_EXPAND = 24.0;\nconst float CAP_BUTT = 1.0;\nconst float CAP_SQUARE = 2.0;\nconst float CAP_ROUND = 3.0;\nconst float CAP_BUTT2 = 4.0;\n\nconst float expand = 1.0;\nconst float dpr = 2.0;\n\nout vec4 v_Distance;\nout vec4 v_Arc;\nout float v_Type;\nout float v_Travel;\nout float v_ScalingFactor;\n#ifdef USE_INSTANCES\n out vec4 v_StrokeColor;\n out vec4 v_Opacity;\n out float v_StrokeAlignment;\n#else\n#endif\n\nvec2 doBisect(\n vec2 norm, float len, vec2 norm2, float len2, float dy, float inner\n) {\n vec2 bisect = (norm + norm2) / 2.0;\n bisect /= dot(norm, bisect);\n if (inner > 0.5) {\n if (len < len2) {\n if (abs(dy * (bisect.x * norm.y - bisect.y * norm.x)) > len) {\n return dy * norm;\n }\n } else {\n if (abs(dy * (bisect.x * norm2.y - bisect.y * norm2.x)) > len2) {\n return dy * norm;\n }\n }\n }\n return dy * bisect;\n}\n\n// vec2 clip2ScreenSpace(vec4 clip) {\n// return u_Viewport * (0.5 * clip.xy / clip.w + 0.5);\n// }\n\nvoid main() {\n \n#ifdef USE_WIREFRAME\n v_Barycentric = a_Barycentric;\n#endif\n\n\n mat3 model = u_ModelMatrix;\n vec4 strokeColor = u_StrokeColor;\n float zIndex = u_ZIndexStrokeWidth.x;\n float strokeWidth = u_ZIndexStrokeWidth.y;\n float strokeMiterlimit = u_ZIndexStrokeWidth.z;\n float strokeAlignment = u_ZIndexStrokeWidth.w;\n bool strokeAttenuation = u_Opacity.w > 0.5;\n\n if (strokeAttenuation) {\n strokeWidth /= u_ZoomScale;\n }\n\n vec2 pointA;\n vec2 pointB;\n // vec4 clip0 = vec4((u_ProjectionMatrix \n // * u_ViewMatrix\n // * model\n // * vec3(a_PointA, 1)).xy, zIndex, 1);;\n // vec4 clip1 = vec4((u_ProjectionMatrix \n // * u_ViewMatrix\n // * model\n // * vec3(a_PointB, 1)).xy, zIndex, 1);;\n\n // if (sizeAttenuation) {\n // pointA = clip2ScreenSpace(clip0);\n // pointB = clip2ScreenSpace(clip1);\n // } else {\n pointA = (model * vec3(a_PointA, 1.0)).xy;\n pointB = (model * vec3(a_PointB, 1.0)).xy;\n // }\n\n vec2 xBasis = pointB - pointA;\n float len = length(xBasis);\n vec2 forward = xBasis / len;\n vec2 norm = vec2(forward.y, -forward.x);\n\n float type = a_VertexJoint;\n float vertexNum = a_VertexNum;\n\n float capType = floor(type / 32.0);\n type -= capType * 32.0;\n v_Arc = vec4(0.0);\n strokeWidth *= 0.5;\n float strokeAlignmentFactor = 2.0 * strokeAlignment - 1.0;\n\n vec2 pos;\n\n if (capType == CAP_ROUND) {\n if (vertexNum < 3.5) {\n gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n return;\n }\n type = JOINT_CAP_ROUND;\n capType = 0.0;\n }\n\n if (type >= BEVEL) {\n float dy = strokeWidth + expand;\n float inner = 0.0;\n if (vertexNum >= 1.5) {\n dy = -dy;\n inner = 1.0;\n }\n\n vec2 base, next, xBasis2, bisect;\n float flag = 0.0;\n float sign2 = 1.0;\n if (vertexNum < 0.5 || vertexNum > 2.5 && vertexNum < 3.5) {\n // if (sizeAttenuation) {\n // next = clip2ScreenSpace(vec4((u_ProjectionMatrix \n // * u_ViewMatrix\n // * model\n // * vec3(a_Prev, 1)).xy, zIndex, 1));\n // } else {\n next = (model * vec3(a_Prev, 1.0)).xy;\n // }\n\n base = pointA;\n flag = type - floor(type / 2.0) * 2.0;\n sign2 = -1.0;\n } else {\n // if (sizeAttenuation) {\n // next = clip2ScreenSpace(vec4((u_ProjectionMatrix \n // * u_ViewMatrix\n // * model\n // * vec3(a_Next, 1)).xy, zIndex, 1));\n // } else {\n next = (model * vec3(a_Next, 1.0)).xy;\n // }\n\n base = pointB;\n if (type >= MITER && type < MITER + 3.5) {\n flag = step(MITER + 1.5, type);\n // check miter limit here?\n }\n }\n\n xBasis2 = next - base;\n float len2 = length(xBasis2);\n vec2 norm2 = vec2(xBasis2.y, -xBasis2.x) / len2;\n float D = norm.x * norm2.y - norm.y * norm2.x;\n if (D < 0.0) {\n inner = 1.0 - inner;\n }\n norm2 *= sign2;\n\n if (abs(strokeAlignmentFactor) > 0.01) {\n float shift = strokeWidth * strokeAlignmentFactor;\n pointA += norm * shift;\n pointB += norm * shift;\n if (abs(D) < 0.01) {\n base += norm * shift;\n } else {\n base += doBisect(norm, len, norm2, len2, shift, 0.0);\n }\n }\n\n float collinear = step(0.0, dot(norm, norm2));\n v_Type = 0.0;\n float dy2 = -1000.0;\n float dy3 = -1000.0;\n if (abs(D) < 0.01 && collinear < 0.5) {\n if (type >= ROUND && type < ROUND + 1.5) {\n type = JOINT_CAP_ROUND;\n }\n // TODO: BUTT here too\n }\n\n if (vertexNum < 3.5) {\n if (abs(D) < 0.01) {\n pos = dy * norm;\n } else {\n if (flag < 0.5 && inner < 0.5) {\n pos = dy * norm;\n } else {\n pos = doBisect(norm, len, norm2, len2, dy, inner);\n }\n }\n if (capType >= CAP_BUTT && capType < CAP_ROUND) {\n float extra = step(CAP_SQUARE, capType) * strokeWidth;\n vec2 back = -forward;\n if (vertexNum < 0.5 || vertexNum > 2.5) {\n pos += back * (expand + extra);\n dy2 = expand;\n } else {\n dy2 = dot(pos + base - pointA, back) - extra;\n }\n }\n if (type >= JOINT_CAP_BUTT && type < JOINT_CAP_SQUARE + 0.5) {\n float extra = step(JOINT_CAP_SQUARE, type) * strokeWidth;\n if (vertexNum < 0.5 || vertexNum > 2.5) {\n dy3 = dot(pos + base - pointB, forward) - extra;\n } else {\n pos += forward * (expand + extra);\n dy3 = expand;\n if (capType >= CAP_BUTT) {\n dy2 -= expand + extra;\n }\n }\n }\n } else if (type >= JOINT_CAP_ROUND && type < JOINT_CAP_ROUND + 1.5) {\n if (inner > 0.5) {\n dy = -dy;\n inner = 0.0;\n }\n vec2 d2 = abs(dy) * forward;\n if (vertexNum < 4.5) {\n dy = -dy;\n pos = dy * norm;\n } else if (vertexNum < 5.5) {\n pos = dy * norm;\n } else if (vertexNum < 6.5) {\n pos = dy * norm + d2;\n v_Arc.x = abs(dy);\n } else {\n dy = -dy;\n pos = dy * norm + d2;\n v_Arc.x = abs(dy);\n }\n dy2 = 0.0;\n v_Arc.y = dy;\n v_Arc.z = 0.0;\n v_Arc.w = strokeWidth;\n v_Type = 3.0;\n } else if (abs(D) < 0.01) {\n pos = dy * norm;\n } else {\n if (type >= ROUND && type < ROUND + 1.5) {\n if (inner > 0.5) {\n dy = -dy;\n inner = 0.0;\n }\n if (vertexNum < 4.5) {\n pos = doBisect(norm, len, norm2, len2, -dy, 1.0);\n } else if (vertexNum < 5.5) {\n pos = dy * norm;\n } else if (vertexNum > 7.5) {\n pos = dy * norm2;\n } else {\n pos = doBisect(norm, len, norm2, len2, dy, 0.0);\n float d2 = abs(dy);\n if (length(pos) > abs(dy) * 1.5) {\n if (vertexNum < 6.5) {\n pos.x = dy * norm.x - d2 * norm.y;\n pos.y = dy * norm.y + d2 * norm.x;\n } else {\n pos.x = dy * norm2.x + d2 * norm2.y;\n pos.y = dy * norm2.y - d2 * norm2.x;\n }\n }\n }\n vec2 norm3 = normalize(norm + norm2);\n\n float sign = step(0.0, dy) * 2.0 - 1.0;\n v_Arc.x = sign * dot(pos, norm3);\n v_Arc.y = pos.x * norm3.y - pos.y * norm3.x;\n v_Arc.z = dot(norm, norm3) * strokeWidth;\n v_Arc.w = strokeWidth;\n\n dy = -sign * dot(pos, norm);\n dy2 = -sign * dot(pos, norm2);\n dy3 = v_Arc.z - v_Arc.x;\n v_Type = 3.0;\n } else {\n float hit = 0.0;\n if (type >= BEVEL && type < BEVEL + 1.5) {\n if (dot(norm, norm2) > 0.0) {\n type = MITER;\n }\n }\n if (type >= MITER && type < MITER + 3.5) {\n if (inner > 0.5) {\n dy = -dy;\n inner = 0.0;\n }\n float sign = step(0.0, dy) * 2.0 - 1.0;\n pos = doBisect(norm, len, norm2, len2, dy, 0.0);\n if (length(pos) > abs(dy) * strokeMiterlimit) {\n type = BEVEL;\n } else {\n if (vertexNum < 4.5) {\n dy = -dy;\n pos = doBisect(norm, len, norm2, len2, dy, 1.0);\n } else if (vertexNum < 5.5) {\n pos = dy * norm;\n } else if (vertexNum > 6.5) {\n pos = dy * norm2;\n }\n v_Type = 1.0;\n dy = -sign * dot(pos, norm);\n dy2 = -sign * dot(pos, norm2);\n hit = 1.0;\n }\n }\n if (type >= BEVEL && type < BEVEL + 1.5) {\n if (inner > 0.5) {\n dy = -dy;\n inner = 0.0;\n }\n float d2 = abs(dy);\n vec2 pos3 = vec2(dy * norm.x - d2 * norm.y, dy * norm.y + d2 * norm.x);\n vec2 pos4 = vec2(dy * norm2.x + d2 * norm2.y, dy * norm2.y - d2 * norm2.x);\n if (vertexNum < 4.5) {\n pos = doBisect(norm, len, norm2, len2, -dy, 1.0);\n } else if (vertexNum < 5.5) {\n pos = dy * norm;\n } else if (vertexNum > 7.5) {\n pos = dy * norm2;\n } else {\n if (vertexNum < 6.5) {\n pos = pos3;\n } else {\n pos = pos4;\n }\n }\n vec2 norm3 = normalize(norm + norm2);\n float sign = step(0.0, dy) * 2.0 - 1.0;\n dy = -sign * dot(pos, norm);\n dy2 = -sign * dot(pos, norm2);\n dy3 = (-sign * dot(pos, norm3)) + strokeWidth;\n v_Type = 4.0;\n hit = 1.0;\n }\n if (hit < 0.5) {\n gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n return;\n }\n }\n }\n pos += base;\n v_Distance = vec4(dy, dy2, dy3, strokeWidth) * dpr;\n v_Arc *= dpr;\n v_Travel = a_Travel + dot(pos - pointA, vec2(-norm.y, norm.x));\n }\n\n // v_ScalingFactor = sqrt(model[0][0] * model[0][0] + model[0][1] * model[0][1] + model[0][2] * model[0][2]);\n v_ScalingFactor = 1.0;\n\n // if (sizeAttenuation) {\n // vec4 clip = mix(clip0, clip1, 0.5);\n // gl_Position = vec4(clip.w * (2.0 * pos / u_Viewport - 1.0), clip.z, clip.w);\n // } else {\n gl_Position = vec4((u_ProjectionMatrix \n * u_ViewMatrix\n * vec3(pos, 1)).xy, zIndex, 1);\n // }\n}\n"; export declare const frag = "\nlayout(std140) uniform SceneUniforms {\n mat3 u_ProjectionMatrix;\n mat3 u_ViewMatrix;\n mat3 u_ViewProjectionInvMatrix;\n vec4 u_BackgroundColor;\n vec4 u_GridColor;\n float u_ZoomScale;\n float u_CheckboardStyle;\n vec2 u_Viewport;\n};\n\nlayout(std140) uniform ShapeUniforms {\n mat3 u_ModelMatrix;\n vec4 u_StrokeColor;\n vec4 u_ZIndexStrokeWidth;\n vec4 u_Opacity;\n vec4 u_StrokeDash;\n};\n\nout vec4 outputColor;\n\n\n#ifdef USE_WIREFRAME\n in vec3 v_Barycentric;\n\n float edgeFactor() {\n float u_WireframeLineWidth = 1.0;\n vec3 d = fwidth(v_Barycentric);\n vec3 a3 = smoothstep(vec3(0.0), d * u_WireframeLineWidth, v_Barycentric);\n return min(min(a3.x, a3.y), a3.z);\n }\n#endif\n\nin vec4 v_Distance;\nin vec4 v_Arc;\nin float v_Type;\nin float v_Travel;\nin float v_ScalingFactor;\n\nfloat epsilon = 0.000001;\n\nfloat antialias(float distance) {\n return clamp(distance / fwidth(distance), 0.0, 1.0);\n}\n\nfloat pixelLine(float x) {\n return clamp(x + 0.5, 0.0, 1.0);\n}\n// float pixelLine(float x, float A, float B) {\n// float y = abs(x), s = sign(x);\n// if (y * 2.0 < A - B) {\n// return 0.5 + s * y / A;\n// }\n// y -= (A - B) * 0.5;\n// y = max(1.0 - y / B, 0.0);\n// return (1.0 + s * (1.0 - y * y)) * 0.5;\n// //return clamp(x + 0.5, 0.0, 1.0);\n// }\n\nvoid main() {\n vec4 strokeColor = u_StrokeColor;\n float opacity = u_Opacity.x;\n float strokeOpacity = u_Opacity.z;\n bool strokeAttenuation = u_Opacity.w > 0.5;\n float strokeAlignment = u_ZIndexStrokeWidth.w;\n float alpha = 1.0;\n\n float d1 = v_Distance.x;\n float d2 = v_Distance.y;\n float d3 = v_Distance.z;\n float w = v_Distance.w;\n\n if (v_Type < 0.5) {\n float left = max(d1 - 0.5, -w);\n float right = min(d1 + 0.5, w);\n float near = d2 - 0.5;\n float far = min(d2 + 0.5, 0.0);\n float top = d3 - 0.5;\n float bottom = min(d3 + 0.5, 0.0);\n alpha = max(antialias(right - left), 0.0) * max(bottom - top, 0.0) * max(far - near, 0.0);\n } else if (v_Type < 1.5) {\n float a1 = pixelLine(d1 - w);\n float a2 = pixelLine(d1 + w);\n float b1 = pixelLine(d2 - w);\n float b2 = pixelLine(d2 + w);\n\n float left = max(d1 - 0.5, -w);\n float right = min(d1 + 0.5, w);\n \n alpha = antialias(a2 * b2 - a1 * b1);\n } else if (v_Type < 2.5) {\n alpha *= max(min(d1 + 0.5, 1.0), 0.0);\n alpha *= max(min(d2 + 0.5, 1.0), 0.0);\n alpha *= max(min(d3 + 0.5, 1.0), 0.0);\n } else if (v_Type < 3.5) {\n float a1 = pixelLine(d1 - w);\n float a2 = pixelLine(d1 + w);\n float b1 = pixelLine(d2 - w);\n float b2 = pixelLine(d2 + w);\n float alpha_miter = a2 * b2 - a1 * b1;\n float alpha_bevel = pixelLine(d3);\n \n float r = length(v_Arc.xy);\n float circle_hor = pixelLine(w + r) - pixelLine(-w + r);\n float circle_vert = min(w * 2.0, 1.0);\n float alpha_circle = circle_hor * circle_vert;\n alpha = min(alpha_miter, max(alpha_circle, alpha_bevel));\n } else {\n float a1 = pixelLine(d1 - w);\n float a2 = pixelLine(d1 + w);\n float b1 = pixelLine(d2 - w);\n float b2 = pixelLine(d2 + w);\n alpha = antialias(a2 * b2 - a1 * b1);\n alpha *= pixelLine(d3);\n }\n\n float u_Dash = u_StrokeDash.x;\n float u_Gap = u_StrokeDash.y;\n float u_DashOffset = u_StrokeDash.z;\n\n float scalingFactor = v_ScalingFactor;\n float travelScalingFactor = 1.0;\n if (strokeAttenuation) {\n travelScalingFactor = u_ZoomScale;\n }\n\n if (u_Dash + u_Gap > 1.0) {\n float travel = mod(v_Travel * travelScalingFactor + u_Gap * scalingFactor * 0.5 + u_DashOffset, u_Dash * scalingFactor + u_Gap * scalingFactor) - (u_Gap * scalingFactor * 0.5);\n float left = max(travel - 0.5, -0.5);\n float right = min(travel + 0.5, u_Gap * v_ScalingFactor + 0.5);\n alpha *= antialias(max(0.0, right - left));\n }\n\n outputColor = strokeColor;\n outputColor.a *= alpha * opacity * strokeOpacity;\n\n \n#ifdef USE_WIREFRAME\n vec3 u_WireframeLineColor = vec3(0.0, 0.0, 0.0);\n\n outputColor.xyz = mix(outputColor.xyz, u_WireframeLineColor, (1.0 - edgeFactor()));\n if (any(lessThan(v_Barycentric, vec3(0.01)))) {\n outputColor.a = 0.95;\n }\n#endif\n\n \n #ifndef USE_STENCIL\n if (outputColor.a < epsilon) {\n discard;\n }\n #endif\n}\n";