UNPKG

molstar

Version:

A comprehensive macromolecular library.

57 lines (46 loc) 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.luminosity_frag = void 0; exports.luminosity_frag = ` precision highp float; precision highp int; precision highp sampler2D; uniform sampler2D tColor; uniform sampler2D tEmissive; uniform sampler2D tDepth; uniform vec2 uTexSizeInv; uniform vec3 uDefaultColor; uniform float uDefaultOpacity; uniform float uLuminosityThreshold; uniform float uSmoothWidth; #include common float getDepth(const in vec2 coords) { #ifdef depthTextureSupport return texture2D(tDepth, coords).r; #else return unpackRGBAToDepth(texture2D(tDepth, coords)); #endif } bool isBackground(const in float depth) { return depth == 1.0; } void main(void) { vec2 coords = gl_FragCoord.xy * uTexSizeInv; vec4 texel = texture2D(tColor, coords); float emissive = texture2D(tEmissive, coords).a; float depth = getDepth(coords); if (isBackground(depth)) { gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); return; } vec4 outputColor = vec4(uDefaultColor.rgb, uDefaultOpacity); #if defined(dMode_luminosity) vec3 luma = vec3(0.299, 0.587, 0.114); float v = dot(texel.xyz, luma); float alpha = smoothstep(uLuminosityThreshold, uLuminosityThreshold + uSmoothWidth, v); gl_FragColor = mix(outputColor, texel, alpha); #elif defined(dMode_emissive) gl_FragColor = mix(outputColor, texel, emissive); #endif } `;