UNPKG

molstar

Version:

A comprehensive macromolecular library.

7 lines (6 loc) 1.85 kB
/** * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Áron Samuel Kovács <aron.kovacs@mail.muni.cz> */ export declare const outlines_frag = "\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nuniform sampler2D tDepth;\nuniform vec2 uTexSize;\n\nuniform float uNear;\nuniform float uFar;\n\nuniform float uMaxPossibleViewZDiff;\n\n#include common\n\nfloat getViewZ(const in float depth) {\n #if dOrthographic == 1\n return orthographicDepthToViewZ(depth, uNear, uFar);\n #else\n return perspectiveDepthToViewZ(depth, uNear, uFar);\n #endif\n}\n\nfloat getDepth(const in vec2 coords) {\n return unpackRGBAToDepth(texture2D(tDepth, coords));\n}\n\nbool isBackground(const in float depth) {\n return depth == 1.0;\n}\n\nvoid main(void) {\n float backgroundViewZ = uFar + 3.0 * uMaxPossibleViewZDiff;\n\n vec2 coords = gl_FragCoord.xy / uTexSize;\n vec2 invTexSize = 1.0 / uTexSize;\n\n float selfDepth = getDepth(coords);\n float selfViewZ = isBackground(selfDepth) ? backgroundViewZ : getViewZ(getDepth(coords));\n\n float outline = 1.0;\n float bestDepth = 1.0;\n\n for (int y = -1; y <= 1; y++) {\n for (int x = -1; x <= 1; x++) {\n vec2 sampleCoords = coords + vec2(float(x), float(y)) * invTexSize;\n float sampleDepth = getDepth(sampleCoords);\n float sampleViewZ = isBackground(sampleDepth) ? backgroundViewZ : getViewZ(sampleDepth);\n\n if (abs(selfViewZ - sampleViewZ) > uMaxPossibleViewZDiff && selfDepth > sampleDepth && sampleDepth <= bestDepth) {\n outline = 0.0;\n bestDepth = sampleDepth;\n }\n }\n }\n\n gl_FragColor = vec4(outline, packUnitIntervalToRG(bestDepth), 0.0);\n}\n";