Fixed reflections on bvh tree
authorAndre Susano Pinto <andresusanopinto@gmail.com>
Fri, 5 Jun 2009 14:44:54 +0000 (14:44 +0000)
committerAndre Susano Pinto <andresusanopinto@gmail.com>
Fri, 5 Jun 2009 14:44:54 +0000 (14:44 +0000)
 (its kinda of a hackish-fix.. must be improved later)

source/blender/render/intern/source/rayobject.c
source/blender/render/intern/source/rayobject_bvh.c
source/blender/render/intern/source/rayshade.c

index ecc74f9c11c7b0a01354d1fe2fe370800ed24939..e622dd971eefa7d5c7ff5eab5fb614af93588efd 100644 (file)
@@ -273,12 +273,12 @@ int RE_rayobject_raycast(RayObject *r, Isect *i)
        if(casted_rays++ % (1<<20) == 0)
                printf("Casting %d rays\n", casted_rays);
 
-/*     i->vec[0] *= i->labda;
+       i->labda = 10000.0;
+       i->vec[0] *= i->labda;
        i->vec[1] *= i->labda;
        i->vec[2] *= i->labda;
        i->labda = 1.0f;
-*/
-//     i->dist = VecLength(i->vec);
+       i->dist = VecLength(i->vec);
        
        if(i->mode==RE_RAY_SHADOW && i->last_hit && RE_rayobject_intersect(i->last_hit, i))
                return 1;
index aa36bc440108ad4dd24dba46d1e13301283d1180..232b221fbdbf131143b29a3a0d732f591ecdbda1 100644 (file)
@@ -55,6 +55,7 @@ typedef struct BVHObject
 {
        RayObject rayobj;
        BVHTree *bvh;
+       float bb[2][3];
 
 } BVHObject;
 
@@ -65,36 +66,42 @@ RayObject *RE_rayobject_bvh_create(int size)
        assert( RayObject_isAligned(obj) ); /* RayObject API assumes real data to be 4-byte aligned */  
        
        obj->rayobj.api = &bvh_api;
-       obj->bvh = BLI_bvhtree_new(size, 0.0, 2, 6);
+       obj->bvh = BLI_bvhtree_new(size, FLT_EPSILON, 2, 6);
        
+       INIT_MINMAX(obj->bb[0], obj->bb[1]);
        return RayObject_unalign((RayObject*) obj);
 }
 
 static void bvh_callback(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
 {
-       Isect *isect = (Isect*)userdata;
+       Isect *isec = (Isect*)userdata;
        RayObject *face = (RayObject*)index;
        
-       if(RE_rayobject_intersect(face,isect))
+       if(RE_rayobject_intersect(face,isec))
        {
                hit->index = index;
 
-               if(isect->mode == RE_RAY_SHADOW)
+               if(isec->mode == RE_RAY_SHADOW)
                        hit->dist = 0;
+//             TODO
+//             else
+//                     hit->dist = isec->labda;
        }
 }
 
 static int  RayObject_bvh_intersect(RayObject *o, Isect *isec)
 {
        BVHObject *obj = (BVHObject*)o;
-//     float dir[3];
-//     VECCOPY( dir, isec->vec );
-//     Normalize( dir );
        BVHTreeRayHit hit;
+       float dir[3];
+
+       VECCOPY(dir, isec->vec);
+       Normalize(dir);
+
        hit.index = 0;
-       hit.dist = isec->labda*isec->dist;
+       hit.dist = FLT_MAX; //TODO isec->labda;
        
-       return BLI_bvhtree_ray_cast(obj->bvh, isec->start, isec->vec, 0.0, &hit, bvh_callback, isec) != 0;
+       return BLI_bvhtree_ray_cast(obj->bvh, isec->start, dir, 0.0, &hit, bvh_callback, isec);
 }
 
 static void RayObject_bvh_add(RayObject *o, RayObject *ob)
@@ -102,8 +109,12 @@ static void RayObject_bvh_add(RayObject *o, RayObject *ob)
        BVHObject *obj = (BVHObject*)o;
        float min_max[6];
        INIT_MINMAX(min_max, min_max+3);
-       RE_rayobject_merge_bb(ob, min_max, min_max+3);  
-       BLI_bvhtree_insert(obj->bvh, (int)ob, min_max, 2 );
+       RE_rayobject_merge_bb(ob, min_max, min_max+3);
+
+       DO_MINMAX(min_max  , obj->bb[0], obj->bb[1]);
+       DO_MINMAX(min_max+3, obj->bb[0], obj->bb[1]);
+       
+       BLI_bvhtree_insert(obj->bvh, (int)ob, min_max, 2 );     
 }
 
 static void RayObject_bvh_done(RayObject *o)
@@ -124,5 +135,7 @@ static void RayObject_bvh_free(RayObject *o)
 
 static void RayObject_bvh_bb(RayObject *o, float *min, float *max)
 {
-       assert(0);
+       BVHObject *obj = (BVHObject*)o;
+       DO_MINMAX( obj->bb[0], min, max );
+       DO_MINMAX( obj->bb[1], min, max );
 }
index b0515e1742473fe6b36104c64b34028e5429a152..2eb545f7364aff16803c688a68473495e11564d8 100644 (file)
@@ -146,8 +146,8 @@ void makeraytree(Render *re)
        }
        
        printf("RE_rayobject_*_create( %d )\n", totface);
-       re->raytree = RE_rayobject_octree_create( re->r.ocres, totface );
-//     re->raytree = RE_rayobject_bvh_create( totface );
+//     re->raytree = RE_rayobject_octree_create( re->r.ocres, totface );
+       re->raytree = RE_rayobject_bvh_create( totface );
        
        //Fill rayfaces
        re->rayfaces = (RayObject*)MEM_callocN(totface*sizeof(RayFace), "render faces");
@@ -433,6 +433,7 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, flo
        VECCOPY(isec.vec, vec );
        isec.labda = dist_mir > 0 ? dist_mir : RE_RAYTRACE_MAXDIST;
        isec.mode= RE_RAY_MIRROR;
+       isec.skip = RE_SKIP_VLR_NEIGHBOUR;
 
        isec.orig.ob   = obi;
        isec.orig.face = vlr;