Revision: 21442
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21442
Author:   jaguarandi
Date:     2009-07-08 23:56:24 +0200 (Wed, 08 Jul 2009)

Log Message:
-----------
*set cost of transversing a BVH as log(size)

Modified Paths:
--------------
    
branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_bvh.c
    
branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_rtbuild.c

Modified: 
branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_bvh.c
===================================================================
--- 
branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_bvh.c
    2009-07-08 21:41:35 UTC (rev 21441)
+++ 
branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_bvh.c
    2009-07-08 21:56:24 UTC (rev 21442)
@@ -28,6 +28,7 @@
  */
 #include <assert.h>
 #include <stdio.h>
+#include <math.h>
 
 #include "MEM_guardedalloc.h"
 #include "BKE_utildefines.h"
@@ -37,6 +38,7 @@
 #include "rayobject_rtbuild.h"
 #include "rayobject.h"
 
+#define RAY_BB_TEST_COST (0.2f)
 #define DFS_STACK_SIZE 64
 #define DYNAMIC_ALLOC
 
@@ -371,7 +373,7 @@
                        for(; i<BVH_NCHILDS; i++)
                                parent->child[i] = 0;
 
-                       *cost = bb_area(parent->bb, 
parent->bb+3)*RE_rayobject_cost(child);
+                       *cost = RE_rayobject_cost(child)+RAY_BB_TEST_COST;
                        return parent;
                }
                else
@@ -414,7 +416,8 @@
                for(; i<BVH_NCHILDS; i++)
                        parent->child[i] = 0;
 
-               *cost *= bb_area(parent->bb, parent->bb+3);
+               *cost /= nc*bb_area(parent->bb, parent->bb+3);
+               *cost += RAY_BB_TEST_COST;
                return parent;
        }
 }
@@ -454,6 +457,8 @@
 #endif
        
        obj->root = bvh_rearrange( obj, obj->builder, 1, &obj->cost );
+//     obj->cost = 1.0;
+       obj->cost = logf( rtbuild_size( obj->builder ) );
        
 #ifndef DYNAMIC_ALLOC
        assert(obj->node_alloc+needed_nodes >= obj->node_next);

Modified: 
branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_rtbuild.c
===================================================================
--- 
branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_rtbuild.c
        2009-07-08 21:41:35 UTC (rev 21441)
+++ 
branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_rtbuild.c
        2009-07-08 21:56:24 UTC (rev 21442)
@@ -280,7 +280,7 @@
        {
                float bcost = FLT_MAX;
                float childrens_cost = 0;
-               int i, axis, baxis, boffset, k, try_axis[3];
+               int i, axis, baxis = -1, boffset = size/2, k, try_axis[3];
                CostObject *cost   = MEM_mallocN( sizeof(CostObject)*size, 
"RTBuilder.HeuristicObjectSplitter" );
                float      *acc_bb = MEM_mallocN( sizeof(float)*6*size, 
"RTBuilder.HeuristicObjectSplitterBB" );
 
@@ -346,8 +346,8 @@
                                //Worst case heuristic (cost of each child is 
linear)
                                float hcost, left_side, right_side;
                                
-                               left_side = bb_area(other_bb, 
other_bb+3)*left_cost;            //(i+logf(i));
-                               right_side= bb_area(acc_bb+i*6, 
acc_bb+i*6+3)*right_cost;       //(size-i+logf(size-i));
+                               left_side = bb_area(other_bb, 
other_bb+3)*(left_cost+logf(i));
+                               right_side= bb_area(acc_bb+i*6, 
acc_bb+i*6+3)*(right_cost+logf(i));
                                
                                if(left_side > bcost) break;    //No way we can 
find a better heuristic in this axis
 
@@ -373,6 +373,8 @@
                                        b->begin[i] = cost[i].obj;
                                b->child_sorted_axis = axis;
                        }
+                       
+                       assert(baxis >= 0 && baxis < 3);
                }
                        
                b->child_offset[0] = 0;


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to