Blender V2.61 - r43446

ntl_lighting.h

Go to the documentation of this file.
00001 
00004 /******************************************************************************
00005  *
00006  * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method
00007  * Copyright 2003-2006 Nils Thuerey
00008  *
00009  * a light object
00010  * default omni light implementation
00011  *
00012  *****************************************************************************/
00013 #ifndef NTL_LIGHTING_H
00014 #define NTL_LIGHTING_H
00015 
00016 #include "ntl_vector3dim.h"
00017 class ntlMaterial;
00018 class ntlRay;
00019 class ntlRenderGlobals;
00020 class ntlGeometryObject;
00021 
00022 
00023 
00024 /* shadow map directions */
00025 #define LSM_RIGHT 0
00026 #define LSM_LEFT  1
00027 #define LSM_UP    2
00028 #define LSM_DOWN  3
00029 #define LSM_FRONT 4
00030 #define LSM_BACK  5
00031 
00033 class ntlLightObject
00034 {
00035 public:
00036   /* CONSTRUCTORS */
00038   ntlLightObject(ntlRenderGlobals *glob);
00040   ntlLightObject(ntlRenderGlobals *glob, const ntlColor& col);
00042   virtual ~ntlLightObject();
00043 
00045     virtual void prepare( bool );
00046     
00048     virtual ntlColor illuminatePoint(ntlRay &reflectedRay, 
00049                                                                      ntlGeometryObject *closest,
00050                                                                      ntlColor &highlight);
00052     const ntlColor
00053     getShadedColor(const ntlRay &reflectedray, ntlVec3Gfx lightDir,
00054                                  ntlMaterial *surf, ntlColor &highlight) const;
00055 
00056 
00057   /* access methods */
00059   inline void setActive(bool set) { mActive = set; }
00060   inline bool getActive() const { return mActive; }
00062   inline void setCastShadows(bool set) { mCastShadows = set; }
00063   inline bool getCastShadows() const { return mCastShadows; }
00065   inline void setColor(ntlColor set) { mcColor = set; }
00066   inline ntlColor getColor() const { return mcColor; }
00067   
00069   void setPosition(ntlVec3Gfx set) { mvPosition = set; }
00070   ntlVec3Gfx getPosition() const { return mvPosition; }
00071     
00072 
00073 protected:
00075     ntlRenderGlobals *mpGlob;
00076 
00078     bool mActive;
00079 
00081     bool mCastShadows;
00082 
00084     ntlColor  mcColor;
00085 
00087     ntlVec3Gfx  mvPosition;
00088 
00089 private:
00090 
00091 };
00092 
00093 
00095 class ntlMaterial
00096 {
00097 public:
00098   // CONSTRUCTORS
00100   ntlMaterial( void );
00102 
00105   ntlMaterial( string name,
00106          const ntlColor& Ref, const ntlColor& Amb, 
00107                gfxReal Spec, gfxReal Exp, gfxReal Mirror,
00108                gfxReal Trans, gfxReal Refrac, gfxReal TAdd,
00109                const ntlColor& Att, int fres);
00111   ~ntlMaterial() {};
00112 
00114     inline void calculateFresnel(const ntlVec3Gfx &dir, const ntlVec3Gfx &normal, gfxReal refIndex,
00115                                                              gfxReal &refl, gfxReal &trans );
00116 
00117 protected:
00118 
00119   /* name of the material */
00120   string mName;
00121 
00123   ntlColor  mDiffuseRefl;
00125   ntlColor mAmbientRefl;
00127   gfxReal mSpecular;
00129   gfxReal mSpecExponent;
00131   gfxReal mMirror;
00132 
00134   gfxReal mTransparence;
00136   gfxReal mRefracIndex;
00138   gfxReal mTransAdditive;
00140   ntlColor mTransAttCol;
00142     int mFresnel;
00143 
00144 
00145 public:
00146   // access methods
00147 
00149   inline string getName() { return mName; }
00151   inline ntlColor  getDiffuseRefl() const { return ntlColor(mDiffuseRefl); }
00153   inline ntlColor getAmbientRefl() const { return ntlColor(mAmbientRefl); }
00155   inline gfxReal getSpecular() const { return mSpecular; }
00157   inline gfxReal getSpecExponent() const { return mSpecExponent; }
00159   inline gfxReal getMirror() const { return mMirror; }
00161   inline gfxReal getTransparence() const { return mTransparence; }
00163   inline gfxReal getRefracIndex() const { return mRefracIndex; }
00165   inline gfxReal getTransAdditive() const { return mTransAdditive; }
00167   inline ntlColor getTransAttCol() const { return mTransAttCol; }
00169     inline int getFresnel( void ) { return mFresnel; }
00170 
00171 
00172 
00174   inline void setName(string set) { mName = set; }
00176   inline void setDiffuseRefl(ntlColor set) { mDiffuseRefl=set; }
00178   inline void setAmbientRefl(ntlColor set) { mAmbientRefl=set; }
00180   inline void setSpecular(gfxReal set) { mSpecular=set; }
00182   inline void setSpecExponent(gfxReal set) { mSpecExponent=set; }
00184   inline void setMirror(gfxReal set) { mMirror=set; }
00186   inline void setTransparence(gfxReal set) { mTransparence=set; }
00188   inline void setRefracIndex(gfxReal set) { mRefracIndex=set; }
00190   inline void setTransAdditive(gfxReal set) { mTransAdditive=set; }
00192   inline void setTransAttCol(ntlColor set) { 
00193         ntlColor setlog = ntlColor( -log(set[0]), -log(set[1]), -log(set[2]) );
00194         mTransAttCol=setlog; }
00196     inline void setFresnel(int set) { mFresnel = set; }
00197 
00198 };
00199 
00200 
00201 /******************************************************************************
00202  * Macro to define the default surface properties for a newly created object
00203  *****************************************************************************/
00204 #define GET_GLOBAL_DEFAULT_MATERIAL new ntlMaterial( "default",\
00205                                         ntlColor( 0.5 ), ntlColor(0.0), \
00206                                         1.0, 5.0, 0.0,   \
00207                                                                                 /*0.0 test:*/ 0.5 , 1.0, 0.0, \
00208                                                                                 ntlColor( 0.0 ), 0 ); 
00209                                                                                                                             
00210 
00211 
00212 /******************************************************************************
00213  * Calculate reflectance and refratance from Fresnel's law
00214  * cf. Glassner p. 46
00215  *****************************************************************************/
00216 inline void 
00217 ntlMaterial::calculateFresnel(const ntlVec3Gfx &dir, const ntlVec3Gfx &normal, gfxReal refIndex,
00218                                                             gfxReal &refl, gfxReal &trans)
00219 {
00220     gfxReal c = -dot(dir, normal);
00221     if(c<0) { 
00222         refl = 0.0; trans = 0.0; return;
00223         //c = 0.0;
00224     }
00225 
00226     gfxReal r0 = ((refIndex-1.0)*(refIndex-1.0)) /
00227         ((refIndex+1.0)*(refIndex+1.0));
00228     gfxReal omc = (1.0-c);
00229     gfxReal r =r0 + (1.0 - r0) * omc*omc*omc*omc*omc;
00230 
00231     //mMirror = r;
00232     //mTransparence = (1.0 - r);
00233     refl = r;
00234     trans = (1.0 - r);
00235     //errorOut(" fres ");
00236 }
00237 
00238 
00239 #endif
00240 
00241