Hi @Alireza and @sankhesh -
Regarding RGBA rendering, Sankesh and I discussed some issues I was running into so I did a dive into the shader code and was able to fix an issue to calculate shading from the alpha channel and get color from the RGB channels like in the image below (there’s also a link to a movie of it). I didn’t have a chance to do a pull request, but the diff with the fixes is included below in case it helps.
-Steve
Yes, exactly. This image uses the CT as alpha, so you get nice detail with the coloring, but we should also do the option where the segmentation opacity controls the alpha channel. We’ll need to do the local smoothing / surface fitting in the GPU...
diff --git a/Rendering/VolumeOpenGL2/vtkVolumeShaderComposer.h b/Rendering/VolumeOpenGL2/vtkVolumeShaderComposer.h
index 6f4962cc6f..e894ff1770 100644
--- a/Rendering/VolumeOpenGL2/vtkVolumeShaderComposer.h
+++ b/Rendering/VolumeOpenGL2/vtkVolumeShaderComposer.h
@@ -678,15 +678,15 @@ namespace vtkvolume
\n }\
\n if (nDotL > 0.0)\
\n {\
- \n diffuse = nDotL * in_diffuse[component] *\
+ \n diffuse = nDotL * in_diffuse[0] *\
\n in_lightDiffuseColor[0] * color.rgb;\
\n }\
- \n specular = pow(nDotH, in_shininess[component]) *\
- \n in_specular[component] *\
+ \n specular = pow(nDotH, in_shininess[0]) *\
+ \n in_specular[0] *\
\n in_lightSpecularColor[0];\
\n // For the headlight, ignore the light's ambient color\
\n // for now as it is causing the old mapper tests to fail\
- \n finalColor.xyz = in_ambient[component] * color.rgb +\
+ \n finalColor.xyz = in_ambient[0] * color.rgb +\
\n diffuse + specular;\
\n");
}
@@ -734,13 +734,13 @@ namespace vtkvolume
\n if (nDotH > 0.0)\
\n {\
\n specular = in_lightSpecularColor[lightNum] *\
- \n pow(nDotH, in_shininess[component]);\
+ \n pow(nDotH, in_shininess[0]);\
\n }\
\n ambient += in_lightAmbientColor[lightNum];\
\n }\
- \n finalColor.xyz = in_ambient[component] * ambient +\
- \n in_diffuse[component] * diffuse * color.rgb +\
- \n in_specular[component] * specular;"
+ \n finalColor.xyz = in_ambient[0] * ambient +\
+ \n in_diffuse[0] * diffuse * color.rgb +\
+ \n in_specular[0] * specular;"
);
}
else if (lightingComplexity == 3)
@@ -811,14 +811,14 @@ namespace vtkvolume
\n }\
\n if (nDotH > 0.0)\
\n {\
- \n float sf = attenuation * pow(nDotH, in_shininess[component]);\
+ \n float sf = attenuation * pow(nDotH, in_shininess[0]);\
\n specular += (sf * in_lightSpecularColor[lightNum]);\
\n }\
\n ambient += in_lightAmbientColor[lightNum];\
\n }\
- \n finalColor.xyz = in_ambient[component] * ambient +\
- \n in_diffuse[component] * diffuse * color.rgb +\
- \n in_specular[component] * specular;\
+ \n finalColor.xyz = in_ambient[0] * ambient +\
+ \n in_diffuse[0] * diffuse * color.rgb +\
+ \n in_specular[0] * specular;\
");
}
}
@@ -930,15 +930,15 @@ namespace vtkvolume
\n }\
\n if (nDotL > 0.0)\
\n {\
- \n diffuse = nDotL * in_diffuse[component] *\
+ \n diffuse = nDotL * in_diffuse[0] *\
\n in_lightDiffuseColor[0] * color.rgb;\
\n }\
- \n specular = pow(nDotH, in_shininess[component]) *\
- \n in_specular[component] *\
+ \n specular = pow(nDotH, in_shininess[0]) *\
+ \n in_specular[0] *\
\n in_lightSpecularColor[0];\
\n // For the headlight, ignore the light's ambient color\
\n // for now as it is causing the old mapper tests to fail\
- \n finalColor.xyz = in_ambient[component] * color.rgb +\
+ \n finalColor.xyz = in_ambient[0] * color.rgb +\
\n diffuse + specular;\
\n");
}
@@ -1061,16 +1061,29 @@ namespace vtkvolume
\n {\
\n return computeLighting(vec4(texture2D(" + colorTableMap[0] + ",\
\n vec2(scalar.x, 0.0)).xyz,\
- \n opacity), 0);\
+ \n opacity), 1);\
+ \n }");
+ return shaderStr;
+ }
+ else if (noOfComponents == 4 && !independentComponents)
+ {
+ shaderStr += std::string("\
+ \nvec4 computeColor(vec4 scalar, float opacity)\
+ \n {\
+ \n return computeLighting(vec4(scalar.xyz, opacity), 3);\
\n }");
return shaderStr;
}
else
{
+ // invalid combination: more than one component but not 2 or 4
+ // and not treated independently, so treat it the same as 2 component
shaderStr += std::string("\
\nvec4 computeColor(vec4 scalar, float opacity)\
\n {\
- \n return computeLighting(vec4(scalar.xyz, opacity), 0);\
+ \n return computeLighting(vec4(texture2D(" + colorTableMap[0] + ",\
+ \n vec2(scalar.x, 0.0)).xyz,\
+ \n opacity), 1);\
\n }");
return shaderStr;
}
@@ -1534,7 +1547,7 @@ namespace vtkvolume
else
{
shader <<
- "g_gradients_0[0] = computeGradient(g_dataPos, 0, in_volume[0], 0);\n";
+ "g_gradients_0[0] = computeGradient(g_dataPos, 3, in_volume[0], 0);\n";
}
return shader.str();