Luxar Viewer API Documentation - v2026.9.22
    Preparing search index...

    Variable CAPSULE_LINE_PICK_FRAGMENT_SHADERConst

    CAPSULE_LINE_PICK_FRAGMENT_SHADER: "\n precision highp float;\n\n in vec2 vLocal;\n flat in vec4 vCutN;\n flat in uvec4 vPack;\n flat in float vAbLen;\n in float vFade;\n in float vSharp;\n flat in highp float vNodeId;\n flat in highp vec2 vElementId;\n\n out vec4 fragColor;\n\n // The PARTNER leg's tapered-capsule field at a pixel offset rel from\n // the shared vertex (my local frame). Its axis is my inward axis\n // reflected across the cut plane (q = m − 2(m·n)n — exact); its\n // radius starts at rEnd, the SHARED-VERTEX radius handed in by the\n // caller from the packed vPack.z lane (#1494); it tapers by the\n // packed gradient, freezes past its far end,\n // and the far cap term closes the rod there (#1490). Sharpness is\n // taken from OUR fragment — the joint region is local.\n float luxarPartnerProfile(vec4 cut, vec2 rel, float mSign, float rEnd, float sharp) {\n vec2 n = cut.xy;\n // Partner axis = my inward axis reflected across the cut plane\n // (q = m − 2(m·n)n — exact; both cut normals are normalize(q − m)\n // up to sign).\n vec2 qdir = vec2(mSign - 2.0 * (mSign * n.x) * n.x, -2.0 * (mSign * n.x) * n.y);\n float xp = dot(rel, qdir);\n float yp2 = max(dot(rel, rel) - xp * xp, 0.0);\n // Radius from the SHARED VERTEX radius (rEnd, #1494) tapered by\n // the packed gradient, FROZEN past the partner's far end; the far\n // cap term closes the rod there (#1490).\n float rp = max(rEnd + cut.z * clamp(xp, 0.0, cut.w), 1e-4);\n float op = max(max(-xp, xp - cut.w), 0.0);\n float qp = (yp2 + op * op) / (rp * rp);\n float wp = 1.0 - qp;\n if (wp <= 0.0) return 0.0;\n return (abs(sharp - 0.5) < 1e-3) ? wp * wp : pow(wp, exp2(3.0 - 4.0 * sharp));\n }\n\n void main() {\n // gl_FragCoord.w IS the perspective-interpolated 1/w (spec identity\n // — PC-interp of a per-vertex w equals 1/gl_FragCoord.w exactly), so\n // the vW varying and its per-fragment divide are both unnecessary.\n float invW = gl_FragCoord.w;\n float x = vLocal.x * invW;\n float y = vLocal.y * invW;\n // Unpack the flat joint state (see the visual twin).\n vec2 pkA = unpackHalf2x16(vPack.x);\n vec2 pkB = unpackHalf2x16(vPack.y);\n vec2 pkR = unpackHalf2x16(vPack.z);\n vec2 pkM = unpackHalf2x16(vPack.w);\n float cutFlagA = mod(pkM.y, 2.0);\n float cutFlagB = pkM.y >= 2.0 ? 1.0 : 0.0;\n float rPx;\n if (pkR.x == pkR.y) {\n rPx = max(pkR.x, 1e-4);\n } else {\n rPx = max(mix(pkR.x, pkR.y, clamp(x * pkM.x, 0.0, 1.0)), 1e-4);\n }\n // TRUE point-to-segment distance: every end is capped (a free end\n // keeps the whole disc, a cut end its half of the joint disc).\n float ox = max(max(-x, x - vAbLen), 0.0);\n float q = (y * y + ox * ox) / (rPx * rPx);\n float w = 1.0 - q;\n if (w <= 0.0) discard;\n\n float profile = (abs(vSharp - 0.5) < 1e-3)\n ? w * w\n : pow(w, exp2(3.0 - 4.0 * vSharp));\n\n // Joint DEFICIT rule (mirrors the visual capsule; see its note).\n // The cut is a 1 px AA RAMP, not a hard step: each leg's fragment\n // evaluates the plane in its OWN local frame, so pixels within float\n // noise of the line would otherwise flip independently — sprinkling\n // black (both discard) and double-bright (both keep) speckles along\n // every joint. Complementary ramps sum to exactly 1 instead, and\n // anti-alias the cut for free. The DEFICIT term blends in over the\n // same ramp: full profile on my side, max(mine − partner, 0) beyond.\n if (cutFlagA > 0.5) {\n float sideA = vCutN.x * x + vCutN.y * y;\n if (sideA > -0.5) {\n float coverA = clamp(0.5 - sideA, 0.0, 1.0);\n float defA = 0.0;\n if (pkA.y > 0.0) {\n defA = max(\n profile - luxarPartnerProfile(vec4(vCutN.xy, pkA), vec2(x, y), 1.0, pkR.x, vSharp),\n 0.0\n );\n }\n profile = profile * coverA + defA * (1.0 - coverA);\n if (profile <= 0.0) discard;\n }\n }\n if (cutFlagB > 0.5) {\n float sideB = vCutN.z * (x - vAbLen) + vCutN.w * y;\n if (sideB > -0.5) {\n float coverB = clamp(0.5 - sideB, 0.0, 1.0);\n float defB = 0.0;\n if (pkB.y > 0.0) {\n defB = max(\n profile - luxarPartnerProfile(vec4(vCutN.zw, pkB), vec2(x - vAbLen, y), -1.0, pkR.y, vSharp),\n 0.0\n );\n }\n profile = profile * coverB + defB * (1.0 - coverB);\n if (profile <= 0.0) discard;\n }\n }\n float brightness = profile * vFade;\n if (brightness < 1e-4) discard;\n\n fragColor = vec4(vNodeId, vElementId.x, brightness, vElementId.y);\n gl_FragDepth = 1.0 - clamp(brightness, 0.0, 1.0);\n }\n" = ...