Changeset 8946 for OpenSceneGraph/trunk/examples/osgvolume/osgvolume.cpp
- Timestamp:
- 09/26/08 13:29:00 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgvolume/osgvolume.cpp
r8936 r8946 59 59 60 60 typedef std::vector< osg::ref_ptr<osg::Image> > ImageList; 61 62 enum ShadingModel 63 { 64 Standard, 65 Light, 66 Isosurface, 67 MaximumIntensityProjection 68 }; 61 69 62 70 // example ReadOperator … … 803 811 }; 804 812 805 osg::Node* createShaderModel(osg::ref_ptr<osg::Image>& image_3d, 813 osg::Node* createShaderModel(ShadingModel shadingModel, 814 osg::ref_ptr<osg::Image>& image_3d, 806 815 osg::Image* normalmap_3d, 807 816 osg::TransferFunction1D* tf, … … 809 818 float xSize, float ySize, float zSize, 810 819 float /*xMultiplier*/, float /*yMultiplier*/, float /*zMultiplier*/, 811 unsigned int /*numSlices*/=500, float /*sliceEnd*/=1.0f, float alphaFuncValue=0.02f , bool maximumIntensityProjection = false)820 unsigned int /*numSlices*/=500, float /*sliceEnd*/=1.0f, float alphaFuncValue=0.02f) 812 821 { 813 822 osg::Texture::FilterMode minFilter = osg::Texture::LINEAR; … … 841 850 program->addShader(new osg::Shader(osg::Shader::VERTEX, volume_vert)); 842 851 } 843 844 852 845 853 if (!(normalmap_3d && tf)) … … 872 880 873 881 874 if (normalmap_3d) 882 if (shadingModel==MaximumIntensityProjection) 883 { 884 if (tf) 885 { 886 osg::Texture1D* texture1D = new osg::Texture1D; 887 texture1D->setImage(tf->getImage()); 888 stateset->setTextureAttributeAndModes(1,texture1D,osg::StateAttribute::ON); 889 890 osg::Shader* fragmentShader = osgDB::readShaderFile(osg::Shader::FRAGMENT, "volume_tf_mip.frag"); 891 if (fragmentShader) 892 { 893 program->addShader(fragmentShader); 894 } 895 else 896 { 897 #include "volume_tf_mip_frag.cpp" 898 program->addShader(new osg::Shader(osg::Shader::FRAGMENT, volume_tf_mip_frag)); 899 } 900 901 osg::Uniform* tfTextureSampler = new osg::Uniform("tfTexture",1); 902 stateset->addUniform(tfTextureSampler); 903 904 } 905 else 906 { 907 osg::Shader* fragmentShader = osgDB::readShaderFile(osg::Shader::FRAGMENT, "volume_mip.frag"); 908 if (fragmentShader) 909 { 910 program->addShader(fragmentShader); 911 } 912 else 913 { 914 #include "volume_mip_frag.cpp" 915 program->addShader(new osg::Shader(osg::Shader::FRAGMENT, volume_mip_frag)); 916 } 917 } 918 } 919 else if (shadingModel==Isosurface) 920 { 921 osg::Uniform* normalMapSampler = new osg::Uniform("normalMap",1); 922 stateset->addUniform(normalMapSampler); 923 924 osg::Texture3D* normalMap = new osg::Texture3D; 925 normalMap->setImage(normalmap_3d); 926 stateset->setTextureAttributeAndModes(1,normalMap,osg::StateAttribute::ON); 927 928 if (tf) 929 { 930 osg::Texture1D* texture1D = new osg::Texture1D; 931 texture1D->setImage(tf->getImage()); 932 stateset->setTextureAttributeAndModes(0,texture1D,osg::StateAttribute::ON); 933 934 osg::Shader* fragmentShader = osgDB::readShaderFile(osg::Shader::FRAGMENT, "volume-tf-iso.frag"); 935 if (fragmentShader) 936 { 937 program->addShader(fragmentShader); 938 } 939 else 940 { 941 #include "volume_tf_iso_frag.cpp" 942 program->addShader(new osg::Shader(osg::Shader::FRAGMENT, volume_tf_iso_frag)); 943 } 944 945 osg::Uniform* tfTextureSampler = new osg::Uniform("tfTexture",0); 946 stateset->addUniform(tfTextureSampler); 947 948 } 949 else 950 { 951 osg::Shader* fragmentShader = osgDB::readShaderFile(osg::Shader::FRAGMENT, "volume_iso.frag"); 952 if (fragmentShader) 953 { 954 program->addShader(fragmentShader); 955 } 956 else 957 { 958 #include "volume_iso_frag.cpp" 959 program->addShader(new osg::Shader(osg::Shader::FRAGMENT, volume_iso_frag)); 960 } 961 } 962 } 963 else if (normalmap_3d) 875 964 { 876 965 osg::notify(osg::NOTICE)<<"Setting up normalmapping shader"<<std::endl; … … 1038 1127 } 1039 1128 1040 osg::Node* createModel(osg::ref_ptr<osg::Image>& image_3d, 1129 osg::Node* createModel(ShadingModel shadeModel, 1130 osg::ref_ptr<osg::Image>& image_3d, 1041 1131 osg::ref_ptr<osg::Image>& normalmap_3d, 1042 1132 osg::Texture::InternalFormatMode internalFormatMode, … … 1134 1224 stateset->setAttributeAndModes(material); 1135 1225 1136 if ( maximumIntensityProjection)1226 if (shadeModel==MaximumIntensityProjection) 1137 1227 { 1138 1228 stateset->setAttribute(new osg::BlendFunc(osg::BlendFunc::ONE, osg::BlendFunc::ONE)); … … 1215 1305 else 1216 1306 { 1217 osg::ref_ptr<osg::Image> normalmap_3d = createNormalMapTexture(image_3d.get());1218 1307 osg::Texture3D* bump_texture3D = new osg::Texture3D; 1219 1308 bump_texture3D->setResizeNonPowerOfTwoHint(false); … … 1715 1804 1716 1805 1806 1807 ShadingModel shadingModel = Standard; 1808 1809 bool maximumIntensityProjection = false; 1810 while(arguments.read("--mip")) shadingModel = MaximumIntensityProjection; 1811 1717 1812 bool createNormalMap = false; 1718 while (arguments.read("-n")) createNormalMap=true; 1719 1720 bool maximumIntensityProjection = false; 1721 while(arguments.read("--mip")) maximumIntensityProjection = true; 1813 while (arguments.read("-n")) 1814 { 1815 shadingModel = Light; 1816 createNormalMap=true; 1817 } 1818 1819 while (arguments.read("--isosurface")) 1820 { 1821 shadingModel = Isosurface; 1822 createNormalMap=true; 1823 } 1722 1824 1723 1825 float xSize=1.0f, ySize=1.0f, zSize=1.0f; … … 2010 2112 if (useShader) 2011 2113 { 2012 rootNode = createShaderModel(image_3d, normalmap_3d.get(), 2114 rootNode = createShaderModel(shadingModel, 2115 image_3d, normalmap_3d.get(), 2013 2116 (gpuTransferFunction ? transferFunction.get() : 0), 2014 2117 internalFormatMode, 2015 2118 xSize, ySize, zSize, 2016 2119 xMultiplier, yMultiplier, zMultiplier, 2017 numSlices, sliceEnd, alphaFunc , maximumIntensityProjection);2120 numSlices, sliceEnd, alphaFunc); 2018 2121 } 2019 2122 else 2020 2123 { 2021 rootNode = createModel(image_3d, normalmap_3d, 2124 rootNode = createModel(shadingModel, 2125 image_3d, normalmap_3d, 2022 2126 internalFormatMode, 2023 2127 xSize, ySize, zSize, 2024 2128 xMultiplier, yMultiplier, zMultiplier, 2025 numSlices, sliceEnd, alphaFunc , maximumIntensityProjection);2129 numSlices, sliceEnd, alphaFunc); 2026 2130 } 2027 2131
