diff options
author | Andre Susano Pinto <andresusanopinto@gmail.com> | 2009-08-26 00:26:50 +0400 |
---|---|---|
committer | Andre Susano Pinto <andresusanopinto@gmail.com> | 2009-08-26 00:26:50 +0400 |
commit | aec7f2f2c47d02b08383a4f30c0dd0067830b8c8 (patch) | |
tree | dedd13739ee273c5cab9225dc0537e5931045b9b | |
parent | 950b770c1ea0c05a907abc93ad7174a02432843f (diff) |
*Changed RayObject_ calls to RE_rayobject to keep consistency on calls
*Moved part of counters code to a separated file (rayobject_raycounter.c)
12 files changed, 196 insertions, 268 deletions
diff --git a/source/blender/render/intern/include/rayobject.h b/source/blender/render/intern/include/rayobject.h index b058f260052..36b0d2692c0 100644 --- a/source/blender/render/intern/include/rayobject.h +++ b/source/blender/render/intern/include/rayobject.h @@ -77,39 +77,16 @@ extern "C" { described on RE_raytrace.h */ -/* defines where coordinates of rayface primitives are stored */ -#define RE_RAYFACE_COORDS_LOCAL - -//(ATM this won't work good with all types of instances) -//#define RE_RAYFACE_COORDS_POINTER -//#define RE_RAYFACE_COORDS_VLAKREN - typedef struct RayFace { -#ifdef RE_RAYFACE_COORDS_LOCAL float v1[4], v2[4], v3[4], v4[3]; int quad; void *ob; void *face; -#elif defined(RE_RAYFACE_COORDS_POINTER) - float *v1, *v2, *v3, *v4; - void *ob; - void *face; -#elif defined(RE_RAYFACE_COORDS_VLAKREN) - void *ob; - void *face; -#endif } RayFace; -#ifdef RE_RAYFACE_COORDS_LOCAL -# define RE_rayface_isQuad(a) ((a)->quad) -#elif defined(RE_RAYFACE_COORDS_POINTER) -# define RE_rayface_isQuad(a) ((a)->v4) -#elif defined(RE_RAYFACE_COORDS_VLAKREN) -# define RE_rayface_isQuad(a) ((((VlakRen*)((a)->face))->v4) != NULL) -#endif - +#define RE_rayface_isQuad(a) ((a)->quad) struct RayObject { @@ -137,13 +114,13 @@ typedef struct RayObjectAPI } RayObjectAPI; -#define RayObject_align(o) ((RayObject*)(((intptr_t)o)&(~3))) -#define RayObject_unalignRayFace(o) ((RayObject*)(((intptr_t)o)|1)) -#define RayObject_unalignRayAPI(o) ((RayObject*)(((intptr_t)o)|2)) +#define RE_rayobject_align(o) ((RayObject*)(((intptr_t)o)&(~3))) +#define RE_rayobject_unalignRayFace(o) ((RayObject*)(((intptr_t)o)|1)) +#define RE_rayobject_unalignRayAPI(o) ((RayObject*)(((intptr_t)o)|2)) -#define RayObject_isAligned(o) ((((intptr_t)o)&3) == 0) -#define RayObject_isRayFace(o) ((((intptr_t)o)&3) == 1) -#define RayObject_isRayAPI(o) ((((intptr_t)o)&3) == 2) +#define RE_rayobject_isAligned(o) ((((intptr_t)o)&3) == 0) +#define RE_rayobject_isRayFace(o) ((((intptr_t)o)&3) == 1) +#define RE_rayobject_isRayAPI(o) ((((intptr_t)o)&3) == 2) /* * Loads a VlakRen on a RayFace diff --git a/source/blender/render/intern/raytrace/bvh.h b/source/blender/render/intern/raytrace/bvh.h index 8538d9201e0..55bed6f0662 100644 --- a/source/blender/render/intern/raytrace/bvh.h +++ b/source/blender/render/intern/raytrace/bvh.h @@ -59,7 +59,7 @@ template<class Tree> static void bvh_add(Tree *obj, RayObject *ob) template<class Node> inline bool is_leaf(Node *node) { - return !RayObject_isAligned(node); + return !RE_rayobject_isAligned(node); } template<class Tree> static void bvh_done(Tree *obj); diff --git a/source/blender/render/intern/raytrace/rayobject_bih.cpp b/source/blender/render/intern/raytrace/rayobject_bih.cpp index 102a347b470..efbf70616b7 100644 --- a/source/blender/render/intern/raytrace/rayobject_bih.cpp +++ b/source/blender/render/intern/raytrace/rayobject_bih.cpp @@ -78,7 +78,7 @@ struct BIHTree RayObject *RE_rayobject_bih_create(int size) { BIHTree *obj= (BIHTree*)MEM_callocN(sizeof(BIHTree), "BIHTree"); - assert( RayObject_isAligned(obj) ); /* RayObject API assumes real data to be 4-byte aligned */ + assert( RE_rayobject_isAligned(obj) ); /* RayObject API assumes real data to be 4-byte aligned */ obj->rayobj.api = &bih_api; obj->root = NULL; @@ -86,7 +86,7 @@ RayObject *RE_rayobject_bih_create(int size) obj->node_alloc = obj->node_next = NULL; obj->builder = rtbuild_create( size ); - return RayObject_unalignRayAPI((RayObject*) obj); + return RE_rayobject_unalignRayAPI((RayObject*) obj); } static void bih_free(BIHTree *obj) @@ -128,7 +128,7 @@ static int dfs_raycast(const BIHNode *const node, Isect *isec, float tmin, float if(t1 <= t2) { - if(RayObject_isAligned(node->child[i])) + if(RE_rayobject_isAligned(node->child[i])) { if(node->child[i] == 0) break; @@ -151,7 +151,7 @@ static int dfs_raycast(const BIHNode *const node, Isect *isec, float tmin, float static int bih_intersect(BIHTree *obj, Isect *isec) { - if(RayObject_isAligned(obj->root)) + if(RE_rayobject_isAligned(obj->root)) return dfs_raycast(obj->root, isec, 0, isec->labda); else return RE_rayobject_intersect( (RayObject*)obj->root, isec); @@ -169,7 +169,7 @@ static void bih_add(BIHTree *obj, RayObject *ob) static BIHNode *bih_new_node(BIHTree *tree, int nid) { BIHNode *node = tree->node_alloc + nid - 1; - assert(RayObject_isAligned(node)); + assert(RE_rayobject_isAligned(node)); if(node+1 > tree->node_next) tree->node_next = node+1; @@ -187,7 +187,7 @@ static BIHNode *bih_rearrange(BIHTree *tree, RTBuilder *builder, int nid, float if(rtbuild_size(builder) == 1) { RayObject *child = rtbuild_get_primitive( builder, 0 ); - assert(!RayObject_isAligned(child)); + assert(!RE_rayobject_isAligned(child)); INIT_MINMAX(bb, bb+3); RE_rayobject_merge_bb( (RayObject*)child, bb, bb+3); diff --git a/source/blender/render/intern/raytrace/rayobject_bvh.cpp b/source/blender/render/intern/raytrace/rayobject_bvh.cpp index 48c1ac07cd4..bf54f889ebf 100644 --- a/source/blender/render/intern/raytrace/rayobject_bvh.cpp +++ b/source/blender/render/intern/raytrace/rayobject_bvh.cpp @@ -117,7 +117,7 @@ static BVHNode *bvh_rearrange(BVHTree *tree, RTBuilder *builder, int nid, float { RayObject *child = rtbuild_get_primitive( builder, 0 ); - if(RayObject_isRayFace(child)) + if(RE_rayobject_isRayFace(child)) { int i; BVHNode *parent = bvh_new_node(tree, nid); @@ -138,7 +138,7 @@ static BVHNode *bvh_rearrange(BVHTree *tree, RTBuilder *builder, int nid, float } else { - assert(!RayObject_isAligned(child)); + assert(!RE_rayobject_isAligned(child)); //Its a sub-raytrace structure, assume it has it own raycast //methods and adding a Bounding Box arround is unnecessary @@ -200,7 +200,7 @@ void bvh_done<BVHTree>(BVHTree *obj) template<> int bvh_intersect<BVHTree>(BVHTree *obj, Isect* isec) { - if(RayObject_isAligned(obj->root)) + if(RE_rayobject_isAligned(obj->root)) return bvh_node_stack_raycast<BVHNode,64,true>(obj->root, isec); else return RE_rayobject_intersect( (RayObject*) obj->root, isec ); @@ -222,7 +222,7 @@ static RayObjectAPI bvh_api = RayObject *RE_rayobject_bvh_create(int size) { BVHTree *obj= (BVHTree*)MEM_callocN(sizeof(BVHTree), "BVHTree"); - assert( RayObject_isAligned(obj) ); /* RayObject API assumes real data to be 4-byte aligned */ + assert( RE_rayobject_isAligned(obj) ); /* RayObject API assumes real data to be 4-byte aligned */ obj->rayobj.api = &bvh_api; obj->root = NULL; @@ -230,5 +230,5 @@ RayObject *RE_rayobject_bvh_create(int size) obj->node_arena = NULL; obj->builder = rtbuild_create( size ); - return RayObject_unalignRayAPI((RayObject*) obj); + return RE_rayobject_unalignRayAPI((RayObject*) obj); } diff --git a/source/blender/render/intern/raytrace/rayobject_vbvh.cpp b/source/blender/render/intern/raytrace/rayobject_vbvh.cpp index b703e57fdd8..6ec8fab15e4 100644 --- a/source/blender/render/intern/raytrace/rayobject_vbvh.cpp +++ b/source/blender/render/intern/raytrace/rayobject_vbvh.cpp @@ -181,7 +181,7 @@ static VBVHNode *bvh_new_node(VBVHTree *tree) #ifdef DYNAMIC_ALLOC_BB node->bb = (float*)BLI_memarena_alloc(tree->node_arena, 6*sizeof(float)); #endif - assert(RayObject_isAligned(node)); + assert(RE_rayobject_isAligned(node)); return node; } @@ -319,7 +319,7 @@ int intersect(VBVHTree *obj, Isect* isec) for(int i=0; i<lcts->size; i++) { VBVHNode *node = (VBVHNode*)lcts->stack[i]; - if(RayObject_isAligned(node)) + if(RE_rayobject_isAligned(node)) hit |= bvh_node_stack_raycast<VBVHNode,StackSize,true>(node, isec); else hit |= RE_rayobject_intersect( (RayObject*)node, isec ); @@ -333,7 +333,7 @@ int intersect(VBVHTree *obj, Isect* isec) else */ { - if(RayObject_isAligned(obj->root)) + if(RE_rayobject_isAligned(obj->root)) return bvh_node_stack_raycast<SVBVHNode,StackSize,false>( obj->root, isec); else return RE_rayobject_intersect( (RayObject*) obj->root, isec ); @@ -346,7 +346,7 @@ void bvh_dfs_make_hint(Node *node, LCTSHint *hint, int reserve_space, HintObject template<class Node,class HintObject> void bvh_dfs_make_hint_push_siblings(Node *node, LCTSHint *hint, int reserve_space, HintObject *hintObject) { - if(!RayObject_isAligned(node)) + if(!RE_rayobject_isAligned(node)) hint->stack[hint->size++] = (RayObject*)node; else { @@ -459,7 +459,7 @@ static RayObjectAPI* get_api(int maxstacksize) RayObject *RE_rayobject_vbvh_create(int size) { VBVHTree *obj= (VBVHTree*)MEM_callocN(sizeof(VBVHTree), "VBVHTree"); - assert( RayObject_isAligned(obj) ); /* RayObject API assumes real data to be 4-byte aligned */ + assert( RE_rayobject_isAligned(obj) ); /* RayObject API assumes real data to be 4-byte aligned */ obj->rayobj.api = get_api<VBVHTree>(DFS_STACK_SIZE); obj->root = NULL; @@ -467,7 +467,7 @@ RayObject *RE_rayobject_vbvh_create(int size) obj->node_arena = NULL; obj->builder = rtbuild_create( size ); - return RayObject_unalignRayAPI((RayObject*) obj); + return RE_rayobject_unalignRayAPI((RayObject*) obj); } @@ -482,7 +482,7 @@ void bvh_dfs_make_hint(VBVHNode *node, LCTSHint *hint, int reserve_space, HintOb RayObject *RE_rayobject_svbvh_create(int size) { SVBVHTree *obj= (SVBVHTree*)MEM_callocN(sizeof(SVBVHTree), "SVBVHTree"); - assert( RayObject_isAligned(obj) ); // RayObject API assumes real data to be 4-byte aligned + assert( RE_rayobject_isAligned(obj) ); // RayObject API assumes real data to be 4-byte aligned obj->rayobj.api = get_api<SVBVHTree>(DFS_STACK_SIZE); obj->root = NULL; @@ -490,6 +490,6 @@ RayObject *RE_rayobject_svbvh_create(int size) obj->node_arena = NULL; obj->builder = rtbuild_create( size ); - return RayObject_unalignRayAPI((RayObject*) obj); + return RE_rayobject_unalignRayAPI((RayObject*) obj); } */
\ No newline at end of file diff --git a/source/blender/render/intern/raytrace/reorganize.h b/source/blender/render/intern/raytrace/reorganize.h index b77a51bbf65..2494f102003 100644 --- a/source/blender/render/intern/raytrace/reorganize.h +++ b/source/blender/render/intern/raytrace/reorganize.h @@ -47,7 +47,7 @@ void reorganize_find_fittest_parent(Node *tree, Node *node, std::pair<float,Node q.pop(); if(parent == node) continue; - if(node_fits_inside(node, parent) && RayObject_isAligned(parent->child) ) + if(node_fits_inside(node, parent) && RE_rayobject_isAligned(parent->child) ) { float pcost = bb_area(parent->bb, parent->bb+3); cost = std::min( cost, std::make_pair(pcost,parent) ); @@ -69,11 +69,11 @@ void reorganize(Node *root) Node * node = q.front(); q.pop(); - if( RayObject_isAligned(node->child) ) + if( RE_rayobject_isAligned(node->child) ) { for(Node **prev = &node->child; *prev; ) { - assert( RayObject_isAligned(*prev) ); + assert( RE_rayobject_isAligned(*prev) ); q.push(*prev); std::pair<float,Node*> best(FLT_MAX, root); @@ -112,7 +112,7 @@ void reorganize(Node *root) template<class Node> void remove_useless(Node *node, Node **new_node) { - if( RayObject_isAligned(node->child) ) + if( RE_rayobject_isAligned(node->child) ) { for(Node **prev = &node->child; *prev; ) @@ -130,7 +130,7 @@ void remove_useless(Node *node, Node **new_node) } if(node->child) { - if(RayObject_isAligned(node->child) && node->child->sibling == 0) + if(RE_rayobject_isAligned(node->child) && node->child->sibling == 0) *new_node = node->child; } else if(node->child == 0) @@ -148,7 +148,7 @@ void pushup(Node *parent) float p_area = bb_area(parent->bb, parent->bb+3); Node **prev = &parent->child; - for(Node *child = parent->child; RayObject_isAligned(child) && child; ) + for(Node *child = parent->child; RE_rayobject_isAligned(child) && child; ) { float c_area = bb_area(child->bb, child->bb+3) ; int nchilds = count_childs(child); @@ -173,7 +173,7 @@ void pushup(Node *parent) } } - for(Node *child = parent->child; RayObject_isAligned(child) && child; child = child->sibling) + for(Node *child = parent->child; RE_rayobject_isAligned(child) && child; child = child->sibling) pushup(child); } @@ -188,10 +188,10 @@ void pushup_simd(Node *parent) int n = count_childs(parent); Node **prev = &parent->child; - for(Node *child = parent->child; RayObject_isAligned(child) && child; ) + for(Node *child = parent->child; RE_rayobject_isAligned(child) && child; ) { int cn = count_childs(child); - if(cn-1 <= (SSize - (n%SSize) ) % SSize && RayObject_isAligned(child->child) ) + if(cn-1 <= (SSize - (n%SSize) ) % SSize && RE_rayobject_isAligned(child->child) ) { n += (cn - 1); append_sibling(child, child->child); @@ -206,7 +206,7 @@ void pushup_simd(Node *parent) } } - for(Node *child = parent->child; RayObject_isAligned(child) && child; child = child->sibling) + for(Node *child = parent->child; RE_rayobject_isAligned(child) && child; child = child->sibling) pushup_simd<Node,SSize>(child); } @@ -221,15 +221,15 @@ void pushdown(Node *parent) Node **s_child = &parent->child; Node * child = parent->child; - while(child && RayObject_isAligned(child)) + while(child && RE_rayobject_isAligned(child)) { Node *next = child->sibling; Node **next_s_child = &child->sibling; //assert(bb_fits_inside(parent->bb, parent->bb+3, child->bb, child->bb+3)); - for(Node *i = parent->child; RayObject_isAligned(i) && i; i = i->sibling) - if(child != i && bb_fits_inside(i->bb, i->bb+3, child->bb, child->bb+3) && RayObject_isAligned(i->child)) + for(Node *i = parent->child; RE_rayobject_isAligned(i) && i; i = i->sibling) + if(child != i && bb_fits_inside(i->bb, i->bb+3, child->bb, child->bb+3) && RE_rayobject_isAligned(i->child)) { // todo optimize (should the one with the smallest area?) // float ia = bb_area(i->bb, i->bb+3) @@ -246,7 +246,7 @@ void pushdown(Node *parent) s_child = next_s_child; } - for(Node *i = parent->child; RayObject_isAligned(i) && i; i = i->sibling) + for(Node *i = parent->child; RE_rayobject_isAligned(i) && i; i = i->sibling) pushdown( i ); } diff --git a/source/blender/render/intern/source/rayobject.c b/source/blender/render/intern/source/rayobject.c index daa6b8d95de..996be35090e 100644 --- a/source/blender/render/intern/source/rayobject.c +++ b/source/blender/render/intern/source/rayobject.c @@ -27,7 +27,6 @@ * ***** END GPL LICENSE BLOCK ***** */ #include <assert.h> -#include <stdio.h> #include "BKE_utildefines.h" #include "BLI_arithb.h" @@ -42,33 +41,6 @@ * Based on Tactical Optimization of Ray/Box Intersection, by Graham Fyffe * [http://tog.acm.org/resources/RTNews/html/rtnv21n1.html#art9] */ -/* -float RE_rayobject_bb_intersect(const Isect *isec, const float *_bb) -{ - const float *bb = _bb; - float dist; - - float t1x = (bb[isec->bv_index[0]] - isec->start[0]) * isec->idot_axis[0]; - float t2x = (bb[isec->bv_index[1]] - isec->start[0]) * isec->idot_axis[0]; - float t1y = (bb[isec->bv_index[2]] - isec->start[1]) * isec->idot_axis[1]; - float t2y = (bb[isec->bv_index[3]] - isec->start[1]) * isec->idot_axis[1]; - float t1z = (bb[isec->bv_index[4]] - isec->start[2]) * isec->idot_axis[2]; - float t2z = (bb[isec->bv_index[5]] - isec->start[2]) * isec->idot_axis[2]; - - RE_RC_COUNT(isec->raycounter->bb.test); - - if(t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return FLT_MAX; - if(t2x < 0.0 || t2y < 0.0 || t2z < 0.0) return FLT_MAX; - if(t1x > isec->labda || t1y > isec->labda || t1z > isec->labda) return FLT_MAX; - - RE_RC_COUNT(isec->raycounter->bb.hit); - - dist = t1x; - if (t1y > dist) dist = t1y; - if (t1z > dist) dist = t1z; - return dist; -} -*/ int RE_rayobject_bb_intersect_test(const Isect *isec, const float *_bb) { const float *bb = _bb; @@ -185,23 +157,7 @@ static int intersect_rayface(RayFace *face, Isect *is) RE_RC_COUNT(is->raycounter->faces.test); -#ifdef RE_RAYFACE_COORDS_VLAKREN - { - VlakRen *vlr = (VlakRen*)face->face; - - VECCOPY(co1, vlr->v1->co); - VECCOPY(co2, vlr->v2->co); - if(vlr->v4) - { - VECCOPY(co3, vlr->v4->co); - VECCOPY(co4, vlr->v3->co); - } - else - { - VECCOPY(co3, vlr->v3->co); - } - } -#else + //Load coords VECCOPY(co1, face->v1); VECCOPY(co2, face->v2); if(RE_rayface_isQuad(face)) @@ -213,7 +169,6 @@ static int intersect_rayface(RayFace *face, Isect *is) { VECCOPY(co3, face->v3); } -#endif t00= co3[0]-co1[0]; t01= co3[1]-co1[1]; @@ -312,13 +267,6 @@ static int intersect_rayface(RayFace *face, Isect *is) } } } -#if 0 - else if(labda < ISECT_EPSILON) - { - /* too close to origin */ - return 0; - } -#endif RE_RC_COUNT(is->raycounter->faces.hit); @@ -329,7 +277,7 @@ static int intersect_rayface(RayFace *face, Isect *is) is->hit.ob = face->ob; is->hit.face = face->face; #ifdef RT_USE_LAST_HIT - is->last_hit = (RayObject*) RayObject_unalignRayFace(face); + is->last_hit = (RayObject*) RE_rayobject_unalignRayFace(face); #endif return 1; } @@ -339,7 +287,6 @@ static int intersect_rayface(RayFace *face, Isect *is) void RE_rayface_from_vlak(RayFace *face, ObjectInstanceRen *obi, VlakRen *vlr) { -#ifdef RE_RAYFACE_COORDS_LOCAL VECCOPY(face->v1, vlr->v1->co); VECCOPY(face->v2, vlr->v2->co); VECCOPY(face->v3, vlr->v3->co); @@ -352,13 +299,7 @@ void RE_rayface_from_vlak(RayFace *face, ObjectInstanceRen *obi, VlakRen *vlr) { face->quad = 0; } -#elif defined(RE_RAYFACE_COORDS_POINTER) - face->v1 = vlr->v1->co; - face->v2 = vlr->v2->co; - face->v3 = vlr->v3->co; - face->v4 = vlr->v4 ? vlr->v4->co : NULL; -#elif defined(RE_RAYFACE_COORDS_VLAKREN) -#endif + face->ob = obi; face->face = vlr; } @@ -405,9 +346,7 @@ int RE_rayobject_raycast(RayObject *r, Isect *isec) if(RE_rayobject_intersect(r, isec)) { -#ifdef RE_RAYCOUNTER RE_RC_COUNT(isec->raycounter->raycast.hit); -#endif #ifdef RT_USE_HINT isec->hint = isec->hit_hint; @@ -419,13 +358,13 @@ int RE_rayobject_raycast(RayObject *r, Isect *isec) int RE_rayobject_intersect(RayObject *r, Isect *i) { - if(RayObject_isRayFace(r)) + if(RE_rayobject_isRayFace(r)) { - return intersect_rayface( (RayFace*) RayObject_align(r), i); + return intersect_rayface( (RayFace*) RE_rayobject_align(r), i); } - else if(RayObject_isRayAPI(r)) + else if(RE_rayobject_isRayAPI(r)) { - r = RayObject_align( r ); + r = RE_rayobject_align( r ); return r->api->raycast( r, i ); } else assert(0); @@ -433,44 +372,36 @@ int RE_rayobject_intersect(RayObject *r, Isect *i) void RE_rayobject_add(RayObject *r, RayObject *o) { - r = RayObject_align( r ); + r = RE_rayobject_align( r ); return r->api->add( r, o ); } void RE_rayobject_done(RayObject *r) { - r = RayObject_align( r ); + r = RE_rayobject_align( r ); r->api->done( r ); } void RE_rayobject_free(RayObject *r) { - r = RayObject_align( r ); + r = RE_rayobject_align( r ); r->api->free( r ); } void RE_rayobject_merge_bb(RayObject *r, float *min, float *max) { - if(RayObject_isRayFace(r)) + if(RE_rayobject_isRayFace(r)) { - RayFace *face = (RayFace*) RayObject_align(r); + RayFace *face = (RayFace*) RE_rayobject_align(r); -#ifdef RE_RAYFACE_COORDS_VLAKREN - VlakRen *vlr = (VlakRen*)face->face; - DO_MINMAX( vlr->v1->co, min, max ); - DO_MINMAX( vlr->v2->co, min, max ); - DO_MINMAX( vlr->v3->co, min, max ); - if(RE_rayface_isQuad(face)) DO_MINMAX( vlr->v4->co, min, max ); -#else DO_MINMAX( face->v1, min, max ); DO_MINMAX( face->v2, min, max ); DO_MINMAX( face->v3, min, max ); if(RE_rayface_isQuad(face)) DO_MINMAX( face->v4, min, max ); -#endif } - else if(RayObject_isRayAPI(r)) + else if(RE_rayobject_isRayAPI(r)) { - r = RayObject_align( r ); + r = RE_rayobject_align( r ); r->api->bb( r, min, max ); } else assert(0); @@ -478,13 +409,13 @@ void RE_rayobject_merge_bb(RayObject *r, float *min, float *max) float RE_rayobject_cost(RayObject *r) { - if(RayObject_isRayFace(r)) + if(RE_rayobject_isRayFace(r)) { return 1.0; } - else if(RayObject_isRayAPI(r)) + else if(RE_rayobject_isRayAPI(r)) { - r = RayObject_align( r ); + r = RE_rayobject_align( r ); return r->api->cost( r ); } else assert(0); @@ -492,61 +423,15 @@ float RE_rayobject_cost(RayObject *r) void RE_rayobject_hint_bb(RayObject *r, RayHint *hint, float *min, float *max) { - if(RayObject_isRayFace(r)) + if(RE_rayobject_isRayFace(r)) { return; } - else if(RayObject_isRayAPI(r)) + else if(RE_rayobject_isRayAPI(r)) { - r = RayObject_align( r ); + r = RE_rayobject_align( r ); return r->api->hint_bb( r, hint, min, max ); } else assert(0); } -#ifdef RE_RAYCOUNTER -void RE_RC_INFO(RayCounter *info) -{ - printf("----------- Raycast counter --------\n"); - printf("Rays total: %llu\n", info->raycast.test ); - printf("Rays hit: %llu\n", info->raycast.hit ); - printf("\n"); - printf("BB tests: %llu\n", info->bb.test ); - printf("BB hits: %llu\n", info->bb.hit ); - printf("\n"); - printf("Primitives tests: %llu\n", info->faces.test ); - printf("Primitives hits: %llu\n", info->faces.hit ); - printf("------------------------------------\n"); - printf("Shadow last-hit tests per ray: %f\n", info->rayshadow_last_hit.test / ((float)info->raycast.test) ); - printf("Shadow last-hit hits per ray: %f\n", info->rayshadow_last_hit.hit / ((float)info->raycast.test) ); - printf("\n"); - printf("Hint tests per ray: %f\n", info->raytrace_hint.test / ((float)info->raycast.test) ); - printf("Hint hits per ray: %f\n", info->raytrace_hint.hit / ((float)info->raycast.test) ); - printf("\n"); - printf("BB tests per ray: %f\n", info->bb.test / ((float)info->raycast.test) ); - printf("BB hits per ray: %f\n", info->bb.hit / ((float)info->raycast.test) ); - printf("\n"); - printf("Primitives tests per ray: %f\n", info->faces.test / ((float)info->raycast.test) ); - printf("Primitives hits per ray: %f\n", info->faces.hit / ((float)info->raycast.test) ); - printf("------------------------------------\n"); -} - -void RE_RC_MERGE(RayCounter *dest, RayCounter *tmp) -{ - dest->faces.test += tmp->faces.test; - dest->faces.hit += tmp->faces.hit; - - dest->bb.test += tmp->bb.test; - dest->bb.hit += tmp->bb.hit; - - dest->raycast.test += tmp->raycast.test; - dest->raycast.hit += tmp->raycast.hit; - - dest->rayshadow_last_hit.test += tmp->rayshadow_last_hit.test; - dest->rayshadow_last_hit.hit += tmp->rayshadow_last_hit.hit; - - dest->raytrace_hint.test += tmp->raytrace_hint.test; - dest->raytrace_hint.hit += tmp->raytrace_hint.hit; -} - -#endif
\ No newline at end of file diff --git a/source/blender/render/intern/source/rayobject_blibvh.c b/source/blender/render/intern/source/rayobject_blibvh.c index 9b872d8f249..6e789862207 100644 --- a/source/blender/render/intern/source/rayobject_blibvh.c +++ b/source/blender/render/intern/source/rayobject_blibvh.c @@ -36,19 +36,19 @@ #include "render_types.h" #include "rayobject.h" -static int RayObject_blibvh_intersect(RayObject *o, Isect *isec); -static void RayObject_blibvh_add(RayObject *o, RayObject *ob); -static void RayObject_blibvh_done(RayObject *o); -static void RayObject_blibvh_free(RayObject *o); -static void RayObject_blibvh_bb(RayObject *o, float *min, float *max); +static int RE_rayobject_blibvh_intersect(RayObject *o, Isect *isec); +static void RE_rayobject_blibvh_add(RayObject *o, RayObject *ob); +static void RE_rayobject_blibvh_done(RayObject *o); +static void RE_rayobject_blibvh_free(RayObject *o); +static void RE_rayobject_blibvh_bb(RayObject *o, float *min, float *max); static RayObjectAPI bvh_api = { - RayObject_blibvh_intersect, - RayObject_blibvh_add, - RayObject_blibvh_done, - RayObject_blibvh_free, - RayObject_blibvh_bb + RE_rayobject_blibvh_intersect, + RE_rayobject_blibvh_add, + RE_rayobject_blibvh_done, + RE_rayobject_blibvh_free, + RE_rayobject_blibvh_bb }; typedef struct BVHObject @@ -63,13 +63,13 @@ typedef struct BVHObject RayObject *RE_rayobject_blibvh_create(int size) { BVHObject *obj= (BVHObject*)MEM_callocN(sizeof(BVHObject), "BVHObject"); - assert( RayObject_isAligned(obj) ); /* RayObject API assumes real data to be 4-byte aligned */ + assert( RE_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, 4, 6); INIT_MINMAX(obj->bb[0], obj->bb[1]); - return RayObject_unalignRayAPI((RayObject*) obj); + return RE_rayobject_unalignRayAPI((RayObject*) obj); } static void bvh_callback(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit) @@ -88,7 +88,7 @@ static void bvh_callback(void *userdata, int index, const BVHTreeRay *ray, BVHTr } } -static int RayObject_blibvh_intersect(RayObject *o, Isect *isec) +static int RE_rayobject_blibvh_intersect(RayObject *o, Isect *isec) { BVHObject *obj = (BVHObject*)o; BVHTreeRayHit hit; @@ -103,7 +103,7 @@ static int RayObject_blibvh_intersect(RayObject *o, Isect *isec) return BLI_bvhtree_ray_cast(obj->bvh, isec->start, dir, 0.0, &hit, bvh_callback, isec); } -static void RayObject_blibvh_add(RayObject *o, RayObject *ob) +static void RE_rayobject_blibvh_add(RayObject *o, RayObject *ob) { BVHObject *obj = (BVHObject*)o; float min_max[6]; @@ -116,13 +116,13 @@ static void RayObject_blibvh_add(RayObject *o, RayObject *ob) BLI_bvhtree_insert(obj->bvh, (int)ob, min_max, 2 ); } -static void RayObject_blibvh_done(RayObject *o) +static void RE_rayobject_blibvh_done(RayObject *o) { BVHObject *obj = (BVHObject*)o; BLI_bvhtree_balance(obj->bvh); } -static void RayObject_blibvh_free(RayObject *o) +static void RE_rayobject_blibvh_free(RayObject *o) { BVHObject *obj = (BVHObject*)o; @@ -132,7 +132,7 @@ static void RayObject_blibvh_free(RayObject *o) MEM_freeN(obj); } -static void RayObject_blibvh_bb(RayObject *o, float *min, float *max) +static void RE_rayobject_blibvh_bb(RayObject *o, float *min, float *max) { BVHObject *obj = (BVHObject*)o; DO_MIN( obj->bb[0], min ); diff --git a/source/blender/render/intern/source/rayobject_instance.c b/source/blender/render/intern/source/rayobject_instance.c index 14f333a7f86..9329d110870 100644 --- a/source/blender/render/intern/source/rayobject_instance.c +++ b/source/blender/render/intern/source/rayobject_instance.c @@ -36,19 +36,19 @@ #define RE_COST_INSTANCE (1.0f) -static int RayObject_instance_intersect(RayObject *o, Isect *isec); -static void RayObject_instance_free(RayObject *o); -static void RayObject_instance_bb(RayObject *o, float *min, float *max); -static float RayObject_instance_cost(RayObject *o); +static int RE_rayobject_instance_intersect(RayObject *o, Isect *isec); +static void RE_rayobject_instance_free(RayObject *o); +static void RE_rayobject_instance_bb(RayObject *o, float *min, float *max); +static float RE_rayobject_instance_cost(RayObject *o); static RayObjectAPI instance_api = { - RayObject_instance_intersect, - NULL, //static void RayObject_instance_add(RayObject *o, RayObject *ob); - NULL, //static void RayObject_instance_done(RayObject *o); - RayObject_instance_free, - RayObject_instance_bb, - RayObject_instance_cost + RE_rayobject_instance_intersect, + NULL, //static void RE_rayobject_instance_add(RayObject *o, RayObject *ob); + NULL, //static void RE_rayobject_instance_done(RayObject *o); + RE_rayobject_instance_free, + RE_rayobject_instance_bb, + RE_rayobject_instance_cost }; typedef struct InstanceRayObject @@ -68,7 +68,7 @@ typedef struct InstanceRayObject RayObject *RE_rayobject_instance_create(RayObject *target, float transform[][4], void *ob, void *target_ob) { InstanceRayObject *obj= (InstanceRayObject*)MEM_callocN(sizeof(InstanceRayObject), "InstanceRayObject"); - assert( RayObject_isAligned(obj) ); /* RayObject API assumes real data to be 4-byte aligned */ + assert( RE_rayobject_isAligned(obj) ); /* RayObject API assumes real data to be 4-byte aligned */ obj->rayobj.api = &instance_api; obj->target = target; @@ -78,10 +78,10 @@ RayObject *RE_rayobject_instance_create(RayObject *target, float transform[][4], Mat4CpyMat4(obj->target2global, transform); Mat4Invert(obj->global2target, obj->target2global); - return RayObject_unalignRayAPI((RayObject*) obj); + return RE_rayobject_unalignRayAPI((RayObject*) obj); } -static int RayObject_instance_intersect(RayObject *o, Isect *isec) +static int RE_rayobject_instance_intersect(RayObject *o, Isect *isec) { //TODO // *there is probably a faster way to convert between coordinates @@ -162,19 +162,19 @@ static int RayObject_instance_intersect(RayObject *o, Isect *isec) return res; } -static void RayObject_instance_free(RayObject *o) +static void RE_rayobject_instance_free(RayObject *o) { InstanceRayObject *obj = (InstanceRayObject*)o; MEM_freeN(obj); } -static float RayObject_instance_cost(RayObject *o) +static float RE_rayobject_instance_cost(RayObject *o) { InstanceRayObject *obj = (InstanceRayObject*)o; return RE_rayobject_cost(obj->target) + RE_COST_INSTANCE; } -static void RayObject_instance_bb(RayObject *o, float *min, float *max) +static void RE_rayobject_instance_bb(RayObject *o, float *min, float *max) { //TODO: // *better bb.. calculated without rotations of bb diff --git a/source/blender/render/intern/source/rayobject_octree.c b/source/blender/render/intern/source/rayobject_octree.c index da1083a654d..4246dd522db 100644 --- a/source/blender/render/intern/source/rayobject_octree.c +++ b/source/blender/render/intern/source/rayobject_octree.c @@ -84,19 +84,19 @@ typedef struct Octree { } Octree; -static int RayObject_octree_intersect(RayObject *o, Isect *isec); -static void RayObject_octree_add(RayObject *o, RayObject *ob); -static void RayObject_octree_done(RayObject *o); -static void RayObject_octree_free(RayObject *o); -static void RayObject_octree_bb(RayObject *o, float *min, float *max); +static int RE_rayobject_octree_intersect(RayObject *o, Isect *isec); +static void RE_rayobject_octree_add(RayObject *o, RayObject *ob); +static void RE_rayobject_octree_done(RayObject *o); +static void RE_rayobject_octree_free(RayObject *o); +static void RE_rayobject_octree_bb(RayObject *o, float *min, float *max); static RayObjectAPI octree_api = { - RayObject_octree_intersect, - RayObject_octree_add, - RayObject_octree_done, - RayObject_octree_free, - RayObject_octree_bb + RE_rayobject_octree_intersect, + RE_rayobject_octree_add, + RE_rayobject_octree_done, + RE_rayobject_octree_free, + RE_rayobject_octree_bb }; /* **************** ocval method ******************* */ @@ -294,7 +294,7 @@ static void ocwrite(Octree *oc, RayFace *face, int quad, short x, short y, short while(no->v[a]!=NULL) a++; } - no->v[a]= (RayFace*) RayObject_align(face); + no->v[a]= (RayFace*) RE_rayobject_align(face); if(quad) calc_ocval_face(rtf[0], rtf[1], rtf[2], rtf[3], x>>2, y>>1, z, &no->ov[a]); @@ -406,7 +406,7 @@ static void filltriangle(Octree *oc, short c1, short c2, char *ocface, short *oc } } -static void RayObject_octree_free(RayObject *tree) +static void RE_rayobject_octree_free(RayObject *tree) { Octree *oc= (Octree*)tree; @@ -450,7 +450,7 @@ static void RayObject_octree_free(RayObject *tree) RayObject *RE_rayobject_octree_create(int ocres, int size) { Octree *oc= MEM_callocN(sizeof(Octree), "Octree"); - assert( RayObject_isAligned(oc) ); /* RayObject API assumes real data to be 4-byte aligned */ + assert( RE_rayobject_isAligned(oc) ); /* RayObject API assumes real data to be 4-byte aligned */ oc->rayobj.api = &octree_api; @@ -461,17 +461,17 @@ RayObject *RE_rayobject_octree_create(int ocres, int size) oc->ro_nodes_used = 0; - return RayObject_unalignRayAPI((RayObject*) oc); + return RE_rayobject_unalignRayAPI((RayObject*) oc); } -static void RayObject_octree_add(RayObject *tree, RayObject *node) +static void RE_rayobject_octree_add(RayObject *tree, RayObject *node) { Octree *oc = (Octree*)tree; - assert( RayObject_isRayFace(node) ); + assert( RE_rayobject_isRayFace(node) ); assert( oc->ro_nodes_used < oc->ro_nodes_size ); - oc->ro_nodes[ oc->ro_nodes_used++ ] = (RayFace*)RayObject_align(node); + oc->ro_nodes[ oc->ro_nodes_used++ ] = (RayFace*)RE_rayobject_align(node); } static void octree_fill_rayface(Octree *oc, RayFace *face) @@ -489,22 +489,11 @@ static void octree_fill_rayface(Octree *oc, RayFace *face) ocres2= oc->ocres*oc->ocres; -#ifdef RE_RAYFACE_COORDS_VLAKREN - { - VlakRen *vlr = (VlakRen*)face->face; - VECCOPY(co1, vlr->v1->co); - VECCOPY(co2, vlr->v2->co); - VECCOPY(co3, vlr->v3->co); - if(RE_rayface_isQuad(face)) - VECCOPY(co4, vlr->v4->co); - } -#else VECCOPY(co1, face->v1); VECCOPY(co2, face->v2); VECCOPY(co3, face->v3); if(face->v4) VECCOPY(co4, face->v4); -#endif for(c=0;c<3;c++) { rtf[0][c]= (co1[c]-oc->min[c])*ocfac[c] ; @@ -602,7 +591,7 @@ static void octree_fill_rayface(Octree *oc, RayFace *face) } } -static void RayObject_octree_done(RayObject *tree) +static void RE_rayobject_octree_done(RayObject *tree) { Octree *oc = (Octree*)tree; int c; @@ -613,7 +602,7 @@ static void RayObject_octree_done(RayObject *tree) /* Calculate Bounding Box */ for(c=0; c<oc->ro_nodes_used; c++) - RE_rayobject_merge_bb( RayObject_unalignRayFace(oc->ro_nodes[c]), oc->min, oc->max); + RE_rayobject_merge_bb( RE_rayobject_unalignRayFace(oc->ro_nodes[c]), oc->min, oc->max); /* Alloc memory */ oc->adrbranch= MEM_callocN(sizeof(void *)*BRANCH_ARRAY, "octree branches"); @@ -656,7 +645,7 @@ static void RayObject_octree_done(RayObject *tree) printf("%f %f - %f\n", oc->min[2], oc->max[2], oc->ocfacz ); } -static void RayObject_octree_bb(RayObject *tree, float *min, float *max) +static void RE_rayobject_octree_bb(RayObject *tree, float *min, float *max) { Octree *oc = (Octree*)tree; DO_MINMAX(oc->min, min, max); @@ -681,7 +670,7 @@ static int testnode(Octree *oc, Isect *is, Node *no, OcVal ocval) if( (ov->ocx & ocval.ocx) && (ov->ocy & ocval.ocy) && (ov->ocz & ocval.ocz) ) { - if( RE_rayobject_intersect( RayObject_unalignRayFace(face),is) ) + if( RE_rayobject_intersect( RE_rayobject_unalignRayFace(face),is) ) return 1; } } @@ -700,7 +689,7 @@ static int testnode(Octree *oc, Isect *is, Node *no, OcVal ocval) if( (ov->ocx & ocval.ocx) && (ov->ocy & ocval.ocy) && (ov->ocz & ocval.ocz) ) { - if( RE_rayobject_intersect( RayObject_unalignRayFace(face),is) ) + if( RE_rayobject_intersect( RE_rayobject_unalignRayFace(face),is) ) found= 1; } } @@ -828,7 +817,7 @@ static int do_coherence_test(int ocx1, int ocx2, int ocy1, int ocy2, int ocz1, i /* return 1: found valid intersection */ /* starts with is->orig.face */ -static int RayObject_octree_intersect(RayObject *tree, Isect *is) +static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is) { Octree *oc= (Octree*)tree; Node *no; diff --git a/source/blender/render/intern/source/rayobject_raycounter.c b/source/blender/render/intern/source/rayobject_raycounter.c new file mode 100644 index 00000000000..83ba15602da --- /dev/null +++ b/source/blender/render/intern/source/rayobject_raycounter.c @@ -0,0 +1,77 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): André Pinto. + * + * ***** END GPL LICENSE BLOCK ***** + */ +#include "rayobject.h" + +#ifdef RE_RAYCOUNTER + +void RE_RC_INFO(RayCounter *info) +{ + printf("----------- Raycast counter --------\n"); + printf("Rays total: %llu\n", info->raycast.test ); + printf("Rays hit: %llu\n", info->raycast.hit ); + printf("\n"); + printf("BB tests: %llu\n", info->bb.test ); + printf("BB hits: %llu\n", info->bb.hit ); + printf("\n"); + printf("Primitives tests: %llu\n", info->faces.test ); + printf("Primitives hits: %llu\n", info->faces.hit ); + printf("------------------------------------\n"); + printf("Shadow last-hit tests per ray: %f\n", info->rayshadow_last_hit.test / ((float)info->raycast.test) ); + printf("Shadow last-hit hits per ray: %f\n", info->rayshadow_last_hit.hit / ((float)info->raycast.test) ); + printf("\n"); + printf("Hint tests per ray: %f\n", info->raytrace_hint.test / ((float)info->raycast.test) ); + printf("Hint hits per ray: %f\n", info->raytrace_hint.hit / ((float)info->raycast.test) ); + printf("\n"); + printf("BB tests per ray: %f\n", info->bb.test / ((float)info->raycast.test) ); + printf("BB hits per ray: %f\n", info->bb.hit / ((float)info->raycast.test) ); + printf("\n"); + printf("Primitives tests per ray: %f\n", info->faces.test / ((float)info->raycast.test) ); + printf("Primitives hits per ray: %f\n", info->faces.hit / ((float)info->raycast.test) ); + printf("------------------------------------\n"); +} + +void RE_RC_MERGE(RayCounter *dest, RayCounter *tmp) +{ + dest->faces.test += tmp->faces.test; + dest->faces.hit += tmp->faces.hit; + + dest->bb.test += tmp->bb.test; + dest->bb.hit += tmp->bb.hit; + + dest->raycast.test += tmp->raycast.test; + dest->raycast.hit += tmp->raycast.hit; + + dest->rayshadow_last_hit.test += tmp->rayshadow_last_hit.test; + dest->rayshadow_last_hit.hit += tmp->rayshadow_last_hit.hit; + + dest->raytrace_hint.test += tmp->raytrace_hint.test; + dest->raytrace_hint.hit += tmp->raytrace_hint.hit; +} + +#endif diff --git a/source/blender/render/intern/source/rayshade.c b/source/blender/render/intern/source/rayshade.c index 05c961d49de..af2c0f99174 100644 --- a/source/blender/render/intern/source/rayshade.c +++ b/source/blender/render/intern/source/rayshade.c @@ -222,7 +222,7 @@ RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi) if(is_raytraceable_vlr(re, vlr)) { RE_rayface_from_vlak( face, obi, vlr ); - RE_rayobject_add( raytree, RayObject_unalignRayFace(face) ); + RE_rayobject_add( raytree, RE_rayobject_unalignRayFace(face) ); face++; } } @@ -372,7 +372,7 @@ static void makeraytree_single(Render *re) Mat4MulVecfl(obi->mat, face->v4); } - RE_rayobject_add( raytree, RayObject_unalignRayFace(face) ); + RE_rayobject_add( raytree, RE_rayobject_unalignRayFace(face) ); face++; } } |