--------------------------------------------------------------------------
| 1215 | |
| 1216 | //-------------------------------------------------------------------------- |
| 1217 | inline std::string ComputeLightingDeclaration(vtkRenderer* vtkNotUsed(ren), vtkVolumeMapper* mapper, |
| 1218 | vtkVolume* vol, int noOfComponents, int independentComponents, int totalNumberOfLights, |
| 1219 | int numberPositionalLights, bool defaultLighting) |
| 1220 | { |
| 1221 | auto glMapper = vtkOpenGLGPUVolumeRayCastMapper::SafeDownCast(mapper); |
| 1222 | vtkVolumeProperty* volProperty = vol->GetProperty(); |
| 1223 | std::string shaderStr = std::string("\ |
| 1224 | \nvec4 computeLighting(vec4 color, int component, float label)\ |
| 1225 | \n{\ |
| 1226 | \n vec4 finalColor = vec4(0.0);\n"); |
| 1227 | |
| 1228 | // Shading for composite blending only |
| 1229 | int const shadeReqd = volProperty->GetShade() && |
| 1230 | (mapper->GetBlendMode() == vtkVolumeMapper::COMPOSITE_BLEND || |
| 1231 | mapper->GetBlendMode() == vtkVolumeMapper::ISOSURFACE_BLEND || |
| 1232 | mapper->GetBlendMode() == vtkVolumeMapper::SLICE_BLEND); |
| 1233 | |
| 1234 | int const transferMode = volProperty->GetTransferFunctionMode(); |
| 1235 | |
| 1236 | if (independentComponents) |
| 1237 | { |
| 1238 | shaderStr += "\n int lightingComponent=component;\n"; |
| 1239 | } |
| 1240 | else |
| 1241 | { |
| 1242 | shaderStr += "\n int lightingComponent=0;\n"; |
| 1243 | } |
| 1244 | |
| 1245 | // If shading is required, we compute a shading gradient (used for the shading model) |
| 1246 | if (shadeReqd) |
| 1247 | { |
| 1248 | if (glMapper->GetComputeNormalFromOpacity()) |
| 1249 | { |
| 1250 | // we compute the gradienty according to the volume's opacity ! |
| 1251 | shaderStr += |
| 1252 | std::string(" vec4 shading_gradient = computeDensityGradient(g_dataPos, component, " |
| 1253 | "in_volume[0], 0, label);\n"); |
| 1254 | } |
| 1255 | else |
| 1256 | { |
| 1257 | // otherwise we take the scalar gradient directly |
| 1258 | shaderStr += std::string( |
| 1259 | " vec4 shading_gradient = computeGradient(g_dataPos, component, in_volume[0], 0);\n"); |
| 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | // If we need the scalar gradient (typically to sample a transfer function) |
| 1264 | if (volProperty->HasGradientOpacity() || volProperty->HasLabelGradientOpacity()) |
| 1265 | { |
| 1266 | // If we didn't compute it before, we compute it |
| 1267 | if (!shadeReqd || glMapper->GetComputeNormalFromOpacity()) |
| 1268 | { |
| 1269 | shaderStr += |
| 1270 | std::string(" vec4 gradient = computeGradient(g_dataPos, component, in_volume[0], 0);\n"); |
| 1271 | } |
| 1272 | // otherwise, we use what we already computed |
| 1273 | else |
| 1274 | { |
no test coverage detected