16 #define TACHYON_INTERNAL 1    78     return incident->scene->bgtexfunc(incident);
    81   RAYPNT(hit, (*incident), t) 
    82   incident->opticdist = FHUGE; 
    83   return obj->tex->texfunc(&hit, obj->tex, incident);
    94   color col, diffuse, phongcol; 
   109     col=incident->scene->bgtexfunc(incident);
   114         incident->scene->fog.fog_fctn != NULL) {
   121   RAYPNT(shadevars.hit, (*incident), t)  
   122   incident->opticdist += t;
   123   obj->methods->normal(obj, &shadevars.hit, incident, &shadevars.N);  
   126   if ((obj->tex->opacity < 1.0) && (incident->transcnt < 1)) {      
   133   col = obj->tex->texfunc(&shadevars.hit, obj->tex, incident); 
   135   if (obj->tex->flags & RT_TEXTURE_ISLIGHT) {  
   145   if ((obj->tex->diffuse > MINCONTRIB) || (obj->tex->phong > MINCONTRIB)) {  
   146     flt light_scale = incident->scene->light_scale;
   147     cur = incident->scene->lightlist;
   148     while (cur != NULL) {              
   153       if (inten > MINCONTRIB) {            
   155         ColorAddS(&diffuse, &((standard_texture *)li->tex)->col, inten);
   158         if (obj->tex->phong > MINCONTRIB) {
   159           flt phongval = light_scale * incident->scene->phongfunc(incident, &shadevars, obj->tex->phongexp);
   161             ColorAddS(&phongcol, &col, phongval * obj->tex->phong);
   163             ColorAddS(&phongcol, &((standard_texture *)li->tex)->col, phongval * obj->tex->phong);
   171   if (obj->tex->outline > 0.0) {
   173     flt edgefactor = 
VDot(&shadevars.N, &incident->d);
   174     edgefactor *= edgefactor;
   175     edgefactor = 1.0 - edgefactor;
   176     edgefactor = 1.0 - 
POW(edgefactor, (1.0 - obj->tex->outlinewidth) * 32.0);
   177     outlinefactor = (1.0-obj->tex->outline) + (edgefactor * obj->tex->outline);
   178     ColorScale(&diffuse, obj->tex->diffuse * outlinefactor);
   183   col.r *= (diffuse.r + obj->tex->ambient); 
   184   col.g *= (diffuse.g + obj->tex->ambient); 
   185   col.b *= (diffuse.b + obj->tex->ambient); 
   187   if (obj->tex->phong > MINCONTRIB) {
   193   if (obj->tex->specular > MINCONTRIB) {    
   201   if (obj->tex->opacity < (1.0 - MINCONTRIB)) {      
   203     float alpha = obj->tex->opacity;
   207       alpha = 1.0 + 
COS(3.1415926 * (1.0-alpha) * 
VDot(&shadevars.N, &incident->d));
   208       alpha = alpha*alpha * 0.25;
   219   if (incident->scene->fog.fog_fctn != NULL) {
   234   color col, diffuse, ambocccol, phongcol;
   250     col=incident->scene->bgtexfunc(incident);
   255         incident->scene->fog.fog_fctn != NULL) {
   262   RAYPNT(shadevars.hit, (*incident), t)  
   263   incident->opticdist += t;
   264   obj->methods->normal(obj, &shadevars.hit, incident, &shadevars.N);  
   267   if ((obj->tex->opacity < 1.0) && (incident->transcnt < 1)) {      
   274   col = obj->tex->texfunc(&shadevars.hit, obj->tex, incident); 
   276   if (obj->tex->flags & RT_TEXTURE_ISLIGHT) {  
   286   if ((obj->tex->diffuse > MINCONTRIB) || (obj->tex->phong > MINCONTRIB)) {  
   287     flt light_scale = incident->scene->light_scale;
   288     cur = incident->scene->lightlist;
   290     if (incident->scene->flags & RT_SHADE_CLIPPING) {
   295     shadowray.serial = incident->serial + 1; 
   296     shadowray.mbox = incident->mbox;
   297     shadowray.scene = incident->scene;
   299     while (cur != NULL) {              
   304       if (inten > MINCONTRIB) {            
   306         shadowray.o   = shadevars.hit;
   307         shadowray.d   = shadevars.L;      
   308         shadowray.maxdist = shadevars.Llen;
   309         shadowray.flags = RT_RAY_SHADOW;
   317           inten *= shadowray.intstruct.shadowfilter;
   320           ColorAddS(&diffuse, &((standard_texture *)li->tex)->col, inten);
   323           if (obj->tex->phong > MINCONTRIB) {
   324             flt phongval = light_scale * incident->scene->phongfunc(incident, &shadevars, obj->tex->phongexp); 
   326               ColorAddS(&phongcol, &col, phongval * obj->tex->phong);
   328               ColorAddS(&phongcol, &((standard_texture *)li->tex)->col, phongval * obj->tex->phong);
   335     incident->serial = shadowray.serial; 
   338     if (incident->scene->ambocc.numsamples > 0) { 
   344   diffuse.r += ambocccol.r;
   345   diffuse.g += ambocccol.g;
   346   diffuse.b += ambocccol.b;
   348   if (obj->tex->outline > 0.0) {
   350     flt edgefactor = 
VDot(&shadevars.N, &incident->d);
   351     edgefactor *= edgefactor;
   352     edgefactor = 1.0 - edgefactor;
   353     edgefactor = 1.0 - 
POW(edgefactor, (1.0 - obj->tex->outlinewidth) * 32.0);
   354     outlinefactor = (1.0-obj->tex->outline) + (edgefactor * obj->tex->outline);
   355     ColorScale(&diffuse, obj->tex->diffuse * outlinefactor);
   361   col.r *= (diffuse.r + obj->tex->ambient);
   362   col.g *= (diffuse.g + obj->tex->ambient);
   363   col.b *= (diffuse.b + obj->tex->ambient);
   365   if (obj->tex->phong > MINCONTRIB) {
   371   if (obj->tex->specular > MINCONTRIB) {    
   379   if (obj->tex->opacity < (1.0 - MINCONTRIB)) {      
   381     float alpha = obj->tex->opacity;
   385       alpha = 1.0 + 
COS(3.1415926 * (1.0-alpha) * 
VDot(&shadevars.N, &incident->d));
   386       alpha = alpha*alpha * 0.25;
   397   if (incident->scene->fog.fog_fctn != NULL) {
   427   flt lightscale = 2.0 / incident->scene->ambocc.numsamples;
   429   ambray.o=shadevars->hit;
   430   ambray.d=shadevars->N;
   431   ambray.o=
Raypnt(&ambray, EPSILON);    
   432   ambray.serial = incident->serial + 1; 
   433   ambray.idx=incident->idx;             
   434   ambray.randval=incident->randval;     
   435   ambray.frng=incident->frng;           
   436   if (incident->scene->flags & RT_SHADE_CLIPPING) {
   441   ambray.mbox = incident->mbox; 
   442   ambray.scene=incident->scene;         
   444   for (i=0; i<incident->scene->ambocc.numsamples; i++) {
   446     ambray.maxdist = incident->scene->ambocc.ao_maxdist; 
   447     ambray.flags = RT_RAY_SHADOW;   
   457     ndotambl = 
VDot(&ambray.d, &shadevars->N);
   459       ndotambl   = -ndotambl;
   460       ambray.d.x = -ambray.d.x;
   461       ambray.d.y = -ambray.d.y;
   462       ambray.d.z = -ambray.d.z;
   472       ndotambl *= ambray.intstruct.shadowfilter;
   477   ambcol.r = lightscale * inten * incident->scene->ambocc.col.r;
   478   ambcol.g = lightscale * inten * incident->scene->ambocc.col.g;
   479   ambcol.b = lightscale * inten * incident->scene->ambocc.col.b;
   481   incident->serial = ambray.serial + 1;     
   482   incident->frng = ambray.frng;             
   495   if (incident->depth <= 1) {
   497     return incident->scene->bgtexfunc(incident);
   499   specray.depth=incident->depth - 1;     
   500   specray.transcnt=incident->transcnt;   
   502   VAddS(-2.0 * (incident->d.x * shadevars->N.x + 
   503                 incident->d.y * shadevars->N.y + 
   504                 incident->d.z * shadevars->N.z), &shadevars->N, &incident->d, &R);
   506   specray.o=shadevars->hit; 
   508   specray.o=
Raypnt(&specray, EPSILON);   
   509   specray.maxdist = FHUGE;               
   510   specray.opticdist = incident->opticdist;
   511   specray.add_intersection=incident->add_intersection; 
   512   specray.flags = RT_RAY_REGULAR;        
   513   specray.serial = incident->serial + 1; 
   514   specray.mbox = incident->mbox; 
   515   specray.scene=incident->scene;         
   516   specray.idx=incident->idx;             
   517   specray.randval=incident->randval;     
   518   specray.frng=incident->frng;           
   522   col=specray.scene->shader(&specray);
   524   incident->serial = specray.serial;     
   525   incident->frng = specray.frng;         
   538   if (incident->depth <= 1) {
   540     return incident->scene->bgtexfunc(incident);
   542   transray.o=shadevars->hit; 
   543   transray.d=incident->d;                 
   544   transray.o=
Raypnt(&transray, EPSILON);  
   545   transray.maxdist = FHUGE;               
   546   transray.opticdist = incident->opticdist;
   547   transray.add_intersection=incident->add_intersection; 
   548   transray.depth=incident->depth - 1;     
   549   transray.transcnt=incident->transcnt-1; 
   550   transray.flags = RT_RAY_REGULAR;        
   551   transray.serial = incident->serial + 1; 
   552   transray.mbox = incident->mbox;
   553   transray.scene=incident->scene;         
   554   transray.idx=incident->idx;             
   555   transray.randval=incident->randval;     
   556   transray.frng=incident->frng;           
   560   col=transray.scene->shader(&transray);
   562   incident->serial = transray.serial;     
   563   incident->frng = transray.frng;         
   589   H.x = shadevars->L.x - incident->d.x; 
   590   H.y = shadevars->L.y - incident->d.y;
   591   H.z = shadevars->L.z - incident->d.z;
   593   inten = shadevars->N.x * H.x + shadevars->N.y * H.y + shadevars->N.z * H.z;
   594   if (inten > MINCONTRIB) {
   596     inten /= 
SQRT(H.x * H.x + H.y * H.y + H.z * H.z);
   599     inten = 
POW(inten, specpower);
   622   H.x = shadevars->L.x - incident->d.x; 
   623   H.y = shadevars->L.y - incident->d.y;
   624   H.z = shadevars->L.z - incident->d.z;
   626   inten = shadevars->N.x * H.x + shadevars->N.y * H.y + shadevars->N.z * H.z;
   629     inten /= 
SQRT(H.x * H.x + H.y * H.y + H.z * H.z);
   632     inten = inten / (specpower - (specpower * inten) + inten);
   654   VAddS(-2.0 * (LL.x * shadevars->N.x + 
   655                 LL.y * shadevars->N.y + 
   656                 LL.z * shadevars->N.z), &shadevars->N, &LL, &R);
   661   inten = 
VDot(&V, &R); 
   662   inten = (inten > 0.0) ? 
POW(inten, specpower) : 0.0;
   677   struct fogdata_t * fog = &incident->scene->fog;
   683     flt hitz = 
VDot(&incident->d, &incident->scene->camera.viewvec) * t;
   686     fogcoord = (incident->flags & RT_RAY_PRIMARY) ? hitz : t;
   689   return incident->scene->fog.fog_fctn(fog, col, fogcoord);
   700   f = (fog->end - r) / (fog->end - fog->start);
   701   t = (f > 1.0) ? 1.0 : f;
   702   f = (t < 0.0) ? 0.0 : t;
   704   c.r = (f * col.r) + ((1 - f) * fog->col.r);
   705   c.g = (f * col.g) + ((1 - f) * fog->col.g);
   706   c.b = (f * col.b) + ((1 - f) * fog->col.b);
   719   v = fog->density * (r - fog->start);
   721   t = (f > 1.0) ? 1.0 : f;
   722   f = (t < 0.0) ? 0.0 : t;
   724   c.r = (f * col.r) + ((1 - f) * fog->col.r);
   725   c.g = (f * col.g) + ((1 - f) * fog->col.g);
   726   c.b = (f * col.b) + ((1 - f) * fog->col.b);
   739   v = fog->density * (r - fog->start);
   741   t = (f > 1.0) ? 1.0 : f;
   742   f = (t < 0.0) ? 0.0 : t;
   744   c.r = (f * col.r) + ((1 - f) * fog->col.r);
   745   c.g = (f * col.g) + ((1 - f) * fog->col.g);
   746   c.b = (f * col.b) + ((1 - f) * fog->col.b);
 void add_clipped_shadow_intersection(flt t, const object *obj, ray *ry)
 
void ColorScale(color *a, flt s)
 
color shade_reflection(ray *incident, const shadedata *shadevars, flt specular)
 
color shade_transmission(ray *incident, const shadedata *shadevars, flt trans)
 
int closest_intersection(flt *t, object const **obj, ray *ry)
 
color fog_color_exp2(struct fogdata_t *fog, color col, flt r)
OpenGL-like exponential-squared fog. 
 
void ColorAddS(color *a, const color *b, flt s)
 
void ColorAccum(color *a, const color *b)
 
#define RT_TRANS_VMD
mult shaded color by opacity, for VMD 
 
color shade_ambient_occlusion(ray *incident, const shadedata *shadevars)
 
color lowest_shader(ray *incident)
 
color fog_color_exp(struct fogdata_t *fog, color col, flt r)
OpenGL-like exponential fog. 
 
void VScale(vector *a, flt s)
 
#define RT_FOG_OPENGL
planar OpenGL-like fog 
 
RT_OBJECT_HEAD flt(* shade_diffuse)(struct light_t *, shadedata *)
diffuse shading function 
 
void jitter_sphere3f(rng_frand_handle *rngh, float *dir)
 
void VAddS(flt a, apivector *A, apivector *B, apivector *C)
 
int shadow_intersection(ray *ry)
 
flt VDot(apivector *a, apivector *b)
 
Tachyon cross-platform thread creation and management, atomic operations, and CPU feature query APIs...
 
#define RT_TRANS_RASTER3D
angle-dependent opacity modulation 
 
double flt
generic floating point number, using double 
 
flt shade_nullphong(const ray *incident, const shadedata *shadevars, flt specpower)
 
flt shade_blinn_fast(const ray *incident, const shadedata *shadevars, flt specpower)
 
color medium_shader(ray *incident)
 
color full_shader(ray *incident)
 
color fog_color_linear(struct fogdata_t *fog, color col, flt r)
OpenGL-like linear fog. 
 
void add_shadow_intersection(flt t, const object *obj, ray *ry)
 
color fog_color(const ray *incident, color col, flt t)
Compute the fog color, given the active fogging function and fog parameters. 
 
vector Raypnt(const ray *a, flt t)
 
color low_shader(ray *incident)
 
Tachyon public API function prototypes and declarations used to drive the ray tracing engine...
 
#define RT_FOG_NORMAL
radial fog 
 
flt shade_phong(const ray *incident, const shadedata *shadevars, flt specpower)
 
#define RT_PHONG_METAL
Metallic Phong highlight. 
 
void intersect_objects(ray *ry)
 
flt shade_blinn(const ray *incident, const shadedata *shadevars, flt specpower)