LocalReflection.h

Go to the documentation of this file.
00001 /* $Id: LocalReflection.h,v 1.1 2002/12/05 15:08:03 cvs Exp $ */
00002 
00003 #ifndef __LOCAL_REFLECTION_H
00004 #define __LOCAL_REFLECTION_H
00005 
00006 #include <gra/reflection/ReflectionModel.h>
00007 #include <esg/explorer/LightsExplorer.h>
00008 #include <esg/Intersector.h>
00009 
00010 /*
00011  * Local reflection computes only local illumination of single point.
00012  * Any BRDF is treated by this reflection model.
00013  *
00014  * ShadowDetection parameter determines how are a shadows tested.
00015  * SD_NONE               - no light source visibility test is performed
00016  * SD_RAY_FROM_EMITTANCE - either emittance location or direction is used
00017  *                         for light position estimation
00018  * SD_GEOMETRY_SAMPLING  - we get random samples from the geometry of light
00019  *                         to get its position. If no geometry is specified for
00020  *                         the light then SD_RAY_FROM_EMITTANCE is
00021  *                         automatically used.
00022  *
00023  * _lightTests determines number of illumination tests per single light.
00024  *   0  - Light sources are ignored
00025  *   1  - Single test per light source, typically used in combination with
00026  *        SD_NONE (= classical local illumination),
00027  *        SD_RAY_FROM_EMITTANCE (= Whitted ray tracing) and
00028  *        SD_GEOMETRY_SAMPLING (= Monte Carlo ray tracing)
00029  *   >1 - Ignored in combination with SD_NONE and SD_RAY_FROM_EMITTANCE,
00030  *        1 is used instead.
00031  *        Together with SD_GEOMETRY_SAMPLING we get soft shadows.
00032  *
00033  */
00034 
00035 using namespace esg;
00036 
00037 namespace gra {
00038 
00039 class GRA_EXPORT LocalReflection : public ReflectionModel {
00040 public:
00041     enum ShadowDetection {
00042         SD_NONE,
00043         SD_RAY_FROM_EMITTANCE,
00044         SD_GEOMETRY_SAMPLING
00045     };
00046     
00047 protected:
00048     LightArray     * _pLights;
00049     ShadowDetection  _shadowDetection;
00050     unsigned         _lightTests; // number of illumination tests per light
00051     unsigned         _numCaches; // caches of bjects blocking lights
00052     unsigned         _useCache;  // if >= _numCaches then does not use cache
00053     
00054 protected:
00055     bool _light_visible (unsigned, const Vector3&, double, const Vector3&,
00056                          SceneGraphObject::OID);
00057 
00058 public:
00059     LocalReflection (DiffuseBRDF   * db /* BRDF                   */ = NULL,
00060                      SpecularBRDF  * sb /* BRDF                   */ = NULL,
00061                      Emittance     * e  /* emittance              */ = NULL,
00062                      ShadowDetection s                               = SD_NONE,
00063                      unsigned        ns /* number tests per light */ = 1,
00064                      unsigned        c  /* num. of caches         */ = 0,
00065                      unsigned        u  /* which cache to use     */ = 1);
00066 
00067     virtual ~LocalReflection () { if (_pLights) delete _pLights; }
00068 
00069     virtual void setScene (Scene *);
00070 
00071     /*
00072      * Required input parametters,
00073      * viwerDir() and distance() have to be defined together:
00074      *   PointEnv.intersection()    = point of interest (PoI)
00075      *   PointEnv.normal()          = surface normal at PoI
00076      *   PointEnv.visitableObject() = surface of interest
00077      * [ PointEnv.viewerDir()       = normalized direction from PoI to viewer
00078      *   PointEnv.distance()        = distance between PoI and viewer ]
00079      */
00080     virtual Color3f* illuminatePoint(PointEnv & /* point of interest */);
00081 
00082     /*
00083      * As above but material coefficients are set in visitor
00084      * instead of being inspected internally
00085      *
00086      * Required input parametters,
00087      * viwerDir() and distance() have to be defined together:
00088      *   PointEnv.intersection()    = point of interest (PoI)
00089      *   PointEnv.normal()          = surface normal at PoI
00090      * [ PointEnv.viewerDir()       = normalized direction from PoI to viewer
00091      *   PointEnv.distance()        = distance between PoI and viewer ]
00092      */
00093     virtual Color3f* illuminatePoint(PointEnv   & /* point of interest  */,
00094                                      MatVisitor & /* intialized visitor */);
00095     const LightArray * lights (void) const { return _pLights; }
00096 
00097     unsigned getBlockingObjCaches   (void) const { return _numCaches; }
00098     unsigned getActBlockingObjCache (void) const { return _useCache;  }
00099     void     setActBlockingObjCache (unsigned i) { _useCache = i;     }
00100     void     blockingObjCacheOff    (void)       { _useCache = _numCaches; }
00101 };
00102     
00103 } // namespace
00104 
00105 #endif // __LOCAL_REFLECTION_H

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