in packages/miew/src/gfx/shaders/Volume.frag [154:219]
vec4 VolRender(vec3 start, vec3 back, float molDist, vec3 dir) {
vec4 acc = NO_COLOR, iso;
vec3 iterator = start, sumColor = vec3(0., 0., 0.);
float stepSize, alpha, sumAlpha = 0.0, vol, curStepSize, molD;
vec3 step, col, colOld, right;
float tr0 = _isoLevel0.x;
float dif, r, kd, finish;
int count = 0, stopMol = 0;
for (int k = 0; k < 3; k++) {
stepSize = (float(k) + 2.) / float(STEPS_COUNT);
kd = 140. * tr0 * stepSize;
r = 1. - kd;
step = stepSize * dir;
iso = GetIso1(iterator, back, molDist, dir, tr0, k);
if (iso.a < 0.1 || length(iso.xyz - start) > molDist)
break;
iterator = iso.xyz;
dif = 1.;// CalcColor(iterator, dir);
colOld = GetColSimple(tr0);
curStepSize = stepSize;
for (int i = 0; i < STEPS_COUNT; i++) {
iterator = iterator + step;
molD = length(iterator - start);
vol = sample3DTextureInclined(iterator).r;
finish = distance(iterator, back) - stepSize;
if (finish < 0.0 || vol < tr0 || (sumAlpha > 0.97) || molD > molDist)
break;
alpha = (1. - r);
col = GetColSimple(vol);
vol = sample3DTextureInclined(iterator - 0.5 * step).r;
vec3 colMid = GetColSimple(vol);
sumColor += (1. - sumAlpha) * (colOld + 4.* colMid + col) * alpha / 6.;
sumAlpha += (1. - sumAlpha) * alpha;// *(1. - 1.0*dif*dif);
colOld = col;
} // for i
if (finish < 0.0 || sumAlpha > 0.97)
break;
if (molD > molDist) {
curStepSize = stepSize - (molD - molDist);
right = iterator - (molD - molDist) * dir;
vol = sample3DTextureInclined(right).r;
} else {
vec3 left = iterator - step;
right = CorrectIso(left, iterator, tr0);
curStepSize = distance(left, right);
vol = tr0;
}
alpha = (1. - r) * curStepSize / stepSize;
dif = 1.;// CalcColor(right, dir);
col = GetColSimple(vol);
vol = sample3DTextureInclined(iterator - 0.5 * curStepSize / stepSize * step).r;
vec3 colMid = GetColSimple(vol);
sumColor += (1. - sumAlpha) * (colOld + 4. * colMid + col) * alpha / 6.;
sumAlpha += (1. - sumAlpha) * alpha;// *(1. - 1.0*dif*dif);
if (molD > molDist)
break;
} // for k
acc.rgb = 1. * sumColor / sumAlpha;
acc.a = sumAlpha;
return acc;
}