I have a GLSL fragment shader as part of a pipeline that renders slices of two 3D volumes blended together. For one of the volumes, I would like to use nearest neighbor interpolation since it is a "segmentation mask" (i.e. at each voxel indicates, which structure the voxel in the other image belongs to, e.g. 0 for background, 1 for target structure; see purple overlay in the image below), since the default trilinear interpolation creates undesired artifacts at the borders (green line at the border in the image below)
How would I have to modify the fragment shader code below to use nearest neighbor interpolation on the segmentation mask (vol2
)?
uniform sampler3D vol1;
uniform sampler3D vol2;
uniform sampler2D lut1;
uniform sampler2D lut2;
uniform float maskAlpha = 0.5;
void main()
{
float data1 = texture3D(vol1, gl_TexCoord[0].xyz).r;
float data2 = texture3D(vol2, gl_TexCoord[0].xyz).r;
vec4 col1 = texture2D(lut1, vec2(data1));
vec4 col2 = texture2D(lut2, vec2(data2));
gl_FragColor = col1 + col2 * maskAlpha;
}