--------------------------------------------------------------------------
| 680 | |
| 681 | //-------------------------------------------------------------------------- |
| 682 | inline std::string ComputeGradientDeclaration( |
| 683 | vtkOpenGLGPUVolumeRayCastMapper* mapper, vtkOpenGLGPUVolumeRayCastMapper::VolumeInputMap& inputs) |
| 684 | { |
| 685 | const bool hasLighting = HasLighting(inputs); |
| 686 | const bool hasGradientOp = HasGradientOpacity(inputs); |
| 687 | |
| 688 | std::string shaderStr; |
| 689 | if (hasLighting || hasGradientOp) |
| 690 | { |
| 691 | shaderStr += std::string( |
| 692 | "// c is short for component\n" |
| 693 | "vec4 computeGradient(in vec3 texPos, in int c, in sampler3D volume,in int index)\n" |
| 694 | "{\n" |
| 695 | " // Approximate Nabla(F) derivatives with central differences.\n" |
| 696 | " vec3 g1; // F_front\n" |
| 697 | " vec3 g2; // F_back\n" |
| 698 | " vec3 xvec = vec3(in_cellStep[index].x, 0.0, 0.0);\n" |
| 699 | " vec3 yvec = vec3(0.0, in_cellStep[index].y, 0.0);\n" |
| 700 | " vec3 zvec = vec3(0.0, 0.0, in_cellStep[index].z);\n" |
| 701 | " vec3 texPosPvec[3];\n" |
| 702 | " texPosPvec[0] = texPos + xvec;\n" |
| 703 | " texPosPvec[1] = texPos + yvec;\n" |
| 704 | " texPosPvec[2] = texPos + zvec;\n" |
| 705 | " vec3 texPosNvec[3];\n" |
| 706 | " texPosNvec[0] = texPos - xvec;\n" |
| 707 | " texPosNvec[1] = texPos - yvec;\n" |
| 708 | " texPosNvec[2] = texPos - zvec;\n" |
| 709 | " g1.x = texture3D(volume, vec3(texPosPvec[0]))[c];\n" |
| 710 | " g1.y = texture3D(volume, vec3(texPosPvec[1]))[c];\n" |
| 711 | " g1.z = texture3D(volume, vec3(texPosPvec[2]))[c];\n" |
| 712 | " g2.x = texture3D(volume, vec3(texPosNvec[0]))[c];\n" |
| 713 | " g2.y = texture3D(volume, vec3(texPosNvec[1]))[c];\n" |
| 714 | " g2.z = texture3D(volume, vec3(texPosNvec[2]))[c];\n" |
| 715 | "\n"); |
| 716 | if (UseClippedVoxelIntensity(inputs) && mapper->GetClippingPlanes()) |
| 717 | { |
| 718 | shaderStr += |
| 719 | std::string(" vec4 g1ObjDataPos[3], g2ObjDataPos[3];\n" |
| 720 | " for (int i = 0; i < 3; ++i)\n" |
| 721 | " {\n" |
| 722 | " g1ObjDataPos[i] = clip_texToObjMat * vec4(texPosPvec[i], 1.0);\n" |
| 723 | " if (g1ObjDataPos[i].w != 0.0)\n" |
| 724 | " {\n" |
| 725 | " g1ObjDataPos[i] /= g1ObjDataPos[i].w;\n" |
| 726 | " }\n" |
| 727 | " g2ObjDataPos[i] = clip_texToObjMat * vec4(texPosNvec[i], 1.0);\n" |
| 728 | " if (g2ObjDataPos[i].w != 0.0)\n" |
| 729 | " {\n" |
| 730 | " g2ObjDataPos[i] /= g2ObjDataPos[i].w;\n" |
| 731 | " }\n" |
| 732 | " }\n" |
| 733 | "\n" |
| 734 | " for (int i = 0; i < clip_numPlanes && !g_skip; i = i + 6)\n" |
| 735 | " {\n" |
| 736 | " vec3 planeOrigin = vec3(in_clippingPlanes[i + 1],\n" |
| 737 | " in_clippingPlanes[i + 2],\n" |
| 738 | " in_clippingPlanes[i + 3]);\n" |
| 739 | " vec3 planeNormal = normalize(vec3(in_clippingPlanes[i + 4],\n" |
no test coverage detected