00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _SO_VOLUME_SHADER_H_
00026 #define _SO_VOLUME_SHADER_H_
00027
00028
00029 #include <Inventor/nodes/SoShaderProgram.h>
00030 #include <Inventor/nodes/SoShaderObject.h>
00031 #include <Inventor/nodes/SoFragmentShader.h>
00032 #include <Inventor/nodes/SoVertexShader.h>
00033 #include <Inventor/nodes/SoTextureUnit.h>
00034 #include <VolumeViz/nodes/SoVolumeRender.h>
00035
00036 #include <Inventor/STL/cassert>
00037 #include <Inventor/STL/string>
00038 #include <Inventor/STL/vector>
00039 #include <Inventor/STL/map>
00040
00041
00042
00043 #ifdef _WIN32
00044 #pragma warning(push)
00045 #pragma warning(disable : 4251)
00046 #endif
00047
00048 class SoVolumeData;
00049 class SoIsosurfaceTexture;
00050 class SoVolumeRenderingQuality;
00051 class SoVolumeDataDrawStyle;
00052 class SoInteractiveComplexity;
00053 class SoNodeDependencies;
00054 class SoGroup;
00055 class SoTexture;
00056
00292 class SoVolumeShader : public SoShaderProgram {
00293
00294 SO_NODE_HEADER(SoVolumeShader);
00295
00296 public:
00300 SoVolumeShader();
00301
00308 enum ShaderPosition {
00316 GEOMETRY_MAIN =0,
00317
00357 DATA_COMBINE_FUNCTION,
00358
00410 GET_DATA_FUNCTION,
00411
00529 FRAGMENT_COMPUTE_COLOR,
00530
00545 VERTEX_MAIN,
00546
00559 FRAGMENT_MAIN,
00560
00570 VERTEX_POSTPROCESSING,
00571
00582 CLIPPING_FUNCTION,
00583
00645 TESS_VERTEX_SHIFT,
00646
00652 CUSTOM_SHADER = 64
00653 };
00654
00670 SoSFBool forVolumeOnly;
00671
00672
00687 SoSFBool interpolateOnMove;
00688
00695 static SbBool isSupported(SoState* state=NULL) ;
00696
00701 virtual SoFragmentShader* setFragmentShader(int pos, const SbString& filenameOrSource,
00702 SoShaderObject::SourceType sourceType = SoShaderObject::FILENAME);
00703
00709 virtual SoVertexShader* setVertexShader(int pos, const SbString& filenameOrSource,
00710 SoShaderObject::SourceType sourceType = SoShaderObject::FILENAME);
00711
00712 #ifndef HIDDEN_FROM_DOC
00713 private:
00714
00719 template<typename T>
00720 T* getCustomShader(const ShaderPosition pos)
00721 {
00722 if (shaderObject.getNum() > pos )
00723 return static_cast<T*>(shaderObject[pos]);
00724 return NULL;
00725 }
00726
00730 template<typename T>
00731 T* setupPublicShaderStage(const ShaderPosition stagePos, const char* hiddenName, T* defaultShader)
00732 {
00733 T* fp = getCustomShader<T>(stagePos);
00734
00735 if ( !fp )
00736 return setupPrivateShaderStage<T>(hiddenName,defaultShader);
00737 else
00738 removeHiddenShaderObject(hiddenName);
00739 return fp;
00740 }
00741
00742
00746 template<typename T>
00747 T* setupPublicShaderStage(const ShaderPosition stagePos, const char* hiddenName, const SbString& shaderSource)
00748 {
00749 T* fp = getCustomShader<T>(stagePos);
00750
00751 if ( !fp )
00752 return setupPrivateShaderStage<T>(hiddenName, shaderSource);
00753 else
00754 removeHiddenShaderObject(hiddenName);
00755 return fp;
00756 }
00757
00762 template<typename T>
00763 T* setupPrivateShaderStageNoOverride(const char* hiddenName, const SbString& shaderSource)
00764 {
00765 T* fp = (T*) getHiddenShaderObject(hiddenName);
00766 if (fp == nullptr)
00767 {
00768 fp = new T;
00769 fp->sourceProgram.setValue(shaderSource);
00770 setHiddenShaderObject(hiddenName, fp);
00771 }
00772 return fp;
00773 }
00774
00779 template<typename T>
00780 T* setupPublicShaderStageNoOverride(const ShaderPosition stagePos, const char* hiddenName, const SbString& shaderSource)
00781 {
00782 T* fp = getCustomShader<T>(stagePos);
00783 if (fp == nullptr)
00784 return setupPrivateShaderStageNoOverride<T>(hiddenName, shaderSource);
00785 else
00786 removeHiddenShaderObject(hiddenName);
00787 return fp;
00788 }
00789
00793 bool isInternalFragment(SoFragmentShader* frag) const;
00794
00798 bool isInternalShaderObject(SoShaderObject* obj) const;
00799
00800 virtual void doAction(SoAction *action);
00801
00805 virtual void GLRender( SoGLRenderAction *action );
00806
00810 void installShaderProgram( SoGLRenderAction *action );
00811
00812 virtual void doRendering(SoGLRenderAction *action);
00813
00815 static void initClass() ;
00816
00818 static void exitClass() ;
00819
00824 SbBool isForVolumeOnly() { return forVolumeOnly.getValue(); }
00825
00830 static void setTexCoordVolUniform(SoState*state, SoVolumeData* vd, SoNode* node);
00831
00832 static int getFirstUsedTextureUnit(SoGLRenderAction* action);
00833
00835 void chooseLightConfig(SoState* state, bool forbidVertexTwoSide = false);
00836
00838 virtual void installTextures(SoGLRenderAction* ) {}
00839
00841 virtual SbBool isRaycastingEnabled(SoState* state) const;
00842
00844 virtual SbBool isVolumeGroupEnabled(SoState* state) const;
00845
00847 virtual void allocateTextureUnit(SoGLRenderAction *) const {}
00848
00852 static SbBool isTextureArrayEXTSupported(SoState* state);
00853
00858 static bool isRaycastingDefault()
00859 { return s_forceRaycasting; };
00860
00861
00862 #if 1 SoDEPRECATED
00864 void createRenderModeShaders(){}
00865 #endif
00868 virtual bool isInterpolationActive(SoGLRenderAction* action);
00869
00871 bool mustUseOrthoCamera( SoState* state );
00872
00873 private:
00874
00876 virtual void notify(SoNotList *list);
00877
00881 void installJitteringTexture(SoGLRenderAction* action);
00882
00886 void uninstallJitteringTexture();
00887
00888 ~SoVolumeShader();
00889
00890
00891
00892
00893 static SbString cleanUpFilePath( const SbString& string );
00894
00896 virtual SoShaderProgram* generateShadowShader() const;
00897
00902 void updateShaderSlots( SoState* state );
00903
00907 static const float DEFAULT_GRADIENT_THRESHOLD;
00908
00909 static const float DEFAULT_EDGE_THRESHOLD;
00910
00911 static const float DEFAULT_BOUNDARY_THRESHOLD;
00912 static const float DEFAULT_BOUNDARY_INTENSITY;
00913
00914 #endif //HIDEN_FROM_DOC
00915
00916 #if 1
00918 SoINTERNAL private:
00919 SoDEPRECATED
00920 SoSFBool raycasting;
00921 #endif
00923 private:
00924
00925 static const size_t JITTER_TEX_SIZE;
00926
00930 void createJitterTex();
00931
00936 bool hasToHandleFakeSoVolumeIsosurfaceStyle(SoState* state);
00937 void handleFakeSoVolumeIsosurfaceStyle(SoGLRenderAction* action);
00938
00939 SoRef<SoGroup> m_jitterTextureGroup;
00940 SoRef<SoTextureUnit> m_jitterTextureUnit;
00941 SoRef<SoTexture2> m_jitterTexture;
00942
00944 SoVolumeDataDrawStyle* m_volumeDataDrawStyle;
00945
00946 static int s_texture_array_EXT_extensionID;
00947 static bool s_forceRaycasting;
00948 };
00949
00950 #ifdef _WIN32
00951 #pragma warning(pop)
00952 #endif
00953
00954 #endif
00955
00956
00957