830 | | " texcoord = gl_MultiTexCoord0.xyz;\n" |
831 | | " gl_Position = ftransform();\n" |
832 | | " cameraPos=vec4(gl_ModelViewMatrixInverse*vec4(0,0,0,1)).xyz;\n" |
| 837 | " gl_Position = ftransform();\n" |
| 838 | "\n" |
| 839 | " cameraPos = gl_ModelViewMatrixInverse*vec4(0,0,0,1);\n" |
| 840 | " vertexPos = gl_Vertex;\n" |
| 841 | "\n" |
| 842 | " texgen = mat4(gl_ObjectPlaneS[0], \n" |
| 843 | " gl_ObjectPlaneT[0],\n" |
| 844 | " gl_ObjectPlaneR[0],\n" |
| 845 | " gl_ObjectPlaneQ[0]);\n" |
861 | | " vec3 deltaTexCoord=normalize(cameraPos-texcoord.xyz)*sampleDensity;\n" |
862 | | " gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n" |
863 | | " while (texcoord.x>=0.0 && texcoord.x<=1.0 &&\n" |
864 | | " texcoord.y>=0.0 && texcoord.y<=1.0 &&\n" |
865 | | " texcoord.z>=0.0 && texcoord.z<=1.0)\n" |
| 875 | " vec3 t0 = (texgen * vertexPos).xyz;\n" |
| 876 | " vec3 te = (texgen * cameraPos).xyz;\n" |
| 877 | "\n" |
| 878 | " if (te.x>=0.0 && te.x<=1.0 &&\n" |
| 879 | " te.y>=0.0 && te.y<=1.0 &&\n" |
| 880 | " te.z>=0.0 && te.z<=1.0)\n" |
| 881 | " {\n" |
| 882 | " // do nothing... te inside volume\n" |
| 883 | " }\n" |
| 884 | " else\n" |
| 885 | " {\n" |
| 886 | " if (te.x<0.0)\n" |
876 | | " if (gl_FragColor.w>1.0) gl_FragColor.w = 1.0; \n" |
877 | | " if (gl_FragColor.w==0.0) discard;\n" |
| 891 | "\n" |
| 892 | " if (te.x>1.0)\n" |
| 893 | " {\n" |
| 894 | " float r = (1.0-te.x) / (t0.x-te.x);\n" |
| 895 | " te = te + (t0-te)*r;\n" |
| 896 | " }\n" |
| 897 | "\n" |
| 898 | " if (te.y<0.0)\n" |
| 899 | " {\n" |
| 900 | " float r = -te.y / (t0.y-te.y);\n" |
| 901 | " te = te + (t0-te)*r;\n" |
| 902 | " }\n" |
| 903 | "\n" |
| 904 | " if (te.y>1.0)\n" |
| 905 | " {\n" |
| 906 | " float r = (1.0-te.y) / (t0.y-te.y);\n" |
| 907 | " te = te + (t0-te)*r;\n" |
| 908 | " }\n" |
| 909 | "\n" |
| 910 | " if (te.z<0.0)\n" |
| 911 | " {\n" |
| 912 | " float r = -te.z / (t0.z-te.z);\n" |
| 913 | " te = te + (t0-te)*r;\n" |
| 914 | " }\n" |
| 915 | "\n" |
| 916 | " if (te.z>1.0)\n" |
| 917 | " {\n" |
| 918 | " float r = (1.0-te.z) / (t0.z-te.z);\n" |
| 919 | " te = te + (t0-te)*r;\n" |
| 920 | " }\n" |
| 921 | " }\n" |
| 922 | "\n" |
| 923 | " const int max_iteratrions = 256;\n" |
| 924 | " int num_iterations = length(te-t0)/sampleDensity;\n" |
| 925 | " if (num_iterations>max_iteratrions) \n" |
| 926 | " {\n" |
| 927 | " num_iterations = max_iteratrions;\n" |
| 928 | " }\n" |
| 929 | "\n" |
| 930 | " vec3 deltaTexCoord=(te-t0)/float(num_iterations-1);\n" |
| 931 | " vec3 texcoord = t0;\n" |
| 932 | "\n" |
| 933 | " gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n" |
| 934 | " while(num_iterations>0)\n" |
| 935 | " {\n" |
| 936 | " vec4 color = texture3D( baseTexture, texcoord);\n" |
| 937 | " float r = color[3]*transparency;\n" |
| 938 | " if (r>alphaCutOff)\n" |
| 939 | " {\n" |
| 940 | " gl_FragColor.xyz = gl_FragColor.xyz*(1.0-r)+color.xyz*r;\n" |
| 941 | " gl_FragColor.w += r;\n" |
| 942 | " }\n" |
| 943 | " texcoord += deltaTexCoord; \n" |
| 944 | "\n" |
| 945 | " --num_iterations;\n" |
| 946 | " }\n" |
| 947 | "\n" |
| 948 | " if (gl_FragColor.w>1.0) gl_FragColor.w = 1.0; \n" |
| 949 | " if (gl_FragColor.w==0.0) discard;\n" |
898 | | if (maximumIntensityProjection) |
899 | | { |
900 | | stateset->setAttribute(new osg::BlendFunc(osg::BlendFunc::ONE, osg::BlendFunc::ONE)); |
901 | | stateset->setAttribute(new osg::BlendEquation(osg::BlendEquation::RGBA_MAX)); |
902 | | } |
| 970 | osg::TexGen* texgen = new osg::TexGen; |
| 971 | texgen->setMode(osg::TexGen::OBJECT_LINEAR); |
| 972 | texgen->setPlane(osg::TexGen::S, osg::Plane(1.0f/xSize,0.0f,0.0f,0.0f)); |
| 973 | texgen->setPlane(osg::TexGen::T, osg::Plane(0.0f,1.0f/ySize,0.0f,0.0f)); |
| 974 | texgen->setPlane(osg::TexGen::R, osg::Plane(0.0f,0.0f,1.0f/zSize,0.0f)); |
| 975 | texgen->setPlane(osg::TexGen::Q, osg::Plane(0.0f,0.0f,0.0f,1.0f)); |
| 976 | |
| 977 | stateset->setTextureAttributeAndModes(0, texgen, osg::StateAttribute::ON); |
918 | | #else |
919 | | (*coords)[0].set(0,0,0); |
920 | | (*coords)[1].set(1.0,0,0); |
921 | | (*coords)[2].set(1.0, 1.0,0); |
922 | | (*coords)[3].set(0,1.0,0); |
923 | | (*coords)[4].set(0,0,1.0); |
924 | | (*coords)[5].set(1.0,0,1.0); |
925 | | (*coords)[6].set(1.0,1.0,1.0); |
926 | | (*coords)[7].set(0,1.0,1.0); |
927 | | geom->setVertexArray(coords); |
928 | | #endif |
929 | | osg::Vec3Array* tcoords = new osg::Vec3Array(8); |
930 | | (*tcoords)[0].set(0,0,0); |
931 | | (*tcoords)[1].set(1,0,0); |
932 | | (*tcoords)[2].set(1,1,0); |
933 | | (*tcoords)[3].set(0,1,0); |
934 | | (*tcoords)[4].set(0,0,1); |
935 | | (*tcoords)[5].set(1,0,1); |
936 | | (*tcoords)[6].set(1,1,1); |
937 | | (*tcoords)[7].set(0,1,1); |
938 | | geom->setTexCoordArray(0,tcoords); |