PhotonMapShader.h

Go to the documentation of this file.
00001 /* $Id:$ */
00002 
00003 #ifndef __PHOTON_MAP_SHADER
00004 #define __PHOTON_MAP_SHADER
00005 
00006 #include <gra/shader/RTShader.h>
00007 #include <gra/reflection/PhotonTracing.h>
00008 #include <gra/reflection/PhotonMapping.h>
00009 #include <gra/reflection/Caustics.h>
00010 #include <esg/LightArray.h>
00011 #include <esg/energy/PhotonMapEnergy.h>
00012 
00013 using namespace esg;
00014 
00015 namespace gra {
00016 
00021 class GRA_EXPORT PhotonMapShader : public RTShader {
00022 public:
00023         enum Mapping {
00024             SCENE_MAPS,    
00025             MAPS_PER_SHAPE 
00026         };
00027 
00028 protected:
00029         PhotonTracing * _pPhotonTracing;
00030         Caustics      * _pCausticsEmittion;
00031         LightArray    * _pLights;
00032         unsigned        _photonsPerLight;
00033         Mapping         _mapping;
00034         bool            _userDefinedBehaviour;
00035         
00036 protected:
00037         void _create_scene_maps     (List<PhotonMapEnergy>&,
00038                                      List<SceneGraphObject>&);
00039         void _create_maps_per_shape (List<PhotonMapEnergy>&,
00040                                      List<SceneGraphObject>&);
00041         PointEnv* _emit_global_photon  (const Vector3&, const Vector3&);
00042         PointEnv* _emit_caustic_photon (const Vector3&, const Vector3&);
00043 
00044 public:
00057         PhotonMapShader(PhotonTracing * m,
00058                         Caustics      * c,
00059                         PhotonMapping * n,
00060                         DiffuseBRDF   * db,
00061                         SpecularBRDF  * sb,
00062                         unsigned        p,
00063                         Mapping         mapping,
00064                         bool            u)
00065             : RTShader(n, db, sb),
00066               _pPhotonTracing(m),
00067               _pCausticsEmittion(c),
00068               _pLights(NULL),
00069               _photonsPerLight(p),
00070               _mapping(mapping),
00071               _userDefinedBehaviour(u) {}
00072 
00078         virtual void setScene (Scene * o) {
00079             RTShader::setScene(o);
00080             if (_pPhotonTracing) _pPhotonTracing->setScene(o);
00081             if (_pCausticsEmittion) _pCausticsEmittion->setScene(o);
00082         }
00083 
00088         virtual void distributeEnergy (void);
00089 
00097         virtual bool setRenderedShape (SceneGraphObject * pShape,
00098                                        const Matrix4    * pTrMat) {
00099             if (!RTShader::setRenderedShape(pShape, pTrMat)) return false;
00100             if (!_pShape)                                    return false;
00101             if (!_pPhotonTracing)                            return false;
00102             if (!_pCausticsEmittion)                         return false;
00103             DiffuseBRDF * pDiffBRDF = _pShape->diffuseBRDF();
00104             SpecularBRDF* pSpecBRDF = _pShape->specularBRDF();
00105             _pPhotonTracing->setDiffuseBRDF((pDiffBRDF)
00106                                             ? pDiffBRDF 
00107                                             : _pDefaultDiffBRDF);
00108             _pPhotonTracing->setSpecularBRDF((pSpecBRDF)
00109                                              ? pSpecBRDF 
00110                                              : _pDefaultSpecBRDF);
00111             _pPhotonTracing->setEmittance(_pShape->emittance());
00112             _pCausticsEmittion->setDiffuseBRDF((pDiffBRDF)
00113                                                ? pDiffBRDF 
00114                                                : _pDefaultDiffBRDF);
00115             _pCausticsEmittion->setSpecularBRDF((pSpecBRDF)
00116                                                 ? pSpecBRDF 
00117                                                 : _pDefaultSpecBRDF);
00118             _pCausticsEmittion->setEmittance(_pShape->emittance());
00119             return true;
00120         }
00121 };
00122     
00123 } // namespace
00124 
00125 #endif // __PHOTON_MAP_SHADER

Generated on Tue Nov 21 15:11:42 2006 for gra by  doxygen 1.4.6