Material.h
Go to the documentation of this file.00001 /**<!--------------------------------------------------------------------> 00002 @class Material 00003 @author Travis Fischer (fisch0920@gmail.com) 00004 @author Matthew Jacobs (jacobs.mh@gmail.com) 00005 @date Fall 2008 00006 00007 @brief 00008 Abstract representation of a surface Material, defined without respect 00009 to the underlying surface (loose coupling between Shapes and Materials 00010 from the point-of-view of a Material, but all Shapes know about their 00011 surface Material). Materials subclass PropertyMap, and it is through this 00012 interface that Material properties may be set (ex: diffuse color, 00013 texture/bump/color map(s), index of refraction of interior volume, etc.) 00014 00015 Reflectivity, emittance, and sensor response (BSDFs, Emitters, and 00016 Sensors respectively) are three properties of a material that are defined 00017 at a single point on a surface. A Material encapsulates BSDF, Emitter, 00018 and Sensor properties defined over its surface, where specific instances of 00019 BSDF, Emitter, and Sensor are allowed to have their inputs vary with 00020 respect to position along the surface. In this respect, Materials 00021 represent a mapping from surface position to associated BSDF, Emitter, and 00022 Sensor functions, where the underlying functions themselves remain constant 00023 along the surface, and only the inputs vary among the different instances / 00024 surface points. For example, a Material may have a DiffuseBSDF over its 00025 entire surface, but a specific DiffuseBSDF instance obtained by getBSDF or 00026 implicitly in initSurfacePoint (which fills in the SurfacePoint's BSDF), is 00027 allowed to have its 'kd' parameter (diffuse albedo) vary with respect to 00028 the given surface point via lookup in an associated 'kd' texture map 00029 defined over the UV coordinates of the surface. 00030 <!-------------------------------------------------------------------->**/ 00031 00032 #ifndef MATERIAL_H_ 00033 #define MATERIAL_H_ 00034 00035 #include <core/SurfacePoint.h> 00036 #include <utils/PropertyMap.h> 00037 #include <shapes/Shape.h> 00038 00039 #include <materials/BSDF.h> 00040 #include <materials/Emitter.h> 00041 #include <materials/Sensor.h> 00042 00043 DECLARE_STL_TYPEDEF(std::vector<Material*>, MaterialList); 00044 00045 class KernelFilter; 00046 00047 class Material : public PropertyMap { 00048 public: 00049 ///@name Static members 00050 //@{----------------------------------------------------------------- 00051 static SurfacePoint s_nullSurfacePoint; 00052 static Emitter *s_nullEmitter; 00053 static Sensor *s_nullSensor; 00054 00055 public: 00056 //@}----------------------------------------------------------------- 00057 ///@name Constructors 00058 //@{----------------------------------------------------------------- 00059 00060 inline Material() 00061 : m_filter(NULL), m_bsdf("diffuse"), m_emitter("null"), m_bumpMap(""), 00062 m_repeatU(1), m_repeatV(1), m_bumpIntensity(5) 00063 { } 00064 00065 virtual ~Material(); 00066 00067 00068 //@}----------------------------------------------------------------- 00069 ///@name Initialization 00070 //@{----------------------------------------------------------------- 00071 00072 /** 00073 * @brief 00074 * Performs any initialization that may be necessary before beginning 00075 * to sample this material 00076 * 00077 * @note default implementation initializes this material's filter, used 00078 * for filtering texture values 00079 */ 00080 virtual void init(); 00081 00082 00083 //@}----------------------------------------------------------------- 00084 ///@name Main usage interface 00085 //@{----------------------------------------------------------------- 00086 00087 /** 00088 * @returns whether or not this Material is an emitter 00089 */ 00090 virtual bool isEmitter(); 00091 00092 /** 00093 * @brief 00094 * Accessor for instantiating BSDFs used in sampling at various 00095 * SurfacePoints along an underlying surface comprised of this Material 00096 * 00097 * @returns a new BSDF defined at the given surface point. The type of 00098 * BSDF returned depends on the 'bsdf' property in the PropertyMap, 00099 * which defaults to DiffuseBSDF 00100 */ 00101 virtual BSDF *getBSDF(SurfacePoint &pt); 00102 00103 /** 00104 * @brief 00105 * Accessor for instantiating Emitters used for evaluating emittance 00106 * along an underlying surface comprised of this Material 00107 * 00108 * @returns a new Emitter defined at the given surface point. The type of 00109 * Emitter returned depends on the 'emitter' property in the 00110 * PropertyMap, which defaults to NullEmitter (no light emitted) 00111 */ 00112 virtual Emitter *getEmitter(SurfacePoint &pt); 00113 00114 /** 00115 * @brief 00116 * Accessor for instantiating a representative Emitter at any point 00117 * on the surface of this Material 00118 * 00119 * @note useful if you just want to know the emittance properties of 00120 * this Material (power, radiant exitance, etc.) and don't actually 00121 * intend to use it for sampling purposes 00122 * 00123 * @returns a new Emitter defined at a dummy surface point. The type of 00124 * Emitter returned depends on the 'emitter' property in the 00125 * PropertyMap, which defaults to NullEmitter (no light emitted) 00126 */ 00127 virtual Emitter *getEmitter(); 00128 00129 /** 00130 * @brief 00131 * Accessor for instantiating Sensors used for evaluating importance 00132 * along an underlying surface comprised of this Material 00133 * 00134 * @returns a new Sensor defined at the given surface point 00135 */ 00136 virtual Sensor *getSensor(SurfacePoint &pt); 00137 00138 /** 00139 * @brief 00140 * Sets up OpenGL material state (color properties, lights, etc.) to 00141 * enable a crude/fast preview of geometry to which this Material is 00142 * applied 00143 */ 00144 virtual void preview(Shape *shape); 00145 00146 00147 //@}------------------------------------------------------------------ 00148 ///@name Utility methods for extracting BSDF/Emitter/Sensor parameters 00149 //@{------------------------------------------------------------------ 00150 00151 SpectralSampleSet getSpectralSampleSet(const std::string &key, 00152 const SpectralSampleSet &defaultValue, 00153 const SurfacePoint &pt); 00154 00155 SpectralSampleSet getSpectralSampleSet(const std::string &key, 00156 const real_t &defaultValue, 00157 const SurfacePoint &pt); 00158 00159 SpectralSampleSet getSpectralSampleSet(const std::string &key, 00160 const std::string &defaultValue, 00161 const SurfacePoint &pt); 00162 00163 SpectralSampleSet getSpectralSampleSet(const std::string &key, 00164 const SurfacePoint &pt); 00165 00166 RgbaHDR getSample(const ImagePtr &image, const UV &uv); 00167 00168 inline KernelFilter *getFilter() { 00169 return m_filter; 00170 } 00171 00172 00173 //@}----------------------------------------------------------------- 00174 ///@name Lazy evaluation of SurfacePoint information 00175 //@{----------------------------------------------------------------- 00176 00177 virtual void initSurfacePoint(SurfacePoint &pt); 00178 00179 00180 //@}----------------------------------------------------------------- 00181 00182 protected: 00183 virtual void _initShadingNormal(SurfacePoint &pt); 00184 00185 protected: 00186 KernelFilter *m_filter; 00187 00188 std::string m_bsdf; 00189 std::string m_emitter; 00190 std::string m_bumpMap; 00191 00192 real_t m_repeatU; 00193 real_t m_repeatV; 00194 real_t m_bumpIntensity; 00195 }; 00196 00197 #endif // MATERIAL_H_ 00198
Generated on 28 Feb 2009 for Milton by
1.5.6