molstar
Version:
A comprehensive macromolecular library.
103 lines (87 loc) • 3.24 kB
JavaScript
/**
* 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_frag = `
precision highp float;
precision highp int;
uniform sampler2D tFont;
uniform vec3 uBorderColor;
uniform float uBorderWidth;
uniform vec3 uBackgroundColor;
uniform float uBackgroundOpacity;
varying vec2 vTexCoord;
void main(){
float fragmentDepth = gl_FragCoord.z;
// determine if this is a background or glyph fragment
bool isBackground = vTexCoord.x > 1.0;
// discard background for non-visual variants (depth, pick, marking, emissive)
if (isBackground) discard;
// SDF test for glyph fragments — discard pixels outside glyph+border
float rawSdf = 0.0;
if (!isBackground) {
rawSdf = texture2D(tFont, vTexCoord).a;
float sdf = rawSdf + min(uBorderWidth, 0.49); // clamp to avoid exceeding max SDF range
if (sdf < 0.5) discard;
}
gl_FragDepthEXT = fragmentDepth;
if (isBackground) {
material = vec4(uBackgroundColor, uBackgroundOpacity * material.a);
} else {
if (uBorderWidth > 0.0 && rawSdf < 0.5) {
material.xyz = uBorderColor;
} else {
// push text fragments forward in depth so they render in front of border
gl_FragDepthEXT = fragmentDepth - 0.0001;
}
}
gl_FragColor = vObject;
gl_FragData[1] = vInstance;
gl_FragData[2] = vGroup;
gl_FragData[3] = packDepthToRGBA(fragmentDepth);
gl_FragColor = vColor;
gl_FragColor = material;
gl_FragColor = material;
gl_FragColor = material;
gl_FragColor = material;
gl_FragData[1] = vec4(-normalize(vViewPosition), emissive);
gl_FragData[2] = vec4(material.rgb, uDensity);
}
`;