molstar
Version:
A comprehensive macromolecular library.
2 lines (1 loc) • 1.43 kB
TypeScript
export declare const luminosity_frag = "\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nuniform sampler2D tColor;\nuniform sampler2D tEmissive;\nuniform sampler2D tDepth;\nuniform vec2 uTexSizeInv;\n\nuniform vec3 uDefaultColor;\nuniform float uDefaultOpacity;\nuniform float uLuminosityThreshold;\nuniform float uSmoothWidth;\n\n#include common\n\nfloat getDepth(const in vec2 coords) {\n #ifdef depthTextureSupport\n return texture2D(tDepth, coords).r;\n #else\n return unpackRGBAToDepth(texture2D(tDepth, coords));\n #endif\n}\n\nbool isBackground(const in float depth) {\n return depth == 1.0;\n}\n\nvoid main(void) {\n vec2 coords = gl_FragCoord.xy * uTexSizeInv;\n vec4 texel = texture2D(tColor, coords);\n float emissive = texture2D(tEmissive, coords).a;\n float depth = getDepth(coords);\n\n if (isBackground(depth)) {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n return;\n }\n\n vec4 outputColor = vec4(uDefaultColor.rgb, uDefaultOpacity);\n\n #if defined(dMode_luminosity)\n vec3 luma = vec3(0.299, 0.587, 0.114);\n float v = dot(texel.xyz, luma);\n float alpha = smoothstep(uLuminosityThreshold, uLuminosityThreshold + uSmoothWidth, v);\n\n gl_FragColor = mix(outputColor, texel, alpha);\n #elif defined(dMode_emissive)\n gl_FragColor = mix(outputColor, texel, emissive);\n #endif\n}\n";