Material.h

Go to the documentation of this file.
00001 /* $Id: Material.h,v 1.1 2002/12/05 15:02:18 cvs Exp $ */
00002 
00003 #ifndef __MATERIAL_H
00004 #define __MATERIAL_H
00005 
00006 #include <esg/visitor/Visitor.h>
00007 #include <esg/ESGObject.h>
00008 
00009 namespace esg {
00010 
00011 /*
00012  * Usefull aliases first
00013  */
00014 
00015 typedef Roughness    Shininess;
00016 typedef Transparency Transmission;
00017 
00018 /********************************************************************/
00019 /*                    generic material                              */
00020 /********************************************************************/
00021 
00022 class OGSCENE_EXPORT Material : public ESGObject{
00023 protected:
00024     virtual void _duplicate_attributes (const Material&) {}
00025     
00026 public:
00027     virtual ~Material() {}
00028     virtual void      acceptVisitor (Visitor&) = 0;
00029     virtual Material* clone         ()  const  = 0;
00030 };
00031 
00032 
00033 /********************************************************************/
00034 /*                    scalar-based materials                        */
00035 /********************************************************************/
00036 
00037 class OGSCENE_EXPORT _ScalarMat : public Material {
00038 protected:
00039     float _val;
00040 
00041 protected:
00042     virtual void _duplicate_attributes (const Material& src) {
00043         Material::_duplicate_attributes(src);
00044         _val = ((_ScalarMat&)src)._val;
00045     }
00046 
00047 public:
00048     _ScalarMat (float v = 0.0) : _val(v) {}
00049     
00050     virtual void      acceptVisitor (Visitor&) = 0;
00051     virtual Material* clone         () const   = 0;
00052     virtual float     value         () const  { return _val; }
00053     virtual void      setValue      (float v) { _val = v; }
00054 };
00055 
00056 
00057 /*
00058  * Roughness/shininess defined in the [0.0, 1.0] or [0, 128] extent.
00059  * Roughness is ususally used as an exponent in specular reflection.
00060  */
00061 class OGSCENE_EXPORT Roughness : public _ScalarMat {
00062 public:
00063     Roughness (float v = 0.0) : _ScalarMat(v)       {}
00064     Roughness (int   v)       : _ScalarMat(v/128.0) {}
00065 
00066     virtual void      acceptVisitor (Visitor& v) { v.visitRoughness(this); }
00067     virtual Material* clone    (void) const { return new Roughness(_val); }
00068     virtual int       intValue (void) const { return (int)(_val * 128.0); }
00069 };
00070 
00071 /*
00072  * Index of refraction.
00073  */
00074 class OGSCENE_EXPORT IndexOfRefraction : public _ScalarMat {
00075 public:
00076     IndexOfRefraction (float v = 0.0) : _ScalarMat(v) {}
00077     
00078     virtual void acceptVisitor (Visitor& v) { v.visitIndexOfRefraction(this); }
00079     virtual Material* clone (void) const { return new IndexOfRefraction(_val); }
00080 };
00081 
00082 
00083 
00084 
00085 /********************************************************************/
00086 /*                    vector-based materials                        */
00087 /********************************************************************/
00088 
00089 class OGSCENE_EXPORT _VectorMat : public Material {
00090 protected:
00091     Vector3 _val;
00092     double  _avgVal;
00093 
00094 protected:
00095     virtual void _duplicate_attributes (const Material& src) {
00096         Material::_duplicate_attributes(src);
00097         _val.set(((_VectorMat&)src)._val);
00098     }
00099 
00100 public:
00101     _VectorMat (Vector3 v)
00102         : _val(v), _avgVal((v.x+v.y+v.z)/3.) {}
00103     
00104     _VectorMat (float x=.0, float y=.0, float z=.0) :
00105         _val(x,y,z), _avgVal((x+y+z)/3.) {}
00106     
00107     virtual void           acceptVisitor (Visitor&)   = 0;
00108     virtual Material*      clone         (void) const = 0;
00109     virtual const Vector3& value         (void) const { return _val; }
00110 
00111     virtual void setValue (const Vector3& v) {
00112         _val.set(v);
00113         _avgVal = (v.x+v.y+v.z) / 3.;
00114     }
00115 
00116     virtual void setValue (float x, float y, float z) {
00117         _val.set(x, y, z);
00118         _avgVal = (x+y+z) / 3.;
00119     }
00120 
00121     double avgValue (void) const { return _avgVal; }
00122 };
00123     
00124 
00125 /*
00126  * Specular coefficients for view-restricted reflection
00127  */
00128 class OGSCENE_EXPORT Specular : public _VectorMat {
00129 public:
00130     Specular (Vector3 v)                          : _VectorMat(v)     {}
00131     Specular (float x=.0, float y=.0, float z=.0) : _VectorMat(x,y,z) {}
00132     
00133     virtual void acceptVisitor (Visitor& v) { v.visitSpecular(this);  }
00134     virtual Material* clone (void) const { return new Specular(_val); }
00135 };
00136 
00137 /*
00138  * Diffuse coefficients for omnidirectional reflectance.
00139  * Usussually controls the basic surface color
00140  */
00141 class OGSCENE_EXPORT Diffuse : public _VectorMat {
00142 public:
00143     Diffuse (Vector3 v)                          : _VectorMat(v)     {}
00144     Diffuse (float x=.8, float y=.8, float z=.8) : _VectorMat(x,y,z) {}
00145     
00146     virtual void acceptVisitor (Visitor& v) { v.visitDiffuse(this);     }
00147     virtual Material* clone (void) const { return new Diffuse(_val); }
00148 };
00149 
00150 /*
00151  * Coefficients for illumination by global ambient light
00152  */
00153 class OGSCENE_EXPORT Ambient : public _VectorMat {
00154 public:
00155     Ambient (Vector3 v)                          : _VectorMat(v)     {}
00156     Ambient (float x=.2, float y=.2, float z=.2) : _VectorMat(x,y,z) {}
00157     
00158     virtual void acceptVisitor (Visitor& v) { v.visitAmbient(this);     }
00159     virtual Material* clone (void) const { return new Ambient(_val); }
00160 };
00161 
00162 /*
00163  * Transparency/refraction
00164  */
00165 class OGSCENE_EXPORT Transparency : public _VectorMat {
00166 public:
00167     Transparency (Vector3 v)                          : _VectorMat(v)     {}
00168     Transparency (float x=.0, float y=.0, float z=.0) : _VectorMat(x,y,z) {}
00169     
00170     virtual void acceptVisitor (Visitor& v) { v.visitTransparency(this);     }
00171     virtual Material* clone (void) const { return new Transparency(_val); }
00172 };
00173 
00174 /*
00175  * Reflection
00176  */
00177 class OGSCENE_EXPORT Reflection : public _VectorMat {
00178 public:
00179     Reflection (Vector3 v)                          : _VectorMat(v)     {}
00180     Reflection (float x=.0, float y=.0, float z=.0) : _VectorMat(x,y,z) {}
00181     
00182     virtual void acceptVisitor (Visitor& v) { v.visitReflection(this);     }
00183     virtual Material* clone (void) const { return new Reflection(_val); }
00184 };  
00185 
00186 
00187 /*
00188  * Fresnel term correspond to the color fo reflected white light with orhogonal
00189  * incidence. For dielectrics (like plastic, porcelain etc.) these
00190  * values are usually 1, meaning that a specular highlight has the color
00191  * of the light source.In contrast to this,
00192  * metals change the color of a highlight, e.g. gold has a
00193  * goldish highlight when the light incidents orthogonally
00194  * to the surface. At more grazing angles all these materials
00195  * change their highlight color to the color of the light source
00196  *
00197  * The Fresnel term is for example used by Cook-Torrance BRDF.
00198  */
00199 class OGSCENE_EXPORT FresnelTerm : public _VectorMat {
00200 public:
00201     FresnelTerm (Vector3 v)                             : _VectorMat(v)     {}
00202     FresnelTerm (float x=1.0, float y=1.0, float z=1.0) : _VectorMat(x,y,z) {}
00203     
00204     virtual void acceptVisitor (Visitor& v) { v.visitFresnelTerm(this);     }
00205     virtual Material* clone (void) const { return new FresnelTerm(_val); }
00206 };
00207 
00208 /*
00209  * Gaussian coefficient used for description of statistical distribution
00210  * in physically based micro-geometry modelling.
00211  *
00212  * The gaussian coefficient is for example used by Cook-Torrance BRDF.
00213  */
00214 class OGSCENE_EXPORT GaussianCoef : public _VectorMat {
00215 public:
00216     GaussianCoef (Vector3 v)                             : _VectorMat(v)     {}
00217     GaussianCoef (float x=1.0, float y=1.0, float z=1.0) : _VectorMat(x,y,z) {}
00218     
00219     virtual void acceptVisitor (Visitor& v) { v.visitGaussianCoef(this);     }
00220     virtual Material* clone (void) const { return new GaussianCoef(_val); }
00221 };
00222     
00223 
00224 }; // namespace
00225 
00226 #endif // __MATERIAL_H

Generated on Wed Jun 28 12:24:28 2006 for esg by  doxygen 1.4.6