openscenegraph
MultipassTechnique
Go to the documentation of this file.
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
14#ifndef OSGVOLUME_MULTIPASSTECHNIQUE
15#define OSGVOLUME_MULTIPASSTECHNIQUE 1
16
17#include <osgVolume/VolumeTechnique>
18#include <osg/MatrixTransform>
19#include <osg/Texture2D>
20
21namespace osgVolume {
22
23
24
25class OSGVOLUME_EXPORT MultipassTechnique : public VolumeTechnique
26{
27 public:
28
29 MultipassTechnique();
30
31 MultipassTechnique(const MultipassTechnique&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
32
33 META_Object(osgVolume, MultipassTechnique);
34
35 virtual void init();
36
37 virtual void update(osgUtil::UpdateVisitor* nv);
38
39 virtual void backfaceSubgraphCullTraversal(osgUtil::CullVisitor* cv);
40
41 virtual void cull(osgUtil::CullVisitor* cv);
42
43 /** Clean scene graph from any terrain technique specific nodes.*/
44 virtual void cleanSceneGraph();
45
46 /** Traverse the terrain subgraph.*/
47 virtual void traverse(osg::NodeVisitor& nv);
48
49 enum RenderingMode
50 {
51 CUBE,
52 HULL,
53 CUBE_AND_HULL
54 };
55
56 RenderingMode computeRenderingMode();
57
58 /** Container for render to texture objects used when doing multi-pass volume rendering techniques.*/
59 struct OSGVOLUME_EXPORT MultipassTileData : public TileData
60 {
61 MultipassTileData(osgUtil::CullVisitor* cv, MultipassTechnique* mpt);
62
63 virtual void update(osgUtil::CullVisitor* cv);
64
65 void setUp(osg::ref_ptr<osg::Camera>& camera, osg::ref_ptr<osg::Texture2D>& texture2D, int width, int height);
66
67
68 osg::observer_ptr<MultipassTechnique> multipassTechnique;
69 RenderingMode currentRenderingMode;
70
71 osg::ref_ptr<osg::Texture2D> frontFaceDepthTexture;
72 osg::ref_ptr<osg::Camera> frontFaceRttCamera;
73
74 osg::ref_ptr<osg::Texture2D> backFaceDepthTexture;
75 osg::ref_ptr<osg::Camera> backFaceRttCamera;
76
77 osg::ref_ptr<osg::Uniform> eyeToTileUniform;
78 osg::ref_ptr<osg::Uniform> tileToImageUniform;
79 };
80
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); }
84
85 protected:
86
87 virtual ~MultipassTechnique();
88
89 osg::ref_ptr<osg::MatrixTransform> _transform;
90
91 typedef std::map<osgUtil::CullVisitor::Identifier*, osg::Matrix> ModelViewMatrixMap;
92
93 OpenThreads::Mutex _mutex;
94 ModelViewMatrixMap _modelViewMatrixMap;
95
96 osg::ref_ptr<osg::StateSet> _whenMovingStateSet;
97 osg::ref_ptr<osg::StateSet> _volumeRenderStateSet;
98
99 osg::StateSet* createStateSet(osg::StateSet* statesetPrototype, osg::Program* programPrototype, osg::Shader* shaderToAdd1=0, osg::Shader* shaderToAdd2=0);
100
101 enum ShaderMask
102 {
103 CUBE_SHADERS = 1,
104 HULL_SHADERS = 2,
105 CUBE_AND_HULL_SHADERS = 4,
106 STANDARD_SHADERS = 8,
107 LIT_SHADERS = 16,
108 ISO_SHADERS = 32,
109 MIP_SHADERS = 64,
110 TF_SHADERS = 128
111 };
112
113 typedef std::map<int, osg::ref_ptr<osg::StateSet> > StateSetMap;
114 StateSetMap _stateSetMap;
115
116 osg::ref_ptr<osg::StateSet> _frontFaceStateSet;
117};
118
119}
120
121#endif