UNPKG

molstar

Version:

A comprehensive macromolecular library.

7 lines (6 loc) 2.91 kB
/** * Copyright (c) 2020-2025 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ export declare const cylinders_vert = "\nprecision highp float;\nprecision highp int;\n\n#include common\n#include read_from_texture\n#include common_vert_params\n#include color_vert_params\n#include size_vert_params\n#include common_clip\n\nuniform mat4 uModelView;\n\nattribute mat4 aTransform;\nattribute float aInstance;\nattribute float aGroup;\n\nattribute vec3 aMapping;\nattribute vec3 aStart;\nattribute vec3 aEnd;\nattribute float aScale;\nattribute float aCap;\nattribute float aColorMode;\n\nvarying mat4 vTransform;\nvarying vec3 vStart;\nvarying vec3 vEnd;\nvarying float vSize;\nvarying float vCap;\n\nuniform float uIsOrtho;\nuniform vec3 uCameraDir;\n\nvoid main() {\n int vertexId = VertexID;\n\n #include assign_group\n #include assign_color_varying\n #include assign_marker_varying\n #include assign_clipping_varying\n #include assign_size\n\n mat4 modelTransform = uModel * aTransform;\n\n vTransform = aTransform;\n vStart = (modelTransform * vec4(aStart, 1.0)).xyz;\n vEnd = (modelTransform * vec4(aEnd, 1.0)).xyz;\n vSize = size * aScale;\n vCap = aCap;\n\n vModelPosition = (vStart + vEnd) * 0.5;\n vec3 camDir = -mix(normalize(vModelPosition - uCameraPosition), uCameraDir, uIsOrtho);\n vec3 dir = vEnd - vStart;\n float f = aMapping.x > 0.0 ? 1.0 : 0.0;\n // ensure cylinder 'dir' is pointing towards the camera\n if(dot(camDir, dir) < 0.0) {\n dir = -dir;\n f = 1.0 - f;\n }\n\n vec3 left = cross(camDir, dir);\n vec3 up = cross(left, dir);\n left = vSize * normalize(left);\n up = vSize * normalize(up);\n\n // move vertex in object-space from center to corner\n vModelPosition += aMapping.x * dir + aMapping.y * left + aMapping.z * up;\n\n vec4 mvPosition = uView * vec4(vModelPosition, 1.0);\n vViewPosition = mvPosition.xyz;\n gl_Position = uProjection * mvPosition;\n\n if (gl_Position.z < -gl_Position.w) {\n mvPosition.z -= 2.0 * (length(vEnd - vStart) + vSize); // avoid clipping\n gl_Position.z = (uProjection * mvPosition).z;\n }\n\n #if defined(dDualColor) && defined(dRenderVariant_color) && (defined(dColorType_group) || defined(dColorType_groupInstance))\n // dual-color mixing\n // - for aColorMode between 0 and 1 use aColorMode to interpolate\n // - for aColorMode == 2 do nothing, i.e., use vColor\n // - for aColorMode == 3 use position on cylinder axis to interpolate\n if (aColorMode <= 1.0){\n vColor.rgb = mix(vColor.rgb, color2.rgb, aColorMode);\n } else if (aColorMode == 3.0) {\n vColor.rgb = mix(vColor.rgb, color2.rgb, mix(-0.25, 1.25, f / 1.5));\n }\n #endif\n\n #include clip_instance\n}\n";