molstar
Version:
A comprehensive macromolecular library.
132 lines (122 loc) • 4.39 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.assign_material_color = void 0;
exports.assign_material_color = `
float marker = uMarker;
if (uMarker == -1.0) {
marker = floor(vMarker * 255.0 + 0.5); // rounding required to work on some cards on win
}
vec4 material = vec4(texture2D(tPalette, vec2(vPaletteV, 0.5)).rgb, uAlpha);
vec4 material = vec4(uColor, uAlpha);
vec4 material = vec4(vColor.rgb, uAlpha);
// mix material with overpaint
material.rgb = mix(material.rgb, vOverpaint.rgb, vOverpaint.a);
float emissive = uEmissive;
emissive += vEmissive;
float metalness = uMetalness;
float roughness = uRoughness;
float bumpiness = uBumpiness;
float sf = clamp(vSubstance.a, 0.0, 0.99); // clamp to avoid artifacts
metalness = mix(metalness, vSubstance.r, sf);
roughness = mix(roughness, vSubstance.g, sf);
bumpiness = mix(bumpiness, vSubstance.b, sf);
material.a = calcXrayShadedAlpha(material.a, normal);
if (fragmentDepth > getDepth(gl_FragCoord.xy / uDrawingBufferSize)) {
discard;
}
vec4 material;
if (uRenderMask == MaskOpaque) {
discard;
float dta = 1.0 - vTransparency;
if (vTransparency < 0.1) dta = 1.0; // hard cutoff to avoid artifacts
if (uAlpha * dta < 1.0) {
discard;
}
if (uAlpha < 1.0) {
discard;
}
material = packDepthToRGBA(fragmentDepth);
} else if (uRenderMask == MaskTransparent) {
float alpha = uAlpha;
float dta = 1.0 - vTransparency;
alpha *= dta;
alpha = calcXrayShadedAlpha(alpha, normal);
if (alpha == 1.0) {
discard;
}
material = packDepthWithAlphaToRGBA(fragmentDepth, alpha);
}
vec4 material;
if(uMarkingType == 1) {
if (marker > 0.0)
discard;
material = packDepthToRGBA(gl_FragDepthEXT);
material = packDepthToRGBA(gl_FragCoord.z);
} else {
if (marker == 0.0)
discard;
float depthTest = 1.0;
if (uMarkingDepthTest) {
depthTest = (fragmentDepth >= getDepthPacked(gl_FragCoord.xy / uDrawingBufferSize)) ? 1.0 : 0.0;
}
bool isHighlight = intMod(marker, 2.0) > 0.1;
float viewZ = depthToViewZ(uIsOrtho, fragmentDepth, uNear, uFar);
float fogFactor = smoothstep(uFogNear, uFogFar, abs(viewZ));
if (fogFactor == 1.0)
discard;
material = vec4(0.0, depthTest, isHighlight ? 1.0 : 0.0, 1.0 - fogFactor);
}
float emissive = uEmissive;
emissive += vEmissive;
vec4 material = vec4(emissive);
// apply per-group transparency
float ta = 1.0 - vTransparency;
if (vTransparency < 0.09) ta = 1.0; // hard cutoff looks better
if (ta * uAlpha < uPickingAlphaThreshold)
discard; // ignore so the element below can be picked
if (ta < 1.0)
discard; // emissive not supported with transparency
material.a *= ta;
`;