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
00273 class SoVolumeShader : public SoShaderProgram {
00274
00275 SO_NODE_HEADER(SoVolumeShader);
00276
00277 public:
00281 SoVolumeShader();
00282
00289 enum ShaderPosition {
00297 GEOMETRY_MAIN =0,
00298
00338 DATA_COMBINE_FUNCTION,
00339
00391 GET_DATA_FUNCTION,
00392
00453 FRAGMENT_COMPUTE_COLOR,
00454
00469 VERTEX_MAIN,
00470
00483 FRAGMENT_MAIN,
00484
00494 VERTEX_POSTPROCESSING,
00495
00506 CLIPPING_FUNCTION,
00507
00513 CUSTOM_SHADER = 64
00514 };
00515
00531 SoSFBool forVolumeOnly;
00532
00533
00548 SoSFBool interpolateOnMove;
00549
00556 static SbBool isSupported(SoState* state=NULL) ;
00557
00562 virtual SoFragmentShader* setFragmentShader(int pos, const SbString& filenameOrSource,
00563 SoShaderObject::SourceType sourceType = SoShaderObject::FILENAME);
00564
00569 virtual SoVertexShader* setVertexShader(int pos, const SbString& filenameOrSource,
00570 SoShaderObject::SourceType sourceType = SoShaderObject::FILENAME);
00571
00572 #ifndef HIDDEN_FROM_DOC
00573 private:
00574
00579 template<typename T>
00580 T* getCustomShader(const ShaderPosition pos)
00581 {
00582 if (shaderObject.getNum() > pos )
00583 return static_cast<T*>(shaderObject[pos]);
00584 return NULL;
00585 }
00586
00590 template<typename T>
00591 void setupPublicShaderStage(const ShaderPosition stagePos, const char* hiddenName, T* defaultShader)
00592 {
00593 T* fp = getCustomShader<T>(stagePos);
00594
00595 if ( !fp )
00596 setupPrivateShaderStage<T>(hiddenName,defaultShader);
00597 else
00598 removeHiddenShaderObject(hiddenName);
00599 }
00600
00601
00605 template<typename T>
00606 void setupPublicShaderStage(const ShaderPosition stagePos, const char* hiddenName, const SbString& shaderSource)
00607 {
00608 T* fp = getCustomShader<T>(stagePos);
00609
00610 if ( !fp )
00611 setupPrivateShaderStage<T>(hiddenName, shaderSource);
00612 else
00613 removeHiddenShaderObject(hiddenName);
00614 }
00615
00619 bool isInternalFragment(SoFragmentShader* frag) const;
00620
00624 bool isInternalShaderObject(SoShaderObject* obj) const;
00625
00626 virtual void doAction(SoAction *action);
00627
00631 virtual void GLRender( SoGLRenderAction *action );
00632
00636 void installShaderProgram( SoGLRenderAction *action );
00637
00638 virtual void doRendering(SoGLRenderAction *action);
00639
00641 static void initClass() ;
00642
00644 static void exitClass() ;
00645
00650 SbBool isForVolumeOnly() { return forVolumeOnly.getValue(); }
00651
00656 static void setTexCoordVolUniform(SoState*state, SoVolumeData* vd, SoNode* node);
00657
00661 inline bool hasPerTileUniforms() const;
00662
00663 static int getFirstUsedTextureUnit(SoGLRenderAction* action);
00664
00666 void chooseLightConfig(SoState* state, bool forbidVertexTwoSide = false);
00667
00669 virtual void installTextures(SoGLRenderAction* ) {}
00670
00672 virtual SbBool isRaycastingEnabled(SoState* state) const;
00673
00675 virtual SbBool isVolumeGroupEnabled(SoState* state) const;
00676
00678 virtual void allocateTextureUnit(SoGLRenderAction *) const {}
00679
00683 static SbBool isTextureArrayEXTSupported(SoState* state);
00684
00689 static bool isRaycastingDefault()
00690 { return s_forceRaycasting; };
00691
00692
00693 #if 1 SoDEPRECATED
00695 void createRenderModeShaders(){}
00696 #endif
00699 virtual bool isInterpolationActive(SoGLRenderAction* action);
00700
00702 bool mustUseOrthoCamera( SoState* state );
00703
00704 private:
00705
00707 virtual void notify(SoNotList *list);
00708
00712 void installJitteringTexture(SoGLRenderAction* action);
00713
00717 void uninstallJitteringTexture();
00718
00719 ~SoVolumeShader();
00720
00721
00722
00723
00724 static SbString cleanUpFilePath( const SbString& string );
00725
00727 virtual SoShaderProgram* generateShadowShader() const;
00728
00733 void updateShaderSlots( SoState* state );
00734
00738 static const float DEFAULT_GRADIENT_THRESHOLD;
00739
00740 static const float DEFAULT_EDGE_THRESHOLD;
00741
00742 static const float DEFAULT_BOUNDARY_THRESHOLD;
00743 static const float DEFAULT_BOUNDARY_INTENSITY;
00744
00745 #endif //HIDEN_FROM_DOC
00746
00747 #if 1
00749 SoINTERNAL private:
00750 SoDEPRECATED
00751 SoSFBool raycasting;
00752 #endif
00754 private:
00755
00756 static const size_t JITTER_TEX_SIZE;
00757
00761 void createJitterTex();
00762
00767 bool hasToHandleFakeSoVolumeIsosurfaceStyle(SoState* state);
00768 void handleFakeSoVolumeIsosurfaceStyle(SoGLRenderAction* action);
00769
00770 SoRef<SoGroup> m_jitterTextureGroup;
00771 SoRef<SoTextureUnit> m_jitterTextureUnit;
00772 SoRef<SoTexture2> m_jitterTexture;
00773
00775 SoVolumeDataDrawStyle* m_volumeDataDrawStyle;
00776
00777 static int s_texture_array_EXT_extensionID;
00778 static bool s_forceRaycasting;
00779 };
00780
00781 #ifdef _WIN32
00782 #pragma warning(pop)
00783 #endif
00784
00785 #endif
00786
00787
00788