20 #define TACHYON_INTERNAL 1    40   VCross(&scene->camera.upvec, &scene->camera.viewvec, &newrightvec);
    43   VCross(&scene->camera.viewvec, &newrightvec, &newupvec);
    46   newviewvec=scene->camera.viewvec;
    48   scene->camera.rightvec=newrightvec;
    49   scene->camera.upvec=newupvec;
    51   sx = (
flt) scene->hres; 
    52   sy = (
flt) scene->vres;
    56   scene->camera.px=((sx / sy) / scene->aspectratio) / scene->camera.camzoom;
    57   scene->camera.py=1.0 / scene->camera.camzoom;
    58   scene->camera.psx = scene->camera.px / sx;
    59   scene->camera.psy = scene->camera.py / sy;
    61   if (scene->camera.frustumcalc == RT_CAMERA_FRUSTUM_AUTO) {
    62     scene->camera.left   = -0.5 * scene->camera.px;
    63     scene->camera.right  =  0.5 * scene->camera.px;
    64     scene->camera.bottom = -0.5 * scene->camera.py;
    65     scene->camera.top    =  0.5 * scene->camera.py;
    69   switch (scene->camera.projection) {
    71       if (scene->antialiasing > 0) {
    83       if (scene->antialiasing > 0) {
    95       if (scene->antialiasing > 0) {
   103       if (scene->antialiasing > 0) {
   114   switch (scene->camera.projection) { 
   116       scene->camera.projcent.x = scene->camera.center.x + scene->camera.viewvec.x;
   117       scene->camera.projcent.y = scene->camera.center.y + scene->camera.viewvec.y;
   118       scene->camera.projcent.z = scene->camera.center.z + scene->camera.viewvec.z;
   122       scene->camera.projcent = scene->camera.center;
   126       scene->camera.lowleft.x = scene->camera.projcent.x +
   127         (scene->camera.left   * scene->camera.rightvec.x) +
   128         (scene->camera.bottom * scene->camera.upvec.x);
   129       scene->camera.lowleft.y = scene->camera.projcent.y +
   130         (scene->camera.left   * scene->camera.rightvec.y) +
   131         (scene->camera.bottom * scene->camera.upvec.y);
   132       scene->camera.lowleft.z = scene->camera.projcent.z +
   133         (scene->camera.left   * scene->camera.rightvec.z) +
   134         (scene->camera.bottom * scene->camera.upvec.z);
   140       scene->camera.projcent.x = scene->camera.center.x + scene->camera.viewvec.x;
   141       scene->camera.projcent.y = scene->camera.center.y + scene->camera.viewvec.y;
   142       scene->camera.projcent.z = scene->camera.center.z + scene->camera.viewvec.z;
   149       scene->camera.lowleft.x = scene->camera.projcent.x +
   150         (scene->camera.left   * scene->camera.rightvec.x) +
   151         (scene->camera.bottom * scene->camera.upvec.x)
   152         - scene->camera.center.x;
   153       scene->camera.lowleft.y = scene->camera.projcent.y +
   154         (scene->camera.left   * scene->camera.rightvec.y) +
   155         (scene->camera.bottom * scene->camera.upvec.y)
   156         - scene->camera.center.y;
   157       scene->camera.lowleft.z = scene->camera.projcent.z +
   158         (scene->camera.left   * scene->camera.rightvec.z) +
   159         (scene->camera.bottom * scene->camera.upvec.z)
   160         - scene->camera.center.z;
   165   scene->camera.px = scene->camera.right - scene->camera.left; 
   166   scene->camera.py = scene->camera.top - scene->camera.bottom; 
   167   scene->camera.psx = scene->camera.px / scene->hres;
   168   scene->camera.psy = scene->camera.py / scene->vres;
   170   scene->camera.iplaneright.x = scene->camera.px * scene->camera.rightvec.x / sx;
   171   scene->camera.iplaneright.y = scene->camera.px * scene->camera.rightvec.y / sx;
   172   scene->camera.iplaneright.z = scene->camera.px * scene->camera.rightvec.z / sx;
   174   scene->camera.iplaneup.x = scene->camera.py * scene->camera.upvec.x / sy;
   175   scene->camera.iplaneup.y = scene->camera.py * scene->camera.upvec.y / sy;
   176   scene->camera.iplaneup.z = scene->camera.py * scene->camera.upvec.z / sy;
   186 void camray_init(scenedef *scene, ray *primary, 
unsigned long serial, 
   187                  unsigned long * mbox, 
   188                  unsigned int aarandval,
   189                  unsigned int aorandval) {
   191   if (scene->flags & RT_SHADE_CLIPPING) {
   197   primary->serial = serial;
   198   primary->mbox = mbox;
   199   primary->scene = scene;
   200   primary->depth = scene->raydepth;      
   201   primary->transcnt = scene->transcount; 
   202   primary->randval = aarandval;          
   203 #if defined(RT_ACCUMULATE_ON)   210   primary->d = scene->camera.viewvec; 
   213   primary->o = scene->camera.center;
   223 color cam_perspective_aa_dof_maxvariance_ray(ray * ry, 
flt x, 
flt y) {
   225   color colsum, colsumsq, colvar;
   226   int samples, samplegroup; 
   227   scenedef * scene=ry->scene;
   228   flt dx, dy, rnsamples, ftmp;
   233   colsumsq.r = colsum.r * colsum.r; 
   234   colsumsq.g = colsum.g * colsum.g;
   235   colsumsq.b = colsum.b * colsum.b;
   245   while (samples < scene->antialiasing) {
   247     samplegroup = scene->antialiasing;
   250       samplegroup = samples + 1;
   252       samplegroup = samples + 32;
   256     for (; samples <= samplegroup; samples++) {
   260       dx = jxy[0] * ry->scene->camera.aperture * ry->scene->hres; 
   261       dy = jxy[1] * ry->scene->camera.aperture * ry->scene->vres; 
   264       ry->o.x = ry->scene->camera.center.x + 
   265                 dx * ry->scene->camera.iplaneright.x +
   266                 dy * ry->scene->camera.iplaneup.x;
   267       ry->o.y = ry->scene->camera.center.y + 
   268                 dx * ry->scene->camera.iplaneright.y +
   269                 dy * ry->scene->camera.iplaneup.y;
   270       ry->o.z = ry->scene->camera.center.z + 
   271                 dx * ry->scene->camera.iplaneright.z +
   272                 dy * ry->scene->camera.iplaneup.z;
   278       colsum.r += sample.r;               
   279       colsum.g += sample.g;
   280       colsum.b += sample.b;
   282       colsumsq.r += sample.r * sample.r;  
   283       colsumsq.g += sample.g * sample.g;
   284       colsumsq.b += sample.b * sample.b;
   288     rnsamples = 1.0 / samples;
   289     ftmp = colsum.r * rnsamples;
   290     colvar.r = ((colsumsq.r * rnsamples) - ftmp*ftmp) * rnsamples;
   291     ftmp = colsum.g * rnsamples;
   292     colvar.g = ((colsumsq.g * rnsamples) - ftmp*ftmp) * rnsamples;
   293     ftmp = colsum.b * rnsamples;
   294     colvar.b = ((colsumsq.b * rnsamples) - ftmp*ftmp) * rnsamples;
   299     if ((colvar.r < maxvar) && (colvar.g < maxvar) && (colvar.b < maxvar)) {
   305   col.r = colsum.r * rnsamples;
   306   col.g = colsum.g * rnsamples;
   307   col.b = colsum.b * rnsamples;
   322   scenedef * scene=ry->scene;
   324 #if defined(RT_ACCUMULATE_ON)   325   col.r = col.g = col.b = 0.0f;
   337 #if defined(RT_ACCUMULATE_ON)   338   for (alias=0; alias <= scene->antialiasing; alias++) {
   340   for (alias=1; alias <= scene->antialiasing; alias++) {
   352   scale = 1.0f / (scene->antialiasing + 1.0f); 
   366   flt rdx, rdy, rdz, invlen;
   370   vector oldorigin=ry->o;      
   371   scenedef * scene=ry->scene;
   377   rdx = scene->camera.lowleft.x + 
   378                 (x * scene->camera.iplaneright.x) + 
   379                 (y * scene->camera.iplaneup.x);
   381   rdy = scene->camera.lowleft.y + 
   382                 (x * scene->camera.iplaneright.y) + 
   383                 (y * scene->camera.iplaneup.y);
   385   rdz = scene->camera.lowleft.z + 
   386                 (x * scene->camera.iplaneright.z) + 
   387                 (y * scene->camera.iplaneup.z);
   390   invlen = 1.0 / 
SQRT(rdx*rdx + rdy*rdy + rdz*rdz);
   391   ry->d.x = rdx * invlen;
   392   ry->d.y = rdy * invlen;
   393   ry->d.z = rdz * invlen;
   396   focuspoint.x = ry->o.x + ry->d.x * scene->camera.dof_focaldist;
   397   focuspoint.y = ry->o.y + ry->d.y * scene->camera.dof_focaldist;
   398   focuspoint.z = ry->o.z + ry->d.z * scene->camera.dof_focaldist;
   402   jxy[0] *= scene->camera.dof_aperture_rad;
   403   jxy[1] *= scene->camera.dof_aperture_rad;
   405   ry->o.x += jxy[0] * scene->camera.rightvec.x +
   406              jxy[1] * scene->camera.upvec.x;
   407   ry->o.y += jxy[0] * scene->camera.rightvec.y +
   408              jxy[1] * scene->camera.upvec.y;
   409   ry->o.z += jxy[0] * scene->camera.rightvec.z +
   410              jxy[1] * scene->camera.upvec.z;
   413   ry->d.x = focuspoint.x - ry->o.x;
   414   ry->d.y = focuspoint.y - ry->o.y;
   415   ry->d.z = focuspoint.z - ry->o.z;
   423   ry->flags = RT_RAY_PRIMARY | RT_RAY_REGULAR;  
   427   col=scene->shader(ry);       
   442   scenedef * scene=ry->scene;
   444 #if defined(RT_ACCUMULATE_ON)   445   col.r = col.g = col.b = 0.0f;
   454 #if defined(RT_ACCUMULATE_ON)   455   for (alias=0; alias <= scene->antialiasing; alias++) {
   457   for (alias=1; alias <= scene->antialiasing; alias++) {
   469   scale = 1.0f / (scene->antialiasing + 1.0f); 
   483   flt rdx, rdy, rdz, len;
   484   scenedef * scene=ry->scene;
   490   rdx = scene->camera.lowleft.x + 
   491                 (x * scene->camera.iplaneright.x) + 
   492                 (y * scene->camera.iplaneup.x);
   494   rdy = scene->camera.lowleft.y + 
   495                 (x * scene->camera.iplaneright.y) + 
   496                 (y * scene->camera.iplaneup.y);
   498   rdz = scene->camera.lowleft.z + 
   499                 (x * scene->camera.iplaneright.z) + 
   500                 (y * scene->camera.iplaneup.z);
   503   len = 1.0 / 
SQRT(rdx*rdx + rdy*rdy + rdz*rdz);
   513   ry->flags = RT_RAY_PRIMARY | RT_RAY_REGULAR;  
   524   scenedef * scene=ry->scene;
   527   return scene->shader(ry);    
   539   scenedef * scene=ry->scene;
   547   for (alias=1; alias <= scene->antialiasing; alias++) {
   558   scale = 1.0f / (scene->antialiasing + 1.0f); 
   576   scenedef * scene=ry->scene;
   581   ry->o.x = scene->camera.lowleft.x +
   582                 (x * scene->camera.iplaneright.x) +
   583                 (y * scene->camera.iplaneup.x);
   585   ry->o.y = scene->camera.lowleft.y +
   586                 (x * scene->camera.iplaneright.y) +
   587                 (y * scene->camera.iplaneup.y);
   589   ry->o.z = scene->camera.lowleft.z +
   590                 (x * scene->camera.iplaneright.z) +
   591                 (y * scene->camera.iplaneup.z);
   594   focuspoint.x = ry->o.x + ry->d.x * scene->camera.dof_focaldist;
   595   focuspoint.y = ry->o.y + ry->d.y * scene->camera.dof_focaldist;
   596   focuspoint.z = ry->o.z + ry->d.z * scene->camera.dof_focaldist;
   600   jxy[0] *= scene->camera.dof_aperture_rad;
   601   jxy[1] *= scene->camera.dof_aperture_rad;
   603   ry->o.x += jxy[0] * scene->camera.rightvec.x +
   604              jxy[1] * scene->camera.upvec.x;
   605   ry->o.y += jxy[0] * scene->camera.rightvec.y +
   606              jxy[1] * scene->camera.upvec.y;
   607   ry->o.z += jxy[0] * scene->camera.rightvec.z +
   608              jxy[1] * scene->camera.upvec.z;
   611   ry->d.x = focuspoint.x - ry->o.x;
   612   ry->d.y = focuspoint.y - ry->o.y;
   613   ry->d.z = focuspoint.z - ry->o.z;
   621   ry->flags = RT_RAY_PRIMARY | RT_RAY_REGULAR;  
   625   col=scene->shader(ry);       
   641   scenedef * scene=ry->scene;
   649   for (alias=1; alias <= scene->antialiasing; alias++) {
   660   scale = 1.0f / (scene->antialiasing + 1.0f); 
   674   scenedef * scene=ry->scene;
   679   ry->o.x = scene->camera.lowleft.x + 
   680                 (x * scene->camera.iplaneright.x) + 
   681                 (y * scene->camera.iplaneup.x);
   683   ry->o.y = scene->camera.lowleft.y + 
   684                 (x * scene->camera.iplaneright.y) + 
   685                 (y * scene->camera.iplaneup.y);
   687   ry->o.z = scene->camera.lowleft.z + 
   688                 (x * scene->camera.iplaneright.z) + 
   689                 (y * scene->camera.iplaneup.z);
   696   ry->flags = RT_RAY_PRIMARY | RT_RAY_REGULAR;  
   700   return scene->shader(ry);    
   709   flt sin_ax, cos_ax, sin_ay, cos_ay;
   710   flt rdx, rdy, rdz, invlen;
   711   scenedef * scene=ry->scene;
   714   flt mx = scene->hres * 0.5; 
   715   flt my = scene->vres * 0.5; 
   718   flt radperpix_x = (3.1415926 / scene->hres) * 2.0;
   719   flt radperpix_y = (3.1415926 / scene->vres);
   722   flt ax = (x - mx) * radperpix_x; 
   723   flt ay = (y - my) * radperpix_y; 
   725   SINCOS(ax, &sin_ax, &cos_ax);
   726   SINCOS(ay, &sin_ay, &cos_ay);
   730   rdx = cos_ay * (cos_ax * scene->camera.viewvec.x + 
   731                   sin_ax * scene->camera.rightvec.x) +
   732                   sin_ay * scene->camera.upvec.x;
   734   rdy = cos_ay * (cos_ax * scene->camera.viewvec.y +
   735                   sin_ax * scene->camera.rightvec.y) +
   736                   sin_ay * scene->camera.upvec.y;
   738   rdz = cos_ay * (cos_ax * scene->camera.viewvec.z +
   739                   sin_ax * scene->camera.rightvec.z) +
   740                   sin_ay * scene->camera.upvec.z;
   743   invlen = 1.0 / 
SQRT(rdx*rdx + rdy*rdy + rdz*rdz);
   744   ry->d.x = rdx * invlen;
   745   ry->d.y = rdy * invlen;
   746   ry->d.z = rdz * invlen;
   748   ry->o.x = scene->camera.center.x;
   749   ry->o.y = scene->camera.center.y;
   750   ry->o.z = scene->camera.center.z;
   757   ry->flags = RT_RAY_PRIMARY | RT_RAY_REGULAR;  
   761   return scene->shader(ry);    
   772   scenedef * scene=ry->scene;
   780   for (alias=1; alias <= scene->antialiasing; alias++) {
   791   scale = 1.0f / (scene->antialiasing + 1.0f); 
   809   flt sin_ax, cos_ax, sin_ay, cos_ay;   
   812   flt vpx, vpy, eyeshift;        
   814   scenedef * scene=ry->scene;    
   817   flt vpszy = scene->vres * 0.5; 
   821     eyeshift = -scene->camera.eyeshift;    
   824     eyeshift = scene->camera.eyeshift;     
   828   flt mx = scene->hres * 0.5; 
   829   flt my = vpszy * 0.5;       
   832   flt radperpix_x = (3.1415926 / scene->hres) * 2.0;
   833   flt radperpix_y = (3.1415926 / vpszy);
   836   flt ax = (vpx - mx) * radperpix_x;   
   837   flt ay = (vpy - my) * radperpix_y;   
   839   SINCOS(ax, &sin_ax, &cos_ax);
   840   SINCOS(ay, &sin_ay, &cos_ay);
   844   rdx = cos_ay * (cos_ax * scene->camera.viewvec.x + 
   845                   sin_ax * scene->camera.rightvec.x) +
   846                   sin_ay * scene->camera.upvec.x;
   848   rdy = cos_ay * (cos_ax * scene->camera.viewvec.y +
   849                   sin_ax * scene->camera.rightvec.y) +
   850                   sin_ay * scene->camera.upvec.y;
   852   rdz = cos_ay * (cos_ax * scene->camera.viewvec.z +
   853                   sin_ax * scene->camera.rightvec.z) +
   854                   sin_ay * scene->camera.upvec.z;
   858   invlen = 1.0 / 
SQRT(rdx*rdx + rdy*rdy + rdz*rdz);
   859   ry->d.x = rdx * invlen;
   860   ry->d.y = rdy * invlen;
   861   ry->d.z = rdz * invlen;
   865   VCross(&scene->camera.upvec, &ry->d, &eye_axial);
   869   if (scene->camera.modulate_eyeshift) {
   871     eyeshift *= powf(
fabsf(cos_ay), scene->camera.modulate_eyeshift_pow);
   876   ry->o.x = scene->camera.center.x + eyeshift * eye_axial.x;
   877   ry->o.y = scene->camera.center.y + eyeshift * eye_axial.y;
   878   ry->o.z = scene->camera.center.z + eyeshift * eye_axial.z;
   885   ry->flags = RT_RAY_PRIMARY | RT_RAY_REGULAR;  
   889   return scene->shader(ry);    
   904   scenedef * scene=ry->scene;
   912   for (alias=1; alias <= scene->antialiasing; alias++) {
   923   scale = 1.0f / (scene->antialiasing + 1.0f); 
   938   scenedef * scene=ry->scene;
   940   ax = scene->camera.left   + x * scene->camera.psx;
   941   ay = scene->camera.bottom + y * scene->camera.psy;
   943   ry->d.x = 
COS(ay) * (
COS(ax) * scene->camera.viewvec.x + 
   944                        SIN(ax) * scene->camera.rightvec.x) +
   945             SIN(ay) * scene->camera.upvec.x;
   947   ry->d.y = 
COS(ay) * (
COS(ax) * scene->camera.viewvec.y +
   948                        SIN(ax) * scene->camera.rightvec.y) +
   949             SIN(ay) * scene->camera.upvec.y;
   951   ry->d.z = 
COS(ay) * (
COS(ax) * scene->camera.viewvec.z +
   952                        SIN(ax) * scene->camera.rightvec.z) +
   953             SIN(ay) * scene->camera.upvec.z;
   960   ry->flags = RT_RAY_PRIMARY | RT_RAY_REGULAR;  
   964   return scene->shader(ry);    
   975   scenedef * scene=ry->scene;
   983   for (alias=1; alias <= scene->antialiasing; alias++) {
   994   scale = 1.0f / (scene->antialiasing + 1.0f); 
  1004   camera->projection=mode;    
  1016   camera->frustumcalc = RT_CAMERA_FRUSTUM_USER;
  1017   camera->left = left;    
  1018   camera->right = right;    
  1019   camera->bottom = bottom;    
  1025   camera->dof_focaldist=focaldist;    
  1030   if (aperture < 0.01)
  1033   camera->dof_aperture_rad=focaldist / aperture;
  1042   camera->frustumcalc = RT_CAMERA_FRUSTUM_AUTO;
  1043   camera->camzoom = zoom;
  1051   camera->dof_focaldist = 1.0;
  1052   camera->dof_aperture_rad = 0.0;
  1063   VCross(&upvec, &viewvec, &newrightvec);
  1064   VNorm(&newrightvec);
  1066   VCross(&viewvec, &newrightvec, &newupvec);
  1072   camera->center=center;
  1073   camera->viewvec=newviewvec;
  1074   camera->rightvec=newrightvec;
  1075   camera->upvec=newupvec;
  1080                        vector * upvec, vector * rightvec) {
  1081   *center = camera->center;
  1082   *viewvec = camera->viewvec;
  1083   *upvec = camera->upvec;
  1084   *rightvec = camera->rightvec;
 color cam_equirectangular_stereo_ray(ray *ry, flt x, flt y)
 
static __device__ __inline__ void jitter_offset2f(unsigned int &pval, float2 &xy)
 
color cam_equirectangular_aa_ray(ray *ry, flt x, flt y)
 
color cam_orthographic_aa_dof_ray(ray *ry, flt x, flt y)
 
color cam_perspective_dof_ray(ray *ry, flt x, flt y)
 
void cameradefault(camdef *camera)
 
void rng_frand_seed(rng_frand_handle *rngh, unsigned int seed)
 
color cam_perspective_aa_ray(ray *ry, flt x, flt y)
 
color cam_equirectangular_aa_stereo_ray(ray *ry, flt x, flt y)
 
__host__ __device__ float3 fabsf(const float3 &a)
 
color cam_equirectangular_ray(ray *ry, flt x, flt y)
 
color cam_perspective_aa_dof_ray(ray *ry, flt x, flt y)
 
color cam_orthographic_ray(ray *ry, flt x, flt y)
 
#define RT_PROJECTION_FISHEYE
Fisheye projection mode. 
 
static __device__ __inline__ void jitter_disc2f(unsigned int &pval, float2 &xy, float radius)
 
#define RT_PROJECTION_STEREO_EQUIRECTANGULAR
over/under omnistereo equirectangular 
 
void cameraprojection(camdef *camera, int mode)
 
double flt
generic floating point number, using double 
 
void camerazoom(camdef *camera, flt zoom)
 
void VCross(apivector *a, apivector *b, apivector *c)
 
#define RT_PROJECTION_PERSPECTIVE
Perspective projection mode. 
 
color cam_fisheye_ray(ray *ry, flt x, flt y)
 
void add_clipped_intersection(flt t, const object *obj, ray *ry)
 
Tachyon cross-platform timers, special math function wrappers, and RNGs. 
 
void cameradof(camdef *camera, flt focaldist, flt aperture)
 
color cam_orthographic_aa_ray(ray *ry, flt x, flt y)
 
color cam_fisheye_aa_ray(ray *ry, flt x, flt y)
 
void camera_init(scenedef *scene)
 
#define SINCOS(ax, sx, cx)
 
void cam_prep_perspective_ray(ray *ry, flt x, flt y)
 
#define RT_PROJECTION_PERSPECTIVE_DOF
Perspective projection mode. 
 
void camray_init(scenedef *scene, ray *primary, unsigned long serial, unsigned long *mbox, unsigned int aarandval, unsigned int aorandval)
 
void getcameraposition(camdef *camera, vector *center, vector *viewvec, vector *upvec, vector *rightvec)
 
color cam_perspective_ray(ray *ry, flt x, flt y)
 
void add_regular_intersection(flt t, const object *obj, ray *ry)
 
void cameraposition(camdef *camera, vector center, vector viewvec, vector upvec)
 
#define RT_PROJECTION_ORTHOGRAPHIC
Orthographic projection mode. 
 
Tachyon public API function prototypes and declarations used to drive the ray tracing engine...
 
color cam_orthographic_dof_ray(ray *ry, flt x, flt y)
 
#define RT_PROJECTION_ORTHOGRAPHIC_DOF
Orthographic projection mode. 
 
void rng_frand_init(rng_frand_handle *rngh)
 
void intersect_objects(ray *ry)
 
void camerafrustum(camdef *camera, flt left, flt right, flt bottom, flt top)
When the user directly specifies the world coordinates of the view frustum, it overrides the normal c...