Subversion Repositories gelsvn

Rev

Rev 430 | Rev 451 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 430 Rev 438
Line 167... Line 167...
167
      BBox left_bbox = bbox;
167
      BBox left_bbox = bbox;
168
      BBox right_bbox = bbox;
168
      BBox right_bbox = bbox;
169
 
169
 
170
      double size = bbox.max_corner[node.axis_leaf]- bbox.min_corner[node.axis_leaf];
170
      double size = bbox.max_corner[node.axis_leaf]- bbox.min_corner[node.axis_leaf];
171
      double center = size*(double)new_pos/(double)TESTS + bbox.min_corner[node.axis_leaf];
171
      double center = size*(double)new_pos/(double)TESTS + bbox.min_corner[node.axis_leaf];
172
      double diff = f_eps < size/8.0 ? f_eps : size/8.0;
172
      double diff = f_eps < size/8.0 ? size/8.0 : f_eps;
173
      
173
      
174
      if (left_zero) 
174
      if (left_zero) 
175
      {
175
      {
176
        // Find min position of all triangle vertices and place the center there
176
        // Find min position of all triangle vertices and place the center there
177
        center = bbox.max_corner[node.axis_leaf];
177
        center = bbox.max_corner[node.axis_leaf];
Line 360... Line 360...
360
 
360
 
361
/*__declspec(align(16))*/ static const unsigned int modulo[] = {0,1,2,0,1};
361
/*__declspec(align(16))*/ static const unsigned int modulo[] = {0,1,2,0,1};
362
 
362
 
363
  inline bool intersect2(Ray &ray, const TriAccel &acc, double t_max) 
363
  inline bool intersect2(Ray &ray, const TriAccel &acc, double t_max) 
364
  {
364
  {
365
//  cout << "Acc: " << (int)&acc << " ";
-
 
366
//inline bool Intersect(TriAccel &acc,Ray &ray)
365
//inline bool Intersect(TriAccel &acc,Ray &ray)
367
#define ku modulo[acc.k+1]
366
#define ku modulo[acc.k+1]
368
#define kv modulo[acc.k+2]
367
#define kv modulo[acc.k+2]
369
    // don’t prefetch here, assume data has already been prefetched
368
    // don’t prefetch here, assume data has already been prefetched
370
    // start high-latency division as early as possible
369
    // start high-latency division as early as possible
Line 393... Line 392...
393
    return true;
392
    return true;
394
  }
393
  }
395
 
394
 
396
  bool BSPTree::intersect_node(Ray &ray, const BSPNode &node, double t_min, double t_max) const 
395
  bool BSPTree::intersect_node(Ray &ray, const BSPNode &node, double t_min, double t_max) const 
397
  {
396
  {
398
//    cout << node.plane << endl;
-
 
399
    node_calls++;    
397
    node_calls++;    
400
    if (node.axis_leaf==4) 
398
    if (node.axis_leaf==4) 
401
    {
399
    {
402
      bool found = false; 
400
      bool found = false; 
403
      for(int i=0; i < node.count; ++i) 
401
      for(int i=0; i < node.count; ++i) 
404
      {
402
      {
405
//        const TriAccel* tri2 = all_triaccel[node.id+i];
-
 
406
        const ISectTri* tri = all_objects[node.id+i];
403
        const ISectTri* tri = all_objects[node.id+i];
407
//        if (intersect2(ray, *tri2, t_max))  
-
 
408
//          found=true;
-
 
409
        if (intersect(ray, *tri, t_max))  
404
        if (intersect(ray, *tri, t_max))  
410
          found=true;
405
          found=true;
-
 
406
        //const TriAccel* tri2 = all_triaccel[node.id+i];
-
 
407
        //if (intersect2(ray, *tri2, t_max))  
-
 
408
        //  found=true;
411
      }
409
      }
412
      if (found)
410
      if (found)
413
        return true;
411
        return true;
414
      else 
412
      else 
415
        return false;
413
        return false;
Line 455... Line 453...
455
    double t_min, t_max;
453
    double t_min, t_max;
456
    bbox.intersect_min_max(ray, t_min, t_max);
454
    bbox.intersect_min_max(ray, t_min, t_max);
457
    if (t_min>t_max)
455
    if (t_min>t_max)
458
      return false;
456
      return false;
459
 
457
 
460
//    printf("%.2f %.2f %.2f\n", ray.dist, t_min, t_max);
-
 
461
    if (!intersect_node(ray, *root, t_min, t_max))
458
    if (!intersect_node(ray, *root, t_min, t_max))
462
      return false;
459
      return false;
463
//  cout << "____" << endl;
-
 
464
//  ray.reset();
-
 
465
//  cout << "Here " << endl;
-
 
466
//    intersect_fast_node(ray, &fast_tree[0], t_min, t_max);
460
    //intersect_fast_node(ray, &fast_tree[0], t_min, t_max);
467
    //  if (!ray.has_hit)
461
    //if (!ray.has_hit)
468
    //return false;
462
    //  return false;
469
    else 
463
    else 
470
    {
464
    {
471
      //printf("HIT\n");
-
 
472
 
-
 
473
      // Calculate the normal at the intersection
465
      // Calculate the normal at the intersection
474
      ray.id = reinterpret_cast<int>(ray.hit_object);
466
      ray.id = reinterpret_cast<int>(ray.hit_object);
475
      ray.hit_object = trimesh[ray.id];
467
      ray.hit_object = trimesh[ray.id];
476
      
468
      
477
      Vec3i face = ray.hit_object->normals.face(ray.hit_face_id);
469
      Vec3i face = ray.hit_object->normals.face(ray.hit_face_id);
Line 539... Line 531...
539
#define ABSP_ISLEAF(n)       (n->inner.flagAndOffset & (unsigned int)1<<31)
531
#define ABSP_ISLEAF(n)       (n->inner.flagAndOffset & (unsigned int)1<<31)
540
#define ABSP_DIMENSION(n)    (n->inner.flagAndOffset & 0x3)
532
#define ABSP_DIMENSION(n)    (n->inner.flagAndOffset & 0x3)
541
#define ABSP_OFFSET(n)       (n->inner.flagAndOffset & (0x7FFFFFFC))
533
#define ABSP_OFFSET(n)       (n->inner.flagAndOffset & (0x7FFFFFFC))
542
#define ABSP_NEARNODE(n)     (FastBSPNode*)(ray.direction[dimension]>=0?ABSP_OFFSET(node):ABSP_OFFSET(node)+sizeof(*node))
534
#define ABSP_NEARNODE(n)     (FastBSPNode*)(ray.direction[dimension]>=0?ABSP_OFFSET(node):ABSP_OFFSET(node)+sizeof(*node))
543
#define ABSP_FARNODE(n)      (FastBSPNode*)(ray.direction[dimension]>=0?ABSP_OFFSET(node)+sizeof(*node):ABSP_OFFSET(node))
535
#define ABSP_FARNODE(n)      (FastBSPNode*)(ray.direction[dimension]>=0?ABSP_OFFSET(node)+sizeof(*node):ABSP_OFFSET(node))
544
#define ABSP_TRIANGLENODE(n) (vector<TriAccel*>::iterator)(n->flagAndOffset & (0x7FFFFFFF))
-
 
545
  
536
  
546
  struct Stack 
537
  struct Stack 
547
  {
538
  {
548
    FastBSPNode *node;
539
    FastBSPNode *node;
549
    double t_min;
540
    double t_min;
Line 551... Line 542...
551
  };
542
  };
552
 
543
 
553
  inline void IntersectAlltrianglesInLeaf(const BSPLeaf* leaf, Ray &ray, double t_max) {
544
  inline void IntersectAlltrianglesInLeaf(const BSPLeaf* leaf, Ray &ray, double t_max) {
554
    TriAccel** tri_acc_ptr = reinterpret_cast<TriAccel**>(leaf->flagAndOffset & (0x7FFFFFFF));
545
    TriAccel** tri_acc_ptr = reinterpret_cast<TriAccel**>(leaf->flagAndOffset & (0x7FFFFFFF));
555
    vector<TriAccel*>::iterator acc = vector<TriAccel*>::iterator(tri_acc_ptr);
546
    vector<TriAccel*>::iterator acc = vector<TriAccel*>::iterator(tri_acc_ptr);
556
//  vector<TriAccel*>::iterator acc = ABSP_TRIANGLENODE(leaf);
-
 
557
    for(unsigned int i=0;i<leaf->count;++i)
547
    for(unsigned int i=0;i<leaf->count;++i)
558
      intersect2(ray, *(*acc++), t_max);
548
      intersect2(ray, *(*acc++), t_max);
559
  }
549
  }
560
 
550
 
561
  void BSPTree::intersect_fast_node(Ray &ray, const FastBSPNode *node, double t_min, double t_max) const 
551
  void BSPTree::intersect_fast_node(Ray &ray, const FastBSPNode *node, double t_min, double t_max) const