*enabled mirror rays again
authorAndre Susano Pinto <andresusanopinto@gmail.com>
Wed, 3 Jun 2009 23:56:04 +0000 (23:56 +0000)
committerAndre Susano Pinto <andresusanopinto@gmail.com>
Wed, 3 Jun 2009 23:56:04 +0000 (23:56 +0000)
*octree is fine
*bvh tree gives bad results

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

index be247d0d86b8db08a004616010f2dd545b0b056f..ecc74f9c11c7b0a01354d1fe2fe370800ed24939 100644 (file)
@@ -250,16 +250,9 @@ static int intersect_rayface(RayFace *face, Isect *is)
                }
 #endif
 
-/*
-               TODO
-               if(is->mode!=RE_RAY_SHADOW) {
-                       / * for mirror & tra-shadow: large faces can be filled in too often, this prevents
-                          a face being detected too soon... * /
-                       if(is->labda > is->ddalabda) {
-                               return 0;
-                       }
-               }
-*/             
+               if(is->mode!=RE_RAY_SHADOW && labda > is->labda)
+                       return 0;
+
                is->isect= ok;  // wich half of the quad
                is->labda= labda;
                is->u= u; is->v= v;
@@ -280,14 +273,13 @@ 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->vec[0] *= i->labda;
        i->vec[1] *= i->labda;
        i->vec[2] *= i->labda;
-       i->labda = 1.0f; //RE_RAYTRACE_MAXDIST; //len;
-       i->dist = VecLength(i->vec);
+       i->labda = 1.0f;
+*/
+//     i->dist = VecLength(i->vec);
        
-               
-       assert(i->mode==RE_RAY_SHADOW);
        if(i->mode==RE_RAY_SHADOW && i->last_hit && RE_rayobject_intersect(i->last_hit, i))
                return 1;
 
index dc4669fa084170c118a7b2f76846b028d5bdb766..018c7735284e4b4c305c10b313fbf8f4dcbb901b 100644 (file)
@@ -664,7 +664,7 @@ static int testnode(Octree *oc, Isect *is, Node *no, OcVal ocval)
                        RayObject *face = no->v[nr];
                        OcVal           *ov = no->ov+nr;
                        
-                       if(!face) break; //TODO? return 0;
+                       if(!face) break;
                        
                        if( (ov->ocx & ocval.ocx) && (ov->ocy & ocval.ocy) && (ov->ocz & ocval.ocz) )
                        {
@@ -675,30 +675,20 @@ static int testnode(Octree *oc, Isect *is, Node *no, OcVal ocval)
        }
        else
        {                       /* else mirror or glass or shadowtra, return closest face  */
-               Isect isect;
                int found= 0;
                
-               assert(0);
-               
-               is->labda= 1.0f;        /* needed? */
-               isect= *is;                     /* copy for sorting */
-               
                for(; no; no = no->next)
                for(nr=0; nr<8; nr++)
                {
                        RayObject *face = no->v[nr];
                        OcVal           *ov = no->ov+nr;
                        
-                       if(!face) return 0;
+                       if(!face) break;
                        
                        if( (ov->ocx & ocval.ocx) && (ov->ocy & ocval.ocy) && (ov->ocz & ocval.ocz) )
                        { 
-
                                if( RE_rayobject_intersect(face,is) )
-                                       if(isect.labda<is->labda) {
-                                               *is= isect;
-                                               found= 1;
-                                       }
+                                       found= 1;
                        }
                }
                
@@ -848,22 +838,6 @@ static int RayObject_octree_intersect(RayObject *tree, Isect *is)
        is->userdata= oc->userdata;
 #endif
 
-#if 0
-       /* only for shadow! */
-       if(is->mode==RE_RAY_SHADOW) {
-       
-               /* TODO check with last intersected shadow face */
-               if(is->last.face!=NULL && !(is->last.face==is->orig.face && is->last.ob==is->orig.ob)) {
-                       if(checkfunc(is, is->last.ob, is->last.face)) {
-                               is->ob= is->last.ob;
-                               is->face= is->last.face;
-                               VECSUB(is->vec, is->end, is->start);
-                               if(RE_ray_face_intersection(is, oc->transformfunc, oc->coordsfunc)) return 1;
-                       }
-               }
-       }
-#endif
-       
        VECADDFAC( end, is->start, is->vec, is->labda );
        ldx= end[0] - is->start[0];
        u1= 0.0f;
@@ -880,6 +854,10 @@ static int RayObject_octree_intersect(RayObject *tree, Isect *is)
                                                if(cliptest(ldz, oc->max[2]-is->start[2], &u1,&u2)) {
                                                        c1=1;
                                                        if(u2<1.0f) {
+                                                               is->vec[0] = u2*ldx;
+                                                               is->vec[1] = u2*ldy;
+                                                               is->vec[2] = u2*ldz;
+
                                                                end[0]= is->start[0]+u2*ldx;
                                                                end[1]= is->start[1]+u2*ldy;
                                                                end[2]= is->start[2]+u2*ldz;
@@ -917,16 +895,6 @@ static int RayObject_octree_intersect(RayObject *tree, Isect *is)
        ocy2= (int)oy2;
        ocz2= (int)oz2;
        
-//     for(ocx1=0; ocx1<oc->ocres; ocx1++)
-//     for(ocy1=0; ocy1<oc->ocres; ocy1++)
-//     for(ocz1=0; ocz1<oc->ocres; ocz1++)
-//     {
-//             no= ocread(oc, ocx1, ocy1, ocz1);
-//             if( testnode(oc, is, no, ocval) ) return 1;
-//     }
-
-//     return 0;
-
        if(ocx1==ocx2 && ocy1==ocy2 && ocz1==ocz2) {
                no= ocread(oc, ocx1, ocy1, ocz1);
                if(no) {
@@ -934,7 +902,7 @@ static int RayObject_octree_intersect(RayObject *tree, Isect *is)
                        vec1[0]= ox1; vec1[1]= oy1; vec1[2]= oz1;
                        vec2[0]= ox2; vec2[1]= oy2; vec2[2]= oz2;
                        calc_ocval_ray(&ocval, (float)ocx1, (float)ocy1, (float)ocz1, vec1, vec2);
-//                     is->ddalabda= 1.0f;
+                       is->labda = 1.0f;
                        if( testnode(oc, is, no, ocval) ) return 1;
                }
        }
@@ -1012,8 +980,8 @@ static int RayObject_octree_intersect(RayObject *tree, Isect *is)
                                vec2[1]= oy1-ddalabda*doy;
                                vec2[2]= oz1-ddalabda*doz;
                                calc_ocval_ray(&ocval, (float)xo, (float)yo, (float)zo, vec1, vec2);
-                                                          
-//                             is->ddalabda= ddalabda;
+
+                               is->labda= ddalabda;
                                if( testnode(oc, is, no, ocval) ) return 1;
                        }
 
index 9bc1d5e75ce8e70d7fb84c15ec97f38069dbf731..b0515e1742473fe6b36104c64b34028e5429a152 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");
@@ -424,8 +424,6 @@ static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, flo
        float ref[3];
        float dist_mir = origshi->mat->dist_mir;
 
-       assert(0);
-
        /* Warning, This is not that nice, and possibly a bit slow for every ray,
        however some variables were not initialized properly in, unless using shade_input_initialize(...), we need to do a memset */
        memset(&shi, 0, sizeof(ShadeInput));