*set cost of transversing a BVH as log(size)
This commit is contained in:
@@ -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 @@ static BVHNode *bvh_rearrange(BVHTree *tree, RTBuilder *builder, int nid, float
|
||||
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 @@ static BVHNode *bvh_rearrange(BVHTree *tree, RTBuilder *builder, int nid, float
|
||||
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 @@ static void bvh_done(BVHTree *obj)
|
||||
#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);
|
||||
|
||||
@@ -280,7 +280,7 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds)
|
||||
{
|
||||
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 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds)
|
||||
//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 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds)
|
||||
b->begin[i] = cost[i].obj;
|
||||
b->child_sorted_axis = axis;
|
||||
}
|
||||
|
||||
assert(baxis >= 0 && baxis < 3);
|
||||
}
|
||||
|
||||
b->child_offset[0] = 0;
|
||||
|
||||
Reference in New Issue
Block a user