vtkvolume::ComputeGradientOpacityMulti1DDecl(this->AssembledInputs));
vtkShaderProgram::Substitute(fragmentShader, "//VTK::ComputeColor::Dec",
- vtkvolume::ComputeColorMultiDeclaration(this->AssembledInputs));
+ vtkvolume::ComputeColorMultiDeclaration(
+ this->AssembledInputs, vol->GetProperty()->HasGradientOpacity()));
vtkShaderProgram::Substitute(fragmentShader, "//VTK::ComputeLighting::Dec",
vtkvolume::ComputeLightingMultiDeclaration(ren, this, vol, numComps, independentComponents,
this->ForceTransferInit();
}
+ if (this->MultiVolume)
+ {
+ bool hasGradient = this->Parent->AssembledInputs[0].Volume->GetProperty()->HasGradientOpacity();
+ for (auto& item : this->Parent->AssembledInputs)
+ {
+ if (item.second.Volume->GetProperty()->HasGradientOpacity() != hasGradient)
+ {
+ vtkGenericWarningMacro(
+ "Current implentation of vtkOpenGLGPUVolumeRayCastMapper does not support MultiVolume "
+ "where some volumes have a gradient opacity function and some others don't. "
+ "Rendering of the MultiVolume is disabled.");
+ success = false;
+ break;
+ }
+ }
+ }
+
return success;
}
this->Impl->MultiVolume = multiVol && this->GetInputCount() > 1 ? multiVol : nullptr;
this->Impl->ClearRemovedInputs(renWin);
- this->Impl->UpdateInputs(ren, vol);
+ if (!this->Impl->UpdateInputs(ren, vol))
+ {
+ return;
+ }
this->Impl->UpdateSamplingDistance(ren);
this->Impl->UpdateTransfer2DYAxisArray(ren, vol);
this->Impl->UpdateTransferFunctions(ren);
int lightingComplexity)
{
vtkVolumeProperty* volProperty = vol->GetProperty();
- std::string shaderStr = std::string("\
+
+ std::string shaderStr = std::string();
+
+ // if no gradient TF is needed, don't add it into the function signature
+ if (volProperty->HasGradientOpacity())
+ {
+ shaderStr += std::string("\
\nvec4 computeLighting(vec3 texPos, vec4 color, const in sampler2D gradientTF, const in sampler3D volume, const int volIdx, int component)\
\n {\
\n vec4 finalColor = vec4(0.0);");
+ }
+ else
+ {
+ shaderStr += std::string("\
+ \nvec4 computeLighting(vec3 texPos, vec4 color, const in sampler3D volume, const int volIdx, int component)\
+ \n {\
+ \n vec4 finalColor = vec4(0.0);");
+ }
// Shading for composite blending only
int const shadeReqd = volProperty->GetShade() &&
}
//--------------------------------------------------------------------------
-std::string ComputeColorMultiDeclaration(vtkOpenGLGPUVolumeRayCastMapper::VolumeInputMap& inputs)
+std::string ComputeColorMultiDeclaration(
+ vtkOpenGLGPUVolumeRayCastMapper::VolumeInputMap& inputs, bool useGradientTF)
{
std::ostringstream ss;
int i = 0;
}
else
{
- ss << "vec4 computeColor(vec3 texPos, vec4 scalar, float opacity, const in sampler2D colorTF, "
- "const in sampler2D gradientTF, const in sampler3D volume, const int volIdx)\n"
- "{\n"
- " return clamp(computeLighting(texPos, vec4(texture2D(colorTF,\n"
- " vec2(scalar.w, 0.0)).xyz, opacity), gradientTF, volume, "
- "volIdx, 0), 0.0, 1.0);\n"
- "}\n";
+ if (useGradientTF)
+ {
+ ss
+ << "vec4 computeColor(vec3 texPos, vec4 scalar, float opacity, const in sampler2D colorTF, "
+ "const in sampler2D gradientTF, const in sampler3D volume, const int volIdx)\n"
+ "{\n"
+ " return clamp(computeLighting(texPos, vec4(texture2D(colorTF,\n"
+ " vec2(scalar.w, 0.0)).xyz, opacity), gradientTF, volume, "
+ "volIdx, 0), 0.0, 1.0);\n"
+ "}\n";
+ }
+ else
+ {
+ ss
+ << "vec4 computeColor(vec3 texPos, vec4 scalar, float opacity, const in sampler2D colorTF, "
+ "const in sampler3D volume, const int volIdx)\n"
+ "{\n"
+ " return clamp(computeLighting(texPos, vec4(texture2D(colorTF,\n"
+ " vec2(scalar.w, 0.0)).xyz, opacity), volume, "
+ "volIdx, 0), 0.0, 1.0);\n"
+ "}\n";
+ }
}
return ss.str();
if (property->GetTransferFunctionMode() == vtkVolumeProperty::TF_1D)
{
+ std::string gradientopacity_param = (property->HasGradientOpacity())
+ ? input.GradientOpacityTablesMap[0] + std::string(", ")
+ : std::string();
+
toShaderStr << " g_srcColor.a = computeOpacity(scalar,"
<< input.OpacityTablesMap[0]
<< ");\n"
" if (g_srcColor.a > 0.0)\n"
" {\n"
" g_srcColor = computeColor(texPos, scalar, g_srcColor.a, "
- << input.RGBTablesMap[0] << ", " << input.GradientOpacityTablesMap[0] << ", "
- << "in_volume[" << i << "], " << i << ");\n";
+ << input.RGBTablesMap[0] << ", " << gradientopacity_param << "in_volume[" << i
+ << "], " << i << ");\n";
if (property->HasGradientOpacity())
{