1 ////////////////////////////////////////////////////////////////////// 2 // 3 // Pixie 4 // 5 // Copyright � 1999 - 2003, Okan Arikan 6 // 7 // Contact: okan@cs.utexas.edu 8 // 9 // This library is free software; you can redistribute it and/or 10 // modify it under the terms of the GNU Lesser General Public 11 // License as published by the Free Software Foundation; either 12 // version 2.1 of the License, or (at your option) any later version. 13 // 14 // This library is distributed in the hope that it will be useful, 15 // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 // Lesser General Public License for more details. 18 // 19 // You should have received a copy of the GNU Lesser General Public 20 // License along with this library; if not, write to the Free Software 21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 // 23 /////////////////////////////////////////////////////////////////////// 24 /////////////////////////////////////////////////////////////////////// 25 // 26 // File : attributes.h 27 // Classes : CAttributes 28 // Description : Holds the attributes attached to an object 29 // 30 //////////////////////////////////////////////////////////////////////// 31 #ifndef ATTRIBUTES_H 32 #define ATTRIBUTES_H 33 34 #include "common/global.h" // The global header file 35 #include "common/algebra.h" // Matrix - vector stuff 36 #include "common/containers.h" // Misc data structures 37 #include "xform.h" // Transformations 38 #include "shader.h" // Shader stuff 39 #include "userAttributes.h" // Attribute dictionary stuff 40 41 class CPhotonMap; 42 43 // Constant definitions for the flag field of the attributes 44 const unsigned int ATTRIBUTES_FLAGS_INSIDE = 1; // Flip the orientation 45 const unsigned int ATTRIBUTES_FLAGS_CUSTOM_ST = 1 << 1; // Explicit surface st 46 const unsigned int ATTRIBUTES_FLAGS_MATTE = 1 << 2; // The object is matte 47 const unsigned int ATTRIBUTES_FLAGS_CUSTOM_BOUND = 1 << 3; // The bound of the object is explicitly set 48 const unsigned int ATTRIBUTES_FLAGS_BINARY_DICE = 1 << 4; // Use binary dicing on the surface 49 const unsigned int ATTRIBUTES_FLAGS_PRIMARY_VISIBLE = 1 << 6; // The primitive is visible to the primary rays 50 const unsigned int ATTRIBUTES_FLAGS_PHOTON_VISIBLE = 1 << 7; // The primitive is visible to the photon rays 51 const unsigned int ATTRIBUTES_FLAGS_SPECULAR_VISIBLE = 1 << 9; // The primitive is visible to the gather/trace/environment rays 52 const unsigned int ATTRIBUTES_FLAGS_DIFFUSE_VISIBLE = 1 << 10; // The primitive is visible to the gather/occlusion/diffuse rays 53 const unsigned int ATTRIBUTES_FLAGS_TRANSMISSION_VISIBLE = 1 << 11; // The primitive is visible to the transmission/shadow rays 54 const unsigned int ATTRIBUTES_FLAGS_DISPLACEMENTS = 1 << 14; // The primitive is visible to the photon rays 55 const unsigned int ATTRIBUTES_FLAGS_ILLUMINATE_FRONT_ONLY = 1 << 17; // During the photon tracing, only photons that hit the front will be traced 56 const unsigned int ATTRIBUTES_FLAGS_LOD = 1 << 18; // A detail range has been specified 57 const unsigned int ATTRIBUTES_FLAGS_DISCARD_GEOMETRY = 1 << 19; // Discard geometry calls 58 const unsigned int ATTRIBUTES_FLAGS_DISCARD_ALL = 1 << 20; // Discard all calls 59 const unsigned int ATTRIBUTES_FLAGS_NONRASTERORIENT_DICE = 1 << 21; // Perform non raster-oriented dicing 60 const unsigned int ATTRIBUTES_FLAGS_SHADE_HIDDEN = 1 << 22; // Shade even if occluded 61 const unsigned int ATTRIBUTES_FLAGS_SHADE_BACKFACE = 1 << 23; // Shade even if backfacing 62 const unsigned int ATTRIBUTES_FLAGS_DOUBLE_SIDED = 1 << 24; // The surface is double sided 63 const unsigned int ATTRIBUTES_FLAGS_SAMPLEMOTION = 1 << 25; // Sample the time in tracing rays 64 65 66 // The minimum shading rate 67 const float ATTRIBUTES_MIN_SHADINGRATE = C_EPSILON; 68 69 /////////////////////////////////////////////////////////////////////// 70 // Class : CActiveLight 71 // Description : Holds an active light source instance 72 // Comments : 73 class CActiveLight { 74 public: 75 CProgrammableShaderInstance *light; 76 CActiveLight *next; 77 }; 78 79 // The shading model 80 typedef enum { 81 SM_MATTE, 82 SM_TRANSLUCENT, 83 SM_CHROME, 84 SM_GLASS, 85 SM_WATER, 86 SM_DIELECTRIC, 87 SM_TRANSPARENT 88 } EShadingModel; 89 90 /////////////////////////////////////////////////////////////////////// 91 // Class : CAttributes 92 // Description : This class encapsulates the attributes attached 93 // to a surface. Surfaces that have the same set of 94 // attributes share a common clone to avoid unnecessary 95 // memory allocation. 96 // Comments : 97 class CAttributes : public CRefCounter { 98 public: 99 CAttributes(); 100 CAttributes(const CAttributes *); 101 virtual ~CAttributes(); 102 103 void addLight(CShaderInstance *); // Add or remove a lightsource from the environment 104 void removeLight(CShaderInstance *); 105 void checkParameters(); // Re-compute the required shader parameters 106 CVariable *findParameter(const char *); // Find a shader parameter 107 void restore(const CAttributes *other,int shading,int geometrymodification,int geometrydefinition,int hiding); 108 int find(const char *name,const char *category,EVariableType &type,const void *&value,int &intValue,float &floatValue) const; 109 110 CAttributes *next; // points to the next attribute if there's motion blur 111 112 CShaderInstance *surface; // Shaders attached to the primitive 113 CShaderInstance *displacement; 114 CShaderInstance *atmosphere; 115 CShaderInstance *interior; 116 CShaderInstance *exterior; 117 unsigned int usedParameters; // The set of used parameters that the shaders need 118 119 vector surfaceColor; // Default surface color and opacity 120 vector surfaceOpacity; 121 122 float s[4],t[4]; // The texture coordinates 123 124 vector bmin,bmax; // The custom bounding box if given 125 float bexpand; // Bounding box expansion percentage 126 127 matrix uBasis,vBasis; // The basis for bicubic patches 128 int uStep,vStep; // The step sizes for bicubic patches 129 130 unsigned int flags; // Attribute flags 131 132 float maxDisplacement; // Maximum amount of displacement in camera system 133 char *maxDisplacementSpace; // The current space in which the maximum displacement is given 134 135 CActiveLight *lightSources; // The list of active light sources 136 137 float shadingRate; // Shading rate for this primitive 138 float motionFactor; // Amount to increase shading rate when motion blurring 139 140 char *name; // The name of the object if any 141 142 int numUProbes,numVProbes; // The samples to gather when estimating the extend of a patch 143 int minSplits; // The minimum number of splits 144 float rasterExpand; // The expansion coefficient during the sampling 145 float bias; // The bias amount expressed in the camera coordinates 146 147 char transmissionHitMode; // Either: 'p' = Look at the primitive or 's' = Execute the shader 148 char specularHitMode; // Either: 'p' = Look at the primitive or 's' = Execute the shader 149 char diffuseHitMode; // Either: 'p' = Look at the primitive or 's' = Execute the shader 150 char cameraHitMode; // Either: 'p' = Look at the primitive or 's' = Execute the shader 151 152 int emit; // The number of photons to emit from this light source 153 float relativeEmit; // The relative emittance 154 155 EShadingModel shadingModel; // The surface shading model 156 157 char *globalMapName; // The name of the global photon map 158 char *causticMapName; // The name of the caustic photon map 159 CPhotonMap *globalMap; // The global photon map 160 CPhotonMap *causticMap; // The caustic photon map 161 char *irradianceHandle; // The irradiance cache 162 char *irradianceHandleMode; // The irradiance cache mode 163 float irradianceMaxError; // The error threshold for the irradiance cache 164 float irradianceMaxPixelDistance; // The maximum pixel distance between the samples for trradiance caching 165 int photonEstimator; // The total number of photons to use to estimate irradiance 166 float photonIor[2]; // Index of refraction range used for the dielectic shading model 167 int maxDiffuseDepth; // The maximum number of diffuse bounces before going to the photon map 168 int maxSpecularDepth; // The maximum number of specular bounces before giving up 169 int shootStep; // The step size for shooting rays for the attached object 170 171 float lodRange[4]; // LOD variables 172 float lodSize; 173 float lodImportance; 174 175 CUserAttributeDictionary userAttributes; // Duh. 176 177 static char findHitMode(const char *mode); 178 static const char *findHitMode(char mode); 179 static EShadingModel findShadingModel(const char *name); 180 static const char *findShadingModel(EShadingModel model); 181 182 }; 183 184 #endif 185 186