| VRS - The Virtual Rendering System |
| version 3.3 |
00001 /********************************************************************** 00002 VRS - The Virtual Rendering System 00003 Copyright (C) 2001 Computer Graphics Systems Group at the 00004 Hasso-Plattner-Institute, Potsdam, Germany. 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 This library is distributed in the hope that it will be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 See the GNU Lesser General Public License for more details. 00013 You should have received a copy of the GNU Lesser+ General Public 00014 License along with this library; if not, write to the FreeSoftware 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA, 02111-1307, USA. 00016 **********************************************************************/ 00017 // $Id: depthmapshadowtechniquegl.h 6014 2007-08-09 07:51:16Z Konstantin_Baumann $ 00018 // $Date: 2007-08-09 09:51:16 +0200 (Thu, 09 Aug 2007) $ 00019 // $Revision: 6014 $ 00020 // $State$ 00021 // $Author: Konstantin_Baumann $ 00022 // 00023 // $Log$ 00024 // Revision 1.46 2005/01/03 01:43:09 klimetschek 00025 // - modified win32 project layout, splitted vrs.vcproj into vrs_container, vrs_core, vrs_sg, vrs_image, vrs_opengl and vrs_io 00026 // - removed vrs.vcproj 00027 // minor things: 00028 // - added all glutexamples to vrs4glut.sln 00029 // - fixed some problems in glutexamples 00030 // - removed all project references from all VS projects (using solution wide project dependencies instead) 00031 // 00032 // Revision 1.45 2004/10/26 18:53:13 kirsch 00033 // added static and dynamic shadow map calculation modes 00034 // 00035 // Revision 1.44 2004/10/21 14:53:27 kirsch 00036 // use cached resource for holding internal textures 00037 // 00038 // Revision 1.43 2004/08/05 14:47:10 kirsch 00039 // numerous cleanups and minor changes 00040 // 00041 // Revision 1.42 2004/06/25 13:52:03 kirsch 00042 // updated comments 00043 // 00044 // Revision 1.41 2004/06/17 14:34:53 kirsch 00045 // cleanup: made pass_ and passArray_ private; added trivial accesor methods for them 00046 // removed hack to collapse shadow map projection and light application pass 00047 // (made more trouble than it was worth) 00048 // 00049 // Revision 1.40 2004/05/06 15:43:33 kirsch 00050 // made some internal methods static such that they can be used from other places 00051 // 00052 // Revision 1.39 2004/03/12 16:28:40 baumann 00053 // macros VRS_NAMESPACE_BEGIN/_END expanded and removed 00054 // 00055 // Revision 1.38 2004/02/01 10:10:35 kirsch 00056 // fix for bug #6: initialize depthMapResolution in constructor 00057 // 00058 // Revision 1.37 2004/01/19 11:43:58 baumann 00059 // serialization mechanism improved 00060 // 00061 // Revision 1.36 2003/11/07 14:19:25 kirsch 00062 // removed leading underscore from include guards 00063 // 00064 // Revision 1.35 2003/07/03 16:21:58 kirsch 00065 // added a hack that allows to collapse depthmap projection and light 00066 // application in a single pass 00067 // 00068 // Revision 1.34 2003/07/03 12:14:03 kirsch 00069 // fixed accuracy issue that showed up when using the lookat maniupulator 00070 // 00071 // Revision 1.33 2002/12/12 15:25:54 kirsch 00072 // changed order of includes, due to errors when used in external projects 00073 // 00074 // Revision 1.32 2002/12/12 09:06:38 kirsch 00075 // removed OpenGL extension ifdefs 00076 // added isSupported() to allow silent extension check. 00077 // rate() now checks extensions silently, canBeUsed() is verbose 00078 // serialization was incomplete 00079 // 00080 // Revision 1.31 2002/12/12 08:06:04 kirsch 00081 // comment fixed 00082 // 00083 // Revision 1.30 2002/12/11 16:22:25 kirsch 00084 // merged with more advanced private version of shadow technique 00085 // - ShadowTechniqueGL is now a factory that choses between the "best" shadow technique 00086 // You best use this technique in the scene graph. 00087 // - ShadowTechniqueTemplateGL is a template pattern which should be used for concrete shadow techniques 00088 // - DepthmapShadowTechniqueGL is abstract base class for 00089 // - DepthTextureShadowTechniqueGL (shadows with depth-textures) 00090 // - AlphaTextureShadowTechniqueGL (shadows with alpha-textures) 00091 // 00092 // Revision 1.29 2002/12/02 16:40:46 kirsch 00093 // cleanup, use TextureUnitSettingGL for texture related settings 00094 // 00095 // Revision 1.28 2002/11/29 09:52:17 kirsch 00096 // partly merged with more advanced private version of shadow technique 00097 // (results in changes to protected methods) 00098 // set shadinghint 00099 // 00100 // Revision 1.27 2002/10/29 10:32:52 baumann 00101 // macros VRS_CLASSNAME_* and VRS_IMPL_TYPEINFO_* removed 00102 // 00103 // Revision 1.26 2002/10/28 14:23:17 kirsch 00104 // use static versions of pbuffermanagergl::prepareContext / releaseContext 00105 // 00106 // Revision 1.25 2002/10/24 10:56:26 kirsch 00107 // use PBufferManagerGL 00108 // 00109 // Revision 1.24 2002/10/10 14:43:42 kirsch 00110 // comparison between signed/unsigned warning fix 00111 // 00112 // Revision 1.23 2002/09/03 09:35:36 kirsch 00113 // various changes: 00114 // - use TextureUnitSelectorGL instead of switching textures manually 00115 // - use TexEnvGL::SubtractWithBiasOneHalf instead of manual setup 00116 // - disregard TextureGL (because of texture - category() changes) 00117 // 00118 // Revision 1.22 2002/07/04 14:23:57 kirsch 00119 // removed IteratorWrapper 00120 // 00121 // Revision 1.21 2002/07/02 06:12:34 baumann 00122 // VRS::Iterator<T> completely rewritten 00123 // 00124 // Revision 1.20 2002/05/14 12:41:30 kirsch 00125 // ameliorate resolution of depth map by regarding only shadow casting 00126 // shapes for it 00127 // interface cleanup 00128 // 00129 // Revision 1.19 2002/04/25 08:29:43 kirsch 00130 // added persistency 00131 // 00132 // Revision 1.18 2002/04/12 12:29:58 kirsch 00133 // updated due to p-buffer changes 00134 // seperated lookat-calculation for camera at light source 00135 // 00136 // Revision 1.17 2002/04/11 09:04:28 baumann 00137 // changed ctx from Canvas* to GLCanvas* 00138 // 00139 // Revision 1.16 2002/03/04 12:00:26 kersting 00140 // directory structure changes 00141 // 00142 // Revision 1.15 2002/03/03 21:44:25 kosta 00143 // VRS_TYPEINFO-macro rewritten 00144 // 00145 // Revision 1.14 2002/02/19 10:34:17 kosta 00146 // undone all changes since 2002-02-15 00147 // 00148 // Revision 1.11 2002/02/04 12:58:41 kirsch 00149 // moved setting of light in shadow application pass to ShadowTechniqueGL 00150 // other minor changes 00151 // 00152 // Revision 1.10 2002/01/25 16:42:06 kirsch 00153 // added canBeUsed() for techniques, and properly react in some OpenGL 00154 // techniques when needed extensions are missing 00155 // 00156 // Revision 1.9 2002/01/15 16:25:55 kosta 00157 // macros rewritten for a better namespace support 00158 // 00159 // Revision 1.8 2002/01/08 16:02:49 kosta 00160 // dir structure for textures changed 00161 // 00162 // Revision 1.7 2001/11/21 10:26:11 nienhaus 00163 // combine mode moved to opengl texture environment attribute 00164 // 00165 // Revision 1.6 2001/11/13 16:36:31 kirsch 00166 // changed line feed to unix style (removed control-M) 00167 // 00168 // Revision 1.5 2001/11/07 12:34:42 kirsch 00169 // setAlphaMapResolution did not change size of PBufferCanvasGL 00170 // 00171 // Revision 1.4 2001/09/05 14:14:36 kirsch 00172 // Documentation updates 00173 // 00174 // Revision 1.3 2001/08/13 16:23:01 kirsch 00175 // small performance improvements 00176 // 00177 // Revision 1.2 2001/08/09 15:37:10 kirsch 00178 // Added shadows in OpenGL, created with alpha depthmaps. 00179 // Still experimental, some flaws 00180 // 00181 // Revision 1.1.2.2 2001/06/28 12:26:11 kirsch 00182 // Removed BLEND_MIN_MAX, i.E., application of 00183 // alpha-textures in two passes. Cleaned up code a bit. 00184 // 00185 // Revision 1.1.2.1 2001/06/22 15:28:40 kirsch 00186 // Added shadow-attributes and depthmapshadowtechniquegl. 00187 // Still broken! Don't Use! Only for Distributing! 00188 // 00189 00190 #ifndef VRS_OPENGL_DEPTHMAPSHADOWTECHNIQUEGL_H 00191 #define VRS_OPENGL_DEPTHMAPSHADOWTECHNIQUEGL_H 00192 00194 // This header file defines // 00195 // * DepthmapShadowTechniqueGL // 00196 // * AlphaTextureShadowTechniqueGL // 00197 // * DepthTextureShadowTechniqueGL // 00199 00200 #include <vrs/opengl/shadowtechniquegl.h> 00201 #include <vrs/bounds.h> 00202 #include <vrs/matrix.h> 00203 00204 namespace VRS { 00205 00206 class PBufferCanvasGL; 00207 class PBufferManagerGL; 00208 class Texture2DGL; 00209 class TextureUnitSettingGL; 00210 template <typename T, typename V> class CachedResource; 00211 00213 // DepthmapShadowTechniqueGL // 00215 00216 class VRS_CORE_API DepthmapShadowTechniqueGL : public ShadowTechniqueTemplateGL { 00217 public: 00218 DepthmapShadowTechniqueGL(int resolution); 00223 void setDepthmapResolution(int); 00229 int getDepthmapResolution() const; 00231 00232 VRS_TYPEINFO(DepthmapShadowTechniqueGL, ShadowTechniqueTemplateGL); 00233 VRS_SERIALIZABLE_ABSTRACT_CLASS(DepthmapShadowTechniqueGL); 00234 00235 protected: 00236 00237 struct DepthMapInfo { 00238 DepthMapInfo() : depthMap_(NULL), transaction_(currentTransactionNo()) { } 00239 SO<Texture2DGL> depthMap_; 00240 TransactionNo transaction_; 00241 Matrix projection_; 00242 Matrix view_; 00243 }; 00244 00245 SO<CachedResource<SO<Light>, DepthMapInfo> > depthMapDict_; 00246 00247 virtual bool addNextBuildDepthMapPass(Iterator<SO<Light> >* lightItr, Engine* engine); 00248 00249 void createPBuffer(Engine*); 00253 void freePBuffer(Engine*); 00254 PBufferCanvasGL* PBuffer(); 00256 void preparePBuffer(Engine*); 00260 void releasePBuffer(Engine*); 00264 public: 00265 static int getViewFromLight(const Light*, Engine*, const Bounds&, 00266 Matrix& proj, Matrix& view); 00270 static double getAngleOfPerspectiveFrustum(const Vector&, const Bounds&); 00273 private: 00274 00275 int depthmapResolution_; 00276 00277 bool pbufferIsPrepared_; 00278 00279 SO<PBufferManagerGL> pbuffermgr_; 00280 SO<PBufferCanvasGL> pbuffer_; 00281 }; 00282 00283 inline int DepthmapShadowTechniqueGL::getDepthmapResolution() const { 00284 return depthmapResolution_; 00285 } 00286 00287 inline PBufferCanvasGL* DepthmapShadowTechniqueGL::PBuffer() { 00288 return pbuffer_; 00289 } 00290 00292 // AlphaTextureShadowTechniqueGL // 00294 00295 class VRS_CORE_API AlphaTextureShadowTechniqueGL : public DepthmapShadowTechniqueGL { 00296 public: 00297 AlphaTextureShadowTechniqueGL(int alphaMapResolution = 512); 00315 virtual bool isSupported(Engine*, bool verbose) const; 00320 virtual int rate(Engine*) const; 00325 VRS_TYPEINFO(AlphaTextureShadowTechniqueGL, ShadowTechniqueTemplateGL); 00326 VRS_SERIALIZABLE(AlphaTextureShadowTechniqueGL); 00327 00328 protected: 00329 00330 // Implementations of the hooks defined by the ShadowTechniqueTemplateGL 00331 virtual void startHook(Engine*); 00332 virtual void stopHook(Engine*); 00333 00334 virtual bool preparePassHook(Engine*); 00335 virtual void finishPassHook(Engine*); 00336 virtual void nextPassHook(Engine*); 00337 00338 virtual bool prepareEvalHook(Engine* engine, const Shape* shape); 00339 virtual void finishEvalHook(Engine* engine, const Shape* shape, bool render); 00340 00341 virtual void setupShadowTest(bool onOff, Engine*); 00342 virtual void toggleShadowTest(bool receiving, Engine*); 00343 00344 private: 00345 00346 SO<TextureUnitSettingGL> alphaDepthTextureSetting_; 00347 SO<TextureUnitSettingGL> alphaRampTextureSetting_; 00348 00349 int stencilValue_; 00350 00351 Matrix originalModelview_; 00352 Matrix originalProjection_; 00353 Matrix orientInverse_; 00354 00355 Bounds sceneBoundingBox_; 00356 }; 00357 00359 // DepthTextureShadowTechniqueGL // 00361 00362 class VRS_CORE_API DepthTextureShadowTechniqueGL : public DepthmapShadowTechniqueGL { 00363 public: 00364 DepthTextureShadowTechniqueGL(int depthTextureResolution = 512, double roffset = 0.01); 00378 virtual bool isSupported(Engine*, bool verbose) const; 00386 virtual int rate(Engine*) const; 00393 VRS_TYPEINFO(DepthTextureShadowTechniqueGL, ShadowTechniqueTemplateGL); 00394 VRS_SERIALIZABLE(DepthTextureShadowTechniqueGL); 00395 00396 protected: 00397 00398 // Implementations of the hooks defined by the ShadowTechniqueTemplateGL 00399 virtual void startHook(Engine*); 00400 virtual void stopHook(Engine*); 00401 00402 virtual bool preparePassHook(Engine*); 00403 virtual void finishPassHook(Engine*); 00404 00405 virtual void nextPassHook(Engine*); 00406 00407 virtual bool prepareEvalHook(Engine* engine, const Shape* shape); 00408 virtual void finishEvalHook(Engine* engine, const Shape* shape, bool render); 00409 00410 virtual void setupShadowTest(bool onOff, Engine*); 00411 virtual void toggleShadowTest(bool receiving, Engine*); 00412 00413 private: 00414 double roffset_; 00415 00416 mutable bool haveStencil_; 00417 mutable bool haveAlpha_; 00418 00419 SO<TextureUnitSettingGL> depthTextureSetting_; 00420 00421 int stencilValue_; 00422 00423 Matrix originalModelview_; 00424 Matrix originalProjection_; 00425 Matrix orientInverse_; 00426 00427 Bounds sceneBoundingBox_; 00428 }; 00429 00430 } // namespace VRS 00431 00432 #endif // VRS_OPENGL_DEPTHMAPSHADOWTECHNIQUEGL_H 00433 00434 00435