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 <VolumeViz/nodes/SoVolumeRender.h>
00034
00035 #include <Inventor/STL/cassert>
00036 #include <Inventor/STL/string>
00037 #include <Inventor/STL/vector>
00038 #include <Inventor/STL/map>
00039
00040
00041
00042 #ifdef _WIN32
00043 #pragma warning(push)
00044 #pragma warning(disable : 4251)
00045 #endif
00046
00047 class SoVolumeData;
00048 class SoGLTexture;
00049 class SoIsosurfaceTexture;
00050 class SoVolumeRenderingQuality;
00051 class SoVolumeDataDrawStyle;
00052 class SoInteractiveComplexity;
00053
00271 class SoVolumeShader : public SoShaderProgram {
00272
00273 SO_NODE_HEADER(SoVolumeShader);
00274
00275 public:
00279 SoVolumeShader();
00280
00287 enum ShaderPosition {
00296 GEOMETRY_MAIN =0,
00297
00337 DATA_COMBINE_FUNCTION,
00338
00390 GET_DATA_FUNCTION,
00391
00452 FRAGMENT_COMPUTE_COLOR,
00453
00468 VERTEX_MAIN,
00469
00483 FRAGMENT_MAIN,
00484
00494 VERTEX_POSTPROCESSING,
00495
00506 CLIPPING_FUNCTION,
00507
00513 CUSTOM_SHADER = 64
00514 };
00515
00531 SoSFBool forVolumeOnly;
00532
00533 #if 1 SoDEPRECATED
00541 SoSFBool raycasting;
00542 #endif
00558 SoSFBool interpolateOnMove;
00559
00566 static SbBool isSupported(SoState* state=NULL) ;
00567
00572 virtual SoFragmentShader* setFragmentShader(int pos, const SbString& filenameOrSource,
00573 SoShaderObject::SourceType sourceType = SoShaderObject::FILENAME);
00574
00579 virtual SoVertexShader* setVertexShader(int pos, const SbString& filenameOrSource,
00580 SoShaderObject::SourceType sourceType = SoShaderObject::FILENAME);
00581
00582 #if 1 SoDEPRECATED
00585 void setForVolumeOnly(SbBool volOnly) { forVolumeOnly = volOnly; }
00586
00587 #endif
00589 #ifndef HIDDEN_FROM_DOC
00590 private:
00591
00596 template<typename T>
00597 T* getCustomShader(const ShaderPosition pos)
00598 {
00599 if (shaderObject.getNum() > pos )
00600 return static_cast<T*>(shaderObject[pos]);
00601 return NULL;
00602 }
00603
00607 template<typename T>
00608 void setupPrivateShaderStage(const char* hiddenName, T* defaultShader)
00609 {
00610
00611 T* fp = (T*)getHiddenShaderObject(hiddenName);
00612 if ( !fp || (fp!=defaultShader) )
00613 setHiddenShaderObject(hiddenName, defaultShader);
00614 }
00615
00619 template<typename T>
00620 void setupPublicShaderStage(const ShaderPosition stagePos, const char* hiddenName, T* defaultShader)
00621 {
00622 T* fp = getCustomShader<T>(stagePos);
00623
00624 if ( !fp )
00625 setupPrivateShaderStage<T>(hiddenName,defaultShader);
00626 else
00627 removeHiddenShaderObject(hiddenName);
00628 }
00629
00633 template<typename T>
00634 void setupPrivateShaderStage(const char* hiddenName, const SbString& shaderSource)
00635 {
00636
00637 T* fp = (T*)getHiddenShaderObject(hiddenName);
00638 if ( !fp || (fp->sourceProgram.getValue() != shaderSource) )
00639 {
00640 fp = new T;
00641 fp->sourceProgram.setValue(shaderSource);
00642 setHiddenShaderObject(hiddenName, fp);
00643 }
00644 }
00645
00649 template<typename T>
00650 void setupPublicShaderStage(const ShaderPosition stagePos, const char* hiddenName, const SbString& shaderSource)
00651 {
00652 T* fp = getCustomShader<T>(stagePos);
00653
00654 if ( !fp )
00655 setupPrivateShaderStage<T>(hiddenName, shaderSource);
00656 else
00657 removeHiddenShaderObject(hiddenName);
00658 }
00659
00663 bool isInternalFragment(SoFragmentShader* frag) const;
00664
00668 bool isInternalShaderObject(SoShaderObject* obj) const;
00669
00670 virtual void doAction(SoAction *action);
00671
00675 virtual void GLRender(SoGLRenderAction *action);
00676
00677 virtual void doRendering(SoGLRenderAction *action, SbBool resetShader=TRUE);
00678
00680 static void initClass() ;
00681
00683 static void exitClass() ;
00684
00689 SbBool isForVolumeOnly() { return forVolumeOnly.getValue(); }
00690
00696 void useFrontToBack(bool flag, SoGLRenderAction* action);
00697
00702 static void setTexCoordVolUniform(SoState*state, SoVolumeData* vd);
00703
00707 static void setDimensionUniforms( SoState* state,
00708 const SbVec3i32 &volumeDim,
00709 const SbVec3i32 &tileDim );
00710
00714 void setPerTileUniforms(const SbVec3i32 &tileMinIJK, const SbVec3i32 &tileMaxIJK );
00715
00719 inline bool hasPerTileUniforms() const;
00720
00721 static int getFirstUsedTextureUnit(SoGLRenderAction* action);
00722
00726 void setupRectilinearCoordinates(SoState *state);
00727
00731 void setPerTileRectilinear(const SbVec3f& tileOrigin,
00732 const SbVec3f& tileFactor,
00733 const SbVec3f&, const SbVec3f&);
00734
00738 void setDataProjectionMode(SoState* state, bool flag);
00739
00743 static unsigned int getEarlyzTextureUnit(SoGLRenderAction* action);
00744
00748 void enableUndefinedValueShader(bool flag);
00749
00751 void chooseLightConfig(SoState* state, bool forbidVertexTwoSide = false);
00752
00754 virtual void installTextures(SoGLRenderAction* action);
00755
00760 void enableColorInterpolation(bool flag);
00761
00763 virtual SbString getNeededVertexMainFilename(SoState* state);
00764
00766 virtual SbString getNeededFragmentMainFilename(SoState* state);
00767
00769 virtual SbString getRenderingModeFragmentName(SoState* state);
00770
00772 virtual SbBool isRaycastingEnabled(SoState* state) const;
00773
00775 virtual SbBool isVolumeGroupEnabled(SoState* state) const;
00776
00778 virtual void allocateTextureUnit(SoGLRenderAction *) const {}
00779
00780
00781 void setTextureSamplers(SoGLRenderAction* action);
00782
00786 static SbBool isTextureArrayEXTSupported(SoState* state);
00787
00792 static bool isRaycastingDefault()
00793 { return s_forceRaycasting; };
00794
00795 private:
00796
00797 #if 1 SoDEPRECATED
00799 void createRenderModeShaders(){}
00800 #endif
00803 virtual bool isInterpolationActive(SoGLRenderAction* action);
00804
00806 virtual void notify(SoNotList *list);
00807
00808 enum GradientMethod
00809 {
00810 GRADIENT_FORWARD_DIFF = 0,
00811 GRADIENT_CENTRAL_DIFF,
00812 GRADIENT_SOBEL,
00813 GRADIENT_LAST
00814 };
00815
00816 enum LightingModel
00817 {
00818 OIV6,
00819 OPENGL,
00820 LIGHTING_MODEL_LAST
00821 };
00822
00823 typedef enum
00824 {
00825 ONE_LIGHT_DIR,
00826 ONE_LIGHT_DIR_2_SIDES,
00827 N_LIGHTS_DIR,
00828 N_LIGHTS,
00829 BASE_COLOR,
00830 LAST_LIGHTING_CONFIG
00831 } LightingConfig;
00832
00834 void setLightingConfig(LightingConfig conf);
00835
00837 void installIsosurfaceTexture(SoGLRenderAction* action);
00838
00842 void createGradientShaders();
00843
00847 void setGradientMethod(GradientMethod method);
00848
00852 void createLightingModelShaders();
00853
00857 void setLightingModel(LightingModel model);
00858
00862 void enableNprShader(bool flag, SoVolumeRenderingQuality* vrq);
00863
00867 void enableBoundaryOpacityShader(bool flag, float boundaryIntensity,
00868 float boundaryThreshold);
00869
00873 void enableEdgeColoringShader(bool flag, const SbColor& edgeColor,
00874 float threshold);
00875
00879 void enableJitteringShader(bool flag);
00880
00884 void enableSegmentedInterpolation(bool flag);
00885
00889 void enableEdgeImageSpaceShader(bool flag, unsigned int edge2DMethod);
00890
00894 void enableMrt();
00895
00899 void enableBumpFunctions(bool flag);
00900
00904 void enableSliceDefaultMain(bool flag);
00905
00909 void installJitteringTexture(SoGLRenderAction* action);
00910
00914 void uninstallJitteringTexture();
00915
00919 void updateEdgeColoringUniforms(const SbVec3f& color, float threshold);
00920
00924 void updateBoundaryOpacityUniforms(float intensity, float threshold);
00925
00929 void updateGradientUniform(float threshold);
00930
00931
00932 void updateVolumeClippingParameters(SoGLRenderAction* action);
00933
00934
00935 void updateGridClippingParameters(SoState *state);
00936
00937
00938 SbBool hasClippingNodesInState(SoState *state);
00939
00940 ~SoVolumeShader();
00941
00942 int m_datumSize;
00943
00944
00945 void checkProjectionType(SoGLRenderAction* action);
00946
00947
00948 SoVertexShader *createVertexProgram(const SbString &shader);
00949 SoFragmentShader *createFragmentProgram(const SbString &shader);
00950
00951
00952
00953
00954 static SbString cleanUpFilePath( const SbString& string );
00955
00957 virtual SoShaderProgram* generateShadowShader() const;
00958
00963 void updateShaderSlots( SoState* state );
00964
00968 static const float DEFAULT_GRADIENT_THRESHOLD;
00969
00970 static const float DEFAULT_EDGE_THRESHOLD;
00971
00972 static const float DEFAULT_BOUNDARY_THRESHOLD;
00973 static const float DEFAULT_BOUNDARY_INTENSITY;
00974
00975 SoIsosurfaceTexture* m_isosurfaceTexture;
00976
00977 #endif //HIDEN_FROM_DOC
00978
00979 private:
00980
00982 void updateDataDrawStyleCache(SoState* state);
00983
00984 static const size_t JITTER_TEX_SIZE;
00985
00987 void createLightingFragmentShader();
00988
00992 void createJitterTex(SoState* state, size_t size);
00993
00997 void getUniformsLocation();
00998
01003 bool hasToHandleFakeSoVolumeIsosurfaceStyle(SoState* state);
01004 void handleFakeSoVolumeIsosurfaceStyle(SoGLRenderAction* action);
01005
01006 SoGLTexture* m_jitterTex;
01007
01008 int m_previousProjectionType;
01009 bool m_useFrontToBack;
01010
01011 enum ClippingMode {
01012 CLIP_MODE_VOLUME = (1 << 1),
01013 CLIP_MODE_UNIFORM_GRID = (1 << 2),
01014 CLIP_MODE_NONE = 0
01015 };
01016
01017 enum DefaultMainPos {
01018 DEFAULT_FRAG_VOLUME = 0,
01019 DEFAULT_FRAG_SLICE,
01020 DEFAULT_FRAG_LAST
01021 };
01022
01023 int m_currentClippingModeMask;
01024
01025 SoGLTexture *m_rectilinearMappingTex;
01026
01027 SoFragmentShader* m_computeRectilinearCoordinates;
01028 SoFragmentShader* m_computeUniformCoordinates;
01029
01030 SoShaderParameter3f* m_VVizRootTileDimensions;
01031 SoShaderParameter3f* m_VVizTileFactor;
01032 SoShaderParameter3f* m_VVizTileOrigin;
01033 SoShaderParameter1i* m_VVizRectilinearMappingSize;
01034
01035 SoFragmentShader* m_defaultMainFragment[DEFAULT_FRAG_LAST];
01036
01037 GLint m_vvizTileMaxIJK;
01038 GLint m_vvizTileMinIJK;
01039
01040 size_t m_numUniformGridClipping;
01041
01045 std::vector<SoFragmentShader*> m_gradientShaders;
01046 GradientMethod m_currentGradientMethod;
01047
01051 std::vector<SoFragmentShader*> m_lightingModelShaders;
01052 LightingModel m_currentLightingModel;
01053
01054 bool m_heightFieldLightingEnaled;
01055
01057 unsigned int m_edge2dMethod;
01058 bool m_edgeImageSpaceEnabled;
01059 bool m_mrtEnabled;
01060 bool m_boundaryOpacityEnabled;
01061 bool m_jitterEnabled;
01062 bool m_edjeColoringEnabled;
01063 bool m_nprEnabled;
01064 bool m_nprNeedGradient;
01065 bool m_undefinedValueEnabled;
01066
01067 SbVec3f m_edgeColor;
01068 float m_edgeThreshold;
01069
01070 float m_gradientThreshold;
01071
01072 float m_boundaryOpacityThreshold;
01073 float m_boundaryOpacityIntensity;
01074
01078 bool m_colorInterpolation;
01079
01083 SoShaderParameter3f* m_vvizDepthTexSize;
01084 SoShaderParameter3f* m_vvizOneOverDepthTexSize;
01085 SoShaderParameter1f* m_vvizExclusive;
01086 SoShaderParameter1f* m_vvizNumLayers;
01087 SoShaderParameter1f* m_vvizNumPassUsed;
01088
01090 std::vector<SoFragmentShader*> m_lightingFragmentShader;
01091 LightingConfig m_curLight;
01092
01094 SoVolumeDataDrawStyle* m_volumeDataDrawStyle;
01095
01096 SoCache* m_dataDrawStyleCache;
01097
01098 static int s_texture_array_EXT_extensionID;
01099 static bool s_forceRaycasting;
01100 };
01101
01102 #ifndef HIDDEN_FROM_DOC
01103
01104 bool
01105 SoVolumeShader::hasPerTileUniforms() const
01106 {
01107 return m_vvizTileMinIJK != -1 || m_vvizTileMaxIJK != -1;
01108 }
01109
01110 #endif // HIDDEN_FROM_DOC
01111 #ifdef _WIN32
01112 #pragma warning(pop)
01113 #endif
01114
01115 #endif
01116
01117
01118