MultipassTechnique 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSGVOLUME_MULTIPASSTECHNIQUE
  14. #define OSGVOLUME_MULTIPASSTECHNIQUE 1
  15. #include <osgVolume/VolumeTechnique>
  16. #include <osg/MatrixTransform>
  17. #include <osg/Texture2D>
  18. namespace osgVolume {
  19. class OSGVOLUME_EXPORT MultipassTechnique : public VolumeTechnique
  20. {
  21. public:
  22. MultipassTechnique();
  23. MultipassTechnique(const MultipassTechnique&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  24. META_Object(osgVolume, MultipassTechnique);
  25. virtual void init();
  26. virtual void update(osgUtil::UpdateVisitor* nv);
  27. virtual void backfaceSubgraphCullTraversal(osgUtil::CullVisitor* cv);
  28. virtual void cull(osgUtil::CullVisitor* cv);
  29. /** Clean scene graph from any terrain technique specific nodes.*/
  30. virtual void cleanSceneGraph();
  31. /** Traverse the terrain subgraph.*/
  32. virtual void traverse(osg::NodeVisitor& nv);
  33. enum RenderingMode
  34. {
  35. CUBE,
  36. HULL,
  37. CUBE_AND_HULL
  38. };
  39. RenderingMode computeRenderingMode();
  40. /** Container for render to texture objects used when doing multi-pass volume rendering techniques.*/
  41. struct OSGVOLUME_EXPORT MultipassTileData : public TileData
  42. {
  43. MultipassTileData(osgUtil::CullVisitor* cv, MultipassTechnique* mpt);
  44. virtual void update(osgUtil::CullVisitor* cv);
  45. void setUp(osg::ref_ptr<osg::Camera>& camera, osg::ref_ptr<osg::Texture2D>& texture2D, int width, int height);
  46. osg::observer_ptr<MultipassTechnique> multipassTechnique;
  47. RenderingMode currentRenderingMode;
  48. osg::ref_ptr<osg::Texture2D> frontFaceDepthTexture;
  49. osg::ref_ptr<osg::Camera> frontFaceRttCamera;
  50. osg::ref_ptr<osg::Texture2D> backFaceDepthTexture;
  51. osg::ref_ptr<osg::Camera> backFaceRttCamera;
  52. osg::ref_ptr<osg::Uniform> eyeToTileUniform;
  53. osg::ref_ptr<osg::Uniform> tileToImageUniform;
  54. };
  55. /** Called from VolumeScene to create the TileData container when a multi-pass technique is being used.
  56. * The TileData container caches any render to texture objects that are required. */
  57. virtual TileData* createTileData(osgUtil::CullVisitor* cv) { return new MultipassTileData(cv, this); }
  58. protected:
  59. virtual ~MultipassTechnique();
  60. osg::ref_ptr<osg::MatrixTransform> _transform;
  61. typedef std::map<osgUtil::CullVisitor::Identifier*, osg::Matrix> ModelViewMatrixMap;
  62. OpenThreads::Mutex _mutex;
  63. ModelViewMatrixMap _modelViewMatrixMap;
  64. osg::ref_ptr<osg::StateSet> _whenMovingStateSet;
  65. osg::ref_ptr<osg::StateSet> _volumeRenderStateSet;
  66. osg::StateSet* createStateSet(osg::StateSet* statesetPrototype, osg::Program* programPrototype, osg::Shader* shaderToAdd1=0, osg::Shader* shaderToAdd2=0);
  67. enum ShaderMask
  68. {
  69. CUBE_SHADERS = 1,
  70. HULL_SHADERS = 2,
  71. CUBE_AND_HULL_SHADERS = 4,
  72. STANDARD_SHADERS = 8,
  73. LIT_SHADERS = 16,
  74. ISO_SHADERS = 32,
  75. MIP_SHADERS = 64,
  76. TF_SHADERS = 128
  77. };
  78. typedef std::map<int, osg::ref_ptr<osg::StateSet> > StateSetMap;
  79. StateSetMap _stateSetMap;
  80. osg::ref_ptr<osg::StateSet> _frontFaceStateSet;
  81. };
  82. }
  83. #endif