Material.hh

00001 /**********************************************************************
00002  * blaRAY -- photon mapper/raytracer
00003  * (C) 2008 by Tomasz bla Fortuna <bla@thera.be>, <bla@af.gliwice.pl>
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation, either version 3 of the License, or
00008  * any later version.
00009  *
00010  * See Docs/LICENSE
00011  *********************/
00012 
00013 #ifndef _MATERIAL_H_
00014 #define _MATERIAL_H_
00015 
00016 #include <string>
00017 #include <iostream>
00018 #include <stdexcept>
00019 
00020 #include "World/Texture.hh"
00021 
00022 namespace World {
00032         class Material {
00033         private:
00034                 /* Material textures (Color filters) */
00035                 const Texture &Diffuse;  
00036                 const Texture &Specular; 
00037                 const Texture &Refract;  
00038                 const Texture &Reflect;  
00041                 /* Material properties */
00042                 Double Reflective; 
00043                 Double Refractive; 
00044                 Double Absorptive; 
00045                 Double Shininess; 
00046                 Double Index; 
00048         public:
00050                 Material(const Texture &Diffuse = TexLib::Red(),
00051                          const Texture &Specular = TexLib::White(),
00052                          const Texture &Refract = TexLib::Black(),
00053                          const Texture &Reflect = TexLib::Black(),
00054                          Double Reflective = 0.0,
00055                          Double Refractive = 0.0,
00056                          Double Absorptive = 0.9,
00057                          Double Shininess = 12.0,
00058                          Double Index = 1.0)
00059                         : Diffuse(Diffuse), Specular(Specular),
00060                           Refract(Refract), Reflect(Reflect),
00061                           Reflective(Reflective), Refractive(Refractive),
00062                           Absorptive(Absorptive), Shininess(Shininess),
00063                           Index(Index)
00064                 {
00065                 }
00066 
00068                 enum Filter { DIFFUSE, SPECULAR, REFRACT, REFLECT };
00070                 enum Property { REFLECTIVE, REFRACTIVE, ABSORPTIVE, SHININESS, INDEX };
00071 
00073                 inline const Texture &GetTexture(Filter f) const
00074                 {
00075                         switch (f) {
00076                         case DIFFUSE: return this->Diffuse;
00077                         case SPECULAR: return this->Specular;
00078                         case REFRACT: return this->Refract;
00079                         case REFLECT: return this->Reflect;
00080                         default:
00081                                 throw std::invalid_argument("Illegal texture filter specified");
00082                         }
00083                 }
00084 
00086                 inline Double GetProperty(Property p) const
00087                 {
00088                         switch (p) {
00089                         case REFLECTIVE: return Reflective;
00090                         case REFRACTIVE: return Refractive;
00091                         case ABSORPTIVE: return Absorptive;
00092                         case SHININESS: return Shininess;
00093                         case INDEX: return this->Index;
00094                         default:
00095                                 throw std::invalid_argument("Illegal material property specified");
00096 
00097                         }
00098                 }
00099 
00101                 inline Color GetColor(Filter f, const Math::Point &UV) const
00102                 {
00103                         return GetTexture(f).Get(UV);
00104                 }
00105 
00107                 friend std::ostream &operator<<(std::ostream &os, const Material &M);
00108         };
00109 
00114         namespace MatLib {
00116                 const Double IdxVacuum = 1.0;
00117                 const Double IdxAir = 1.0002926;
00118                 const Double IdxWater = 1.333;
00119                 const Double IdxDiamond = 2.419;
00120                 const Double IdxAmber = 1.55;
00121                 const Double IdxSalt = 1.544;
00122                 const Double IdxIce = 1.31;
00123                 const Double IdxGlass = 1.60;
00128                 const Material &Red();
00129                 const Material &Green();
00130                 const Material &Blue();
00131                 const Material &White();
00132                 const Material &Black();
00133                 const Material &Gray();
00137                 const Material &Glass();
00138         };
00139 };
00140 
00141 #endif

Generated on Wed Mar 12 00:34:58 2008 for blaRAY by  doxygen 1.5.5