Changeset 13041 for OpenSceneGraph/trunk/include/osgShadow/OccluderGeometry
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgShadow/OccluderGeometry
r7038 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 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 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 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 30 30 * OccluderGeometry supports the computation of silhouette edges and shadow volume geometries, as well as use as geometry that one can rendering 31 31 * into a shadow map or end caps for the ZP+ algorithm. OccluderGeometry may be of the same resolution as an underlying geometry that it 32 * represents, or can be of lower resolution and combine manager seperate geometries together into a single shadow casting object. 32 * represents, or can be of lower resolution and combine manager seperate geometries together into a single shadow casting object. 33 33 * OccluderGeometry may be attached as UserData to Nodes or to Drawables. */ 34 34 class OSGSHADOW_EXPORT OccluderGeometry : public osg::Drawable … … 38 38 39 39 OccluderGeometry(const OccluderGeometry& oc, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 40 40 41 41 virtual Object* cloneType() const { return new OccluderGeometry(); } 42 42 virtual Object* clone(const osg::CopyOp& copyop) const { return new OccluderGeometry(*this,copyop); } … … 44 44 virtual const char* libraryName() const { return "osgShadow"; } 45 45 virtual const char* className() const { return "OccluderGeometry"; } 46 46 47 47 /** Compute an occluder geometry containing all the geometry in specified subgraph.*/ 48 48 void computeOccluderGeometry(osg::Node* subgraph, osg::Matrix* matrix=0, float sampleRatio=1.0f); 49 49 50 50 /** Compute an occluder geometry containing the geometry in specified drawable.*/ 51 51 void computeOccluderGeometry(osg::Drawable* drawable, osg::Matrix* matrix=0, float sampleRatio=1.0f); 52 52 53 53 54 54 /** Compute ShadowVolumeGeometry. */ 55 55 void computeShadowVolumeGeometry(const osg::Vec4& lightpos, ShadowVolumeGeometry& svg) const; 56 56 57 57 58 58 /** Set the bounding polytope of the OccluderGeometry.*/ 59 59 void setBoundingPolytope(const osg::Polytope& polytope) { _boundingPolytope = polytope; } … … 68 68 /** Render the occluder geometry. */ 69 69 virtual void drawImplementation(osg::RenderInfo& renderInfo) const; 70 70 71 71 /** Compute the bounding box around occluder geometry.*/ 72 72 virtual osg::BoundingBox computeBound() const; … … 82 82 83 83 virtual ~OccluderGeometry() {} 84 84 85 85 struct Edge 86 86 { … … 104 104 } 105 105 } 106 106 107 107 inline bool operator < (const Edge& rhs) const 108 108 { … … 111 111 return (_p2 < rhs._p2); 112 112 } 113 113 114 114 bool addTriangle(unsigned int tri) const 115 115 { … … 127 127 return false; 128 128 } 129 129 130 130 bool boundaryEdge() const { return _t2<0; } 131 131 132 132 unsigned int _p1; 133 133 unsigned int _p2; 134 134 135 135 mutable int _t1; 136 136 mutable int _t2; 137 137 138 138 mutable osg::Vec3 _normal; 139 139 }; … … 144 144 { 145 145 if (edge.boundaryEdge()) return true; 146 146 147 147 float offset = 0.0f; 148 148 149 149 osg::Vec3 delta(lightpos-_vertices[edge._p1]); 150 150 delta.normalize(); 151 151 152 152 float n1 = delta * _triangleNormals[edge._t1] + offset; 153 153 float n2 = delta * _triangleNormals[edge._t2] + offset; … … 159 159 160 160 if (n1==0.0f && n2==0.0f) return false; 161 162 return n1*n2 <= 0.0f; 161 162 return n1*n2 <= 0.0f; 163 163 } 164 164 … … 166 166 { 167 167 if (edge.boundaryEdge()) return true; 168 168 169 169 float offset = 0.0f; 170 170 171 171 float n1 = lightdirection * _triangleNormals[edge._t1] + offset; 172 172 float n2 = lightdirection * _triangleNormals[edge._t2] + offset; … … 178 178 179 179 if (n1==0.0f && n2==0.0f) return false; 180 181 return n1*n2 <= 0.0f; 180 181 return n1*n2 <= 0.0f; 182 182 } 183 183 184 184 void setUpInternalStructures(); 185 185 186 186 void removeDuplicateVertices(); 187 187 void removeNullTriangles(); 188 188 void computeNormals(); 189 189 void buildEdgeMaps(); 190 190 191 191 void computeLightDirectionSilhouetteEdges(const osg::Vec3& lightdirection, UIntList& silhouetteIndices) const; 192 192 void computeLightPositionSilhouetteEdges(const osg::Vec3& lightpos, UIntList& silhouetteIndices) const; … … 198 198 Vec3List _triangleNormals; 199 199 UIntList _triangleIndices; 200 200 201 201 EdgeList _edges; 202 202 }; … … 208 208 209 209 ShadowVolumeGeometry(const ShadowVolumeGeometry& oc, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 210 210 211 211 virtual Object* cloneType() const { return new ShadowVolumeGeometry(); } 212 212 virtual Object* clone(const osg::CopyOp& copyop) const { return new ShadowVolumeGeometry(*this,copyop); } … … 221 221 STENCIL_TWO_SIDED 222 222 }; 223 223 224 224 void setDrawMode(DrawMode mode) { _drawMode = mode; } 225 225 DrawMode getDrawMode() const { return _drawMode; } … … 227 227 typedef std::vector<osg::Vec3> Vec3List; 228 228 typedef std::vector<GLuint> UIntList; 229 229 230 230 void setVertices(const Vec3List& vertices) { _vertices = vertices; } 231 231 Vec3List& getVertices() { return _vertices; } 232 232 const Vec3List& getVertices() const { return _vertices; } 233 233 234 234 void setNormals(const Vec3List& normals) { _normals = normals; } 235 235 Vec3List& getNormals() { return _normals; } 236 236 const Vec3List& getNormals() const { return _normals; } 237 237 238 238 239 239 /** Render the occluder geometry. */ 240 240 virtual void drawImplementation(osg::RenderInfo& renderInfo) const; 241 241 242 242 /** Compute the bounding box around occluder geometry.*/ 243 243 virtual osg::BoundingBox computeBound() const;
