UNPKG

molstar

Version:

A comprehensive macromolecular library.

119 lines (94 loc) 3.31 kB
/** * Copyright (c) 2019-2026 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Gianluca Tomasello <giagitom@gmail.com> */ export const text_vert = ` precision highp float; precision highp int; #include common #include read_from_texture #include common_vert_params #include color_vert_params #include size_vert_params #include common_clip uniform mat4 uModelView; attribute vec3 aPosition; attribute vec2 aMapping; attribute float aDepth; attribute vec2 aTexCoord; attribute mat4 aTransform; attribute float aInstance; attribute float aGroup; uniform float uOffsetX; uniform float uOffsetY; uniform float uOffsetZ; uniform float uIsOrtho; uniform float uPixelRatio; uniform vec4 uViewport; uniform mat4 uInvHeadRotation; uniform bool uHasHeadRotation; uniform mat4 uModelViewEye; uniform mat4 uInvModelViewEye; uniform bool uHasEyeCamera; varying vec2 vTexCoord; void main(void){ int vertexId = VertexID; #include assign_group #include assign_color_varying #include assign_marker_varying #include assign_clipping_varying #include assign_size vTexCoord = aTexCoord; float scale = uModelScale; float offsetX = uOffsetX * scale; float offsetY = uOffsetY * scale; float offsetZ = (uOffsetZ + aDepth * 0.95) * scale; vec4 position4 = vec4(aPosition, 1.0); vec4 mvPosition = uHasEyeCamera ? uModelViewEye * aTransform * position4 : uModelView * aTransform * position4; vModelPosition = (uModel * aTransform * position4).xyz; // for clipping in frag shader // TODO // #ifdef FIXED_SIZE // if (ortho) { // scale /= pixelRatio * ((uViewport.w / 2.0) / -uCameraPosition.z) * 0.1; // } else { // scale /= pixelRatio * ((uViewport.w / 2.0) / -mvPosition.z) * 0.1; // } // #endif vec4 mvCenter = vec4(mvPosition.xyz, 1.0); if (vTexCoord.x == 10.0) { // indicates background plane // move a bit to the back, taking distance to camera into account to avoid z-fighting offsetZ -= 0.001 * distance(uCameraPosition, (uProjection * mvCenter).xyz); } // apply Z offset in view space if (!uHasEyeCamera) { if (uIsOrtho == 1.0) { mvCenter.z += offsetZ; } else { mvCenter.xyz += normalize(-mvCenter.xyz) * offsetZ; } } if (uHasEyeCamera) { mvCenter = uModelView * uInvModelViewEye * mvCenter; } // project center to clip space vec4 clip = uProjection * mvCenter; // compute corner offset in screen-space units vec2 cornerOffset = aMapping * size * scale; cornerOffset.x += offsetX; cornerOffset.y += offsetY; if (uHasHeadRotation) { vec3 rotatedOffset = (uInvHeadRotation * vec4(cornerOffset, 0.0, 0.0)).xyz; clip += uProjection * vec4(rotatedOffset, 0.0); } else { // apply offset in clip space to avoid perspective distortion on the quad clip.xy += vec2(uProjection[0][0], uProjection[1][1]) * cornerOffset; } gl_Position = clip; vViewPosition = -mvCenter.xyz; #include clip_instance } `;