1 /* 2 * types.h - This file contains all of the type definitions for the raytracer 3 * 4 * $Id: types.h,v 1.117 2009/05/18 03:31:48 johns Exp $ 5 */ 6 7 #ifndef TYPES_H 8 #define TYPES_H 1 9 10 #include "rtcommon.h" /* defintions common to all interfaces */ 11 12 struct ray_t; 13 14 #ifdef USESINGLEFLT 15 /* All floating point types will be based on "float" */ 16 #define SPEPSILON 0.0001f /* amount to crawl down a ray */ 17 #define EPSILON 0.0001f /* amount to crawl down a ray */ 18 #define FHUGE 1e18f /* biggest fp number we care about */ 19 #define TWOPI 6.28318531f /* guess... :-) */ 20 #define MINCONTRIB 0.001959f /* 1.0 / 512.0, smallest contribution */ 21 /* to overall pixel color we care about */ 22 /* XXX this must change for HDR images */ 23 #else 24 /* All floating point types will be based on "double" */ 25 #define SPEPSILON 0.00000005 /* amount to crawl down a ray */ 26 #define EPSILON 0.00000005 /* amount to crawl down a ray */ 27 #define FHUGE 1e18 /* biggest fp number we care about */ 28 #define TWOPI 6.28318531 /* guess... :-) */ 29 #define MINCONTRIB 0.001959 /* 1.0 / 512.0, smallest contribution */ 30 /* to overall pixel color we care about */ 31 /* XXX this must change for HDR images */ 32 #endif 33 34 #define BOUNDTHRESH 16 /* subdivide cells /w > # of children */ 35 36 /* 37 * Maximum internal table sizes 38 * Use prime numbers for best memory system performance 39 * (helps avoid cache aliasing..) 40 */ 41 #define MAXIMGS 39 /* maxiumum number of distinct images */ 42 43 /* 44 * Ray flags 45 * 46 * These are used in order to skip calculations which are only 47 * needed some of the time. For example, when shooting shadow 48 * rays, we only have to find *one* intersection that's valid, 49 * if we find even one, we can quit early, thus saving lots of work. 50 */ 51 #define RT_RAY_PRIMARY 1 /* A primary ray */ 52 #define RT_RAY_REGULAR 2 /* A regular ray, fewer shorcuts available */ 53 #define RT_RAY_SHADOW 4 /* A shadow ray, we can early-exit asap */ 54 #define RT_RAY_FINISHED 8 /* We've found what we're looking for already */ 55 /* early-exit at soonest opportunity.. */ 56 /* 57 * Texture flags 58 * 59 * These are used in order to skip calculations that are only needed 60 * some of the time. 61 */ 62 #define RT_TEXTURE_NOFLAGS 0 /* No options set */ 63 #define RT_TEXTURE_SHADOWCAST 1 /* This object casts a shadow */ 64 #define RT_TEXTURE_ISLIGHT 2 /* This object is a light */ 65 66 /* 67 * Image buffer format flags 68 */ 69 #define RT_IMAGE_BUFFER_RGB24 0 /* 24-bit color, unsigned char RGB */ 70 #define RT_IMAGE_BUFFER_RGB96F 1 /* 96-bit color, 32-bit float RGB */ 71 72 /* 73 * Image post-processing flags 74 */ 75 #define RT_IMAGE_CLAMP 0 /* clamp pixel values [0 to 1) */ 76 #define RT_IMAGE_NORMALIZE 1 /* normalize pixel values [0 to 1) */ 77 #define RT_IMAGE_GAMMA 2 /* gamma correction */ 78 79 typedef unsigned char byte; /* 1 byte */ 80 81 typedef struct { 82 flt x; /* X coordinate value */ 83 flt y; /* Y coordinate value */ 84 flt z; /* Z coordinate value */ 85 } vector; 86 87 88 typedef struct { 89 float r; /* Red component */ 90 float g; /* Green component */ 91 float b; /* Blue component */ 92 } color; 93 94 95 typedef struct { /* Raw 24 bit RGB image structure */ 96 int loaded; /* image memory residence flag */ 97 int xres; /* image X axis size */ 98 int yres; /* image Y axis size */ 99 int zres; /* image Z axis size */ 100 int bpp; /* image bits per pixel */ 101 char name[96]; /* image filename (with path) */ 102 unsigned char * data; /* pointer to raw byte image data */ 103 } rawimage; 104 105 106 typedef struct { 107 int levels; 108 rawimage ** images; 109 } mipmap; 110 111 112 typedef struct { /* Scalar Volume Data */ 113 int loaded; /* Volume data memory residence flag */ 114 int xres; /* volume X axis size */ 115 int yres; /* volume Y axis size */ 116 int zres; /* volume Z axis size */ 117 flt opacity; /* opacity per unit length */ 118 char name[96]; /* Volume data filename */ 119 unsigned char * data; /* pointer to raw byte volume data */ 120 } scalarvol; 121 122 123 /* 124 * Background texture data structure 125 */ 126 typedef struct { 127 color background; /* solid background color */ 128 vector gradient; /* gradient direction vector for "up" */ 129 flt gradtopval; /* texture dot product max parameter for top */ 130 flt gradbotval; /* texture dot product min parameter for bot */ 131 color backgroundtop; /* gradient background top */ 132 color backgroundbot; /* gradient background bottom */ 133 } background_texture; 134 135 /* 136 * Object texture data structures 137 */ 138 typedef struct { 139 void (* freetex)(void *); /* free the texture */ 140 } texture_methods; 141 142 #define RT_TEXTURE_HEAD \ 143 color (* texfunc)(const void *, const void *, void *); \ 144 texture_methods * methods; /* this texture's methods */ \ 145 unsigned int flags; /* texturing/lighting flags */ \ 146 float ambient; /* ambient lighting */ \ 147 float diffuse; /* diffuse reflection */ \ 148 float phong; /* phong specular highlights */ \ 149 float phongexp; /* phong exponent/shininess factor */ \ 150 int phongtype; /* phong type: 0 == plastic, nonzero == metal */ \ 151 float specular; /* specular reflection */ \ 152 float opacity; /* how opaque the object is */ \ 153 float outline; /* edge outline shading (for VMD) */ \ 154 float outlinewidth; /* edge outline width (for VMD) */ 155 156 typedef struct { 157 RT_TEXTURE_HEAD 158 } texture; 159 160 typedef struct { 161 RT_TEXTURE_HEAD 162 color col; /* base object color */ 163 vector ctr; /* origin of texture */ 164 vector rot; /* rotation of texture about origin */ 165 vector scale; /* scale of texture in x,y,z */ 166 vector uaxs; /* planar/volume map U axis */ 167 vector vaxs; /* planar/volume map V axis */ 168 vector waxs; /* volumetric map W axis */ 169 void * img; /* pointer to image or volume texture */ 170 void * obj; /* object ptr, hack for vol shaders */ 171 } standard_texture; 172 173 typedef struct { 174 RT_TEXTURE_HEAD 175 void * obj; /* object ptr, hack for vcstri for now */ 176 color c0; /* color for vertex 0 */ 177 color c1; /* color for vertex 1 */ 178 color c2; /* color for vertex 2 */ 179 } vcstri_texture; 180 181 182 /* 183 * Object data structures 184 */ 185 typedef struct { 186 void (* intersect)(const void *, void *); /* intersection func ptr */ 187 void (* normal)(const void *, const void *, const void *, void *); /* normal function ptr */ 188 int (* bbox)(void *, vector *, vector *); /* return the object bbox */ 189 void (* freeobj)(void *); /* free the object */ 190 } object_methods; 191 192 193 /* 194 * Clipping plane data structure 195 */ 196 typedef struct { 197 int numplanes; /* number of clipping planes */ 198 flt * planes; /* 4 plane eq coefficients per plane */ 199 } clip_group; 200 201 202 #define RT_OBJECT_HEAD \ 203 unsigned int id; /* Unique Object serial number */ \ 204 void * nextobj; /* pointer to next object in list */ \ 205 object_methods * methods; /* this object's methods */ \ 206 clip_group * clip; /* this object's clip group */ \ 207 texture * tex; /* object texture */ 208 209 210 typedef struct { 211 RT_OBJECT_HEAD 212 } object; 213 214 215 typedef struct { 216 const object * obj; /* to object we hit */ 217 flt t; /* distance along the ray to the hit point */ 218 } intersection; 219 220 221 typedef struct { 222 int num; /* number of intersections */ 223 intersection closest; /* closest intersection > 0.0 */ 224 flt shadowfilter; /* modulation by transparent surfaces */ 225 } intersectstruct; 226 227 228 229 typedef struct { 230 int projection; /* camera projection mode */ 231 vector center; /* center of the camera in world coords */ 232 vector viewvec; /* view direction of the camera (Z axis) */ 233 vector rightvec; /* right axis for the camera (X axis) */ 234 vector upvec; /* up axis for the camera (Y axis) */ 235 flt camzoom; /* zoom factor for the camera */ 236 flt px; /* width of image plane in world coords */ 237 flt py; /* height of image plane in world coords */ 238 flt psx; /* width of pixel in world coords */ 239 flt psy; /* height of pixel in world coords */ 240 flt focallength; /* distance from eye to focal plane */ 241 flt left; /* left side of perspective frustum */ 242 flt right; /* right side of perspective frustum */ 243 flt top; /* top side of perspective frustum */ 244 flt bottom; /* bottom side of perspective frustum */ 245 flt aperture; /* depth of field aperture */ 246 vector projcent; /* center of image plane in world coords */ 247 color (* cam_ray)(void *, flt, flt); /* camera ray generator fctn */ 248 vector lowleft; /* lower left corner of image plane */ 249 vector iplaneright; /* image plane right vector */ 250 vector iplaneup; /* image plane up vector */ 251 } camdef; 252 253 typedef struct fogdata_t { 254 color (* fog_fctn)(struct fogdata_t *, color, flt); /* fogging function */ 255 int type; /* radial, planer, etc */ 256 color col; /* fog color */ 257 flt start; /* fog start parameter */ 258 flt end; /* fog end parameter */ 259 flt density; /* fog density parameter */ 260 } fogdata; 261 262 typedef struct amboccdata_t { 263 int numsamples; /* number of samples for ambient occlusion */ 264 color col; /* color of ambient occlusion light */ 265 } amboccludedata; 266 267 typedef struct { 268 int numcpus; /* number of processors on this node */ 269 flt cpuspeed; /* relative speed of cpus on this node */ 270 flt nodespeed; /* relative speed index for this node */ 271 char machname[512]; /* machine/node name */ 272 } nodeinfo; 273 274 typedef struct list { 275 void * item; 276 struct list * next; 277 } list; 278 279 typedef struct { 280 vector hit; /* ray object intersection hit point */ 281 vector N; /* surface normal at the hit point */ 282 vector L; /* vector point in the direction from hit point to the light */ 283 flt Llen; /* distance from hit point to the light (if any) */ 284 } shadedata; 285 286 typedef struct { 287 int cropmode; /* output image cropping mode */ 288 int xres; /* cropped image x resolution in pixels */ 289 int yres; /* cropped image y resolution in pixels */ 290 int xstart; /* starting pixel in x (left side) */ 291 int ystart; /* starting pixel in y (top size) */ 292 } cropinfo; 293 294 typedef struct { 295 object * boundedobj; /* bounded object list, starts out empty */ 296 object * unboundedobj; /* unbounded object list, starts out empty */ 297 int numobjects; /* number of objects in group */ 298 } displist; 299 300 typedef struct { 301 char outfilename[256]; /* name of the output image */ 302 int writeimagefile; /* enable/disable writing of image to disk */ 303 void * img; /* pointer to a raw rgb image to be stored */ 304 int imginternal; /* image was allocated by the library */ 305 int imgprocess; /* image post processing flags */ 306 float imggamma; /* image gamma correction value */ 307 int imgbufformat; /* pixel format for image buffer */ 308 int imgfileformat; /* output format for final image */ 309 cropinfo imgcrop; /* image output cropping for SPEC MPI */ 310 int numthreads; /* user controlled number of threads */ 311 int nodes; /* number of distributed memory nodes */ 312 int mynode; /* my distributed memory node number */ 313 nodeinfo * cpuinfo; /* overall cpu/node/threads info */ 314 int hres; /* horizontal output image resolution */ 315 int vres; /* vertical output image resolution */ 316 flt aspectratio; /* aspect ratio of output image */ 317 int raydepth; /* maximum recursion depth */ 318 int antialiasing; /* number of antialiasing rays to fire */ 319 int verbosemode; /* verbose reporting flag */ 320 int boundmode; /* automatic spatial subdivision flag */ 321 int boundthresh; /* threshold number of subobjects */ 322 list * texlist; /* linked list of texture objects */ 323 list * cliplist; /* linked list of clipping plane groups */ 324 unsigned int flags; /* scene feature requirement flags */ 325 camdef camera; /* camera definition */ 326 color (* shader)(void *); /* main shader used for the whole scene */ 327 flt (* phongfunc)(const struct ray_t * incident, const shadedata * shadevars, flt specpower); /* phong shader used for whole scene */ 328 int transmode; /* transparency mode */ 329 background_texture bgtex; /* background texture parameters */ 330 color (* bgtexfunc)(const struct ray_t * incident); /* background texturing function ptr */ 331 fogdata fog; /* fog parameters */ 332 displist objgroup; /* objects in the scene */ 333 list * lightlist; /* linked list of lights in the scene */ 334 flt light_scale; /* global scaling factor for direct lights */ 335 int numlights; /* number of lights in the scene */ 336 amboccludedata ambocc; /* ambient occlusion data */ 337 int scenecheck; /* re-check scene for changes */ 338 void * parbuf; /* parallel message passing handle */ 339 void * threads; /* thread handles */ 340 void * threadparms; /* thread parameters */ 341 clip_group * curclipgroup; /* current clipping group, during parsing */ 342 int normalfixupmode; /* normal/winding order fixup for stri */ 343 } scenedef; 344 345 346 typedef struct ray_t { 347 vector o; /* origin of the ray X,Y,Z */ 348 vector d; /* normalized direction of the ray */ 349 flt maxdist; /* maximum distance to search for intersections */ 350 flt opticdist; /* total distance traveled from camera so far */ 351 void (* add_intersection)(flt, const object *, struct ray_t *); 352 intersectstruct intstruct; /* ptr to thread's intersection data */ 353 unsigned int depth; /* levels left to recurse.. (maxdepth - curdepth) */ 354 unsigned int flags; /* ray flags, any special treatment needed etc */ 355 unsigned long serial; /* serial number of the ray */ 356 unsigned long * mbox; /* mailbox array for optimizing intersections */ 357 scenedef * scene; /* pointer to the scene, for global parms such as */ 358 /* background colors etc */ 359 unsigned int randval; /* random number seed */ 360 rng_frand_handle frng; /* 32-bit FP random number generator handle */ 361 } ray; 362 363 #endif 364