in src/engine/shaders/volumerender.frag [788:959]
void main() {
const float DELTA1 = 0.1;
const float DELTA2 = 0.05;
vec4 acc = vec4(0.0, 0.0, 0.0, 1.0);
// To increase the points of the beginning and end of the ray and its direction
vec2 tc = screenpos.xy / screenpos.w * 0.5 + 0.5;
// gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);
// return;
vec4 backTexel = texture2D(texBF, tc, 0.0);
vec3 back = backTexel.xyz;
vec4 start = texture2D(texFF, tc, 0.0);
if (length(back) < 0.001 || length(start.xyz) < 0.01) {
gl_FragColor = vec4(0, 0, 0, 1.0);
return;
}
vec3 dir = normalize(back - start.xyz);
if (start.a < 0.3 || backTexel.a < 0.3) {
gl_FragColor = vec4(0, 0, 0, 1.0);
return;
}
if (length (back - start.xyz) < 0.03) {
gl_FragColor = vec4(0.0, 0, 0, 1.0);
return;
}
// Read texels adjacent to the pixel
vec2 tc1 = tc.xy;
vec2 tSize = isoSurfTexel;
tc1 = tc1 - 0.5 * tSize;
vec2 uv_fract = fract(tc1 / tSize);
vec2 tex_dU = vec2(tSize.x, 0.0);
vec2 tex_dV = vec2(0.0, tSize.y);
vec4 iso1 = texture2D(texIsoSurface, tc1, 0.0);
vec4 iso2 = texture2D(texIsoSurface, tc1 + tex_dU, 0.0);
vec4 iso3 = texture2D(texIsoSurface, tc1 + tex_dV, 0.0);
vec4 iso4 = texture2D(texIsoSurface, tc1 + tex_dU + tex_dV, 0.0);
vec4 minIso = min(iso1, iso2);
minIso = min(minIso, iso3);
minIso = min(minIso, iso4);
float delta = DELTA1;
#if isoRenderFlag==1
{
delta = DELTA2;
}
#endif
if (minIso.a > 1.9)
{
// The neighboring texels do not contain an isosurface
gl_FragColor = vec4(0.0, 0, 0, 1.0);
return;
}
if (length(iso1.rgb - iso2.rgb) < delta && length(iso1.rgb - iso3.rgb) < delta && length(iso1.rgb - iso4.rgb) < delta)
{
// The color of the pixel is calculated by bilinear interpolation of colors of neighboring texels
acc = vec4(mix(mix(iso1.xyz, iso2.xyz, uv_fract.x), mix(iso3.xyz, iso4.xyz, uv_fract.x), uv_fract.y), 1.0);
gl_FragColor = acc;
return;
}
// Direct volume render
#if isoRenderFlag==0
{
float vol = tex3D(start.xyz);
if (vol > t_function2min.a)
acc.rgb = 0.75*vol * t_function2min.rgb;
else
acc.rgb = VolumeRender(start.xyz + max(0., minIso.a - 0. / 128.)*dir , dir, back).rgb;
acc.a = 1.0;
acc.rgb = (1.0 - contrast3D)*acc.rgb + contrast3D*vec3(vol);
gl_FragColor = acc;
return;
}
#endif
// Direct isosurface render
#if isoRenderFlag==1
{
//float v = length(start.xyz - back);
//gl_FragColor = vec4(v, v, v, 1.0);
//return;
float vol = tex3D(start.xyz);
if (vol > isoThreshold)
{
acc.rgb = vec3(vol);
acc.a = 1.0;
gl_FragColor = acc;
return;
}
else
{
acc = Isosurface(start.xyz + max(0., minIso.a - 1. / 128.)*dir, dir, back, isoThreshold);
// acc = Isosurface(start.xyz, dir, back, isoThreshold);
if (acc.a < 1.9)
{
acc.rgb = CalcLighting(acc.rgb, dir);
//acc.rgb = (1.0 - contrast3D)*acc.rgb + contrast3D*vec3(vol);
acc.a = 1.0;
}
gl_FragColor = acc;
return;
}
}
#endif
// Direct full volume render
#if isoRenderFlag==3
{
acc.rgb = FullVolumeRender(start.xyz + max(0., minIso.a - 0. / 128.)*dir, dir, back).rgb;
acc.a = 1.0;
gl_FragColor = acc;
return;
}
#endif
// Direct volume render with ROI
#if isoRenderFlag==4
{
vec4 vol = tex3DRoi(start.xyz);
if (vol.a > 0.75)
acc.rgb = 0.75 * vol.rgb;
else
// acc.rgb = RoiVolumeRender(start.xyz, dir, back).rgb;
acc.rgb = RoiVolumeRender(start.xyz + max(0., minIso.a - 0. / 128.)*dir, dir, back).rgb;
acc.a = 1.0;
gl_FragColor = acc;
return;
}
#endif
//Direct isosurface render with ROI
#if isoRenderFlag == 5
{
//float v = tex3DRoi(start.xyz).a;
//gl_FragColor = vec4(v, v, v, 1.0);
//return;
float Threshold = 0.3 * isoThreshold + 0.5;
acc = IsosurfaceRoi(start.xyz + max(0., minIso.a - 1. / 128.)*dir, dir, back, Threshold, stepSize.b);
if (acc.a < 1.9)
{
vec4 vol = tex3DRoi(start.xyz);
if (vol.a > Threshold)//t_function2min.a)
acc.rgb = 0.75 * vol.rgb;
else
{
const float AMBIENT = 0.3;
const float DIFFUSE = 0.7;
const float SPEC = 0.1;
const float SPEC_POV = 90.0;
vec3 N = CalcNormalRoi(acc.rgb);
float dif = max(0.0, dot(N, -lightDir));
float specular = pow(max(0.0, dot(normalize(reflect(lightDir, N)), dir)), SPEC_POV);
// acc.rgb = (0.5*(brightness3D + 1.5)*(DIFFUSE * dif + AMBIENT * computeSsaoShadow(acc.rgb, N, Threshold) ) + SPEC * specular) * tex3DRoi(acc.rgb).rgb;
acc.rgb = (0.5*(brightness3D + 1.5)*(DIFFUSE * dif + AMBIENT) + SPEC * specular) * tex3DRoi(acc.rgb).rgb;
// acc.rgb = computeSsaoShadow(acc.rgb, Threshold) * vec3(1.0, 1.0, 1.0);
}
acc.a = 1.0;
}
gl_FragColor = acc;
return;
}
#endif
// Render of maximum intensity
#if isoRenderFlag == 2
{
acc.rgb = MipRender(start.xyz, dir, back).rgb;
gl_FragColor = acc;
return;
}
#endif
}