1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
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.
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.
14#ifndef OSGVOLUME_MULTIPASSTECHNIQUE
15#define OSGVOLUME_MULTIPASSTECHNIQUE 1
17#include <osgVolume/VolumeTechnique>
18#include <osg/MatrixTransform>
19#include <osg/Texture2D>
25class OSGVOLUME_EXPORT MultipassTechnique : public VolumeTechnique
31 MultipassTechnique(const MultipassTechnique&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
33 META_Object(osgVolume, MultipassTechnique);
37 virtual void update(osgUtil::UpdateVisitor* nv);
39 virtual void backfaceSubgraphCullTraversal(osgUtil::CullVisitor* cv);
41 virtual void cull(osgUtil::CullVisitor* cv);
43 /** Clean scene graph from any terrain technique specific nodes.*/
44 virtual void cleanSceneGraph();
46 /** Traverse the terrain subgraph.*/
47 virtual void traverse(osg::NodeVisitor& nv);
56 RenderingMode computeRenderingMode();
58 /** Container for render to texture objects used when doing multi-pass volume rendering techniques.*/
59 struct OSGVOLUME_EXPORT MultipassTileData : public TileData
61 MultipassTileData(osgUtil::CullVisitor* cv, MultipassTechnique* mpt);
63 virtual void update(osgUtil::CullVisitor* cv);
65 void setUp(osg::ref_ptr<osg::Camera>& camera, osg::ref_ptr<osg::Texture2D>& texture2D, int width, int height);
68 osg::observer_ptr<MultipassTechnique> multipassTechnique;
69 RenderingMode currentRenderingMode;
71 osg::ref_ptr<osg::Texture2D> frontFaceDepthTexture;
72 osg::ref_ptr<osg::Camera> frontFaceRttCamera;
74 osg::ref_ptr<osg::Texture2D> backFaceDepthTexture;
75 osg::ref_ptr<osg::Camera> backFaceRttCamera;
77 osg::ref_ptr<osg::Uniform> eyeToTileUniform;
78 osg::ref_ptr<osg::Uniform> tileToImageUniform;
81 /** Called from VolumeScene to create the TileData container when a multi-pass technique is being used.
82 * The TileData container caches any render to texture objects that are required. */
83 virtual TileData* createTileData(osgUtil::CullVisitor* cv) { return new MultipassTileData(cv, this); }
87 virtual ~MultipassTechnique();
89 osg::ref_ptr<osg::MatrixTransform> _transform;
91 typedef std::map<osgUtil::CullVisitor::Identifier*, osg::Matrix> ModelViewMatrixMap;
93 OpenThreads::Mutex _mutex;
94 ModelViewMatrixMap _modelViewMatrixMap;
96 osg::ref_ptr<osg::StateSet> _whenMovingStateSet;
97 osg::ref_ptr<osg::StateSet> _volumeRenderStateSet;
99 osg::StateSet* createStateSet(osg::StateSet* statesetPrototype, osg::Program* programPrototype, osg::Shader* shaderToAdd1=0, osg::Shader* shaderToAdd2=0);
105 CUBE_AND_HULL_SHADERS = 4,
106 STANDARD_SHADERS = 8,
113 typedef std::map<int, osg::ref_ptr<osg::StateSet> > StateSetMap;
114 StateSetMap _stateSetMap;
116 osg::ref_ptr<osg::StateSet> _frontFaceStateSet;